blob: 0ec9779c2b56dc5476ea2e0ec8226d31502d413b [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Jouni Malinen5fb628e2011-08-10 23:54:35 +030026static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
30 int cipher_limit);
31
Johannes Berg4c476992010-10-04 21:36:35 +020032static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
38static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020044 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020045 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040047};
48
Johannes Berg79c97e92009-07-07 03:56:12 +020049/* internal helper: get rdev and dev */
Johannes Berg00918d32011-12-13 17:22:05 +010050static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
51 struct cfg80211_registered_device **rdev,
52 struct net_device **dev)
Johannes Berg55682962007-09-20 13:09:35 -040053{
54 int ifindex;
55
Johannes Bergbba95fe2008-07-29 13:22:51 +020056 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040057 return -EINVAL;
58
Johannes Bergbba95fe2008-07-29 13:22:51 +020059 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg00918d32011-12-13 17:22:05 +010060 *dev = dev_get_by_index(netns, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040061 if (!*dev)
62 return -ENODEV;
63
Johannes Berg00918d32011-12-13 17:22:05 +010064 *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020065 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040066 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020067 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040068 }
69
70 return 0;
71}
72
Johannes Berga9455402012-06-15 13:32:49 +020073static struct cfg80211_registered_device *
74__cfg80211_rdev_from_info(struct genl_info *info)
75{
Johannes Berg7fee4772012-06-15 14:09:58 +020076 struct cfg80211_registered_device *rdev = NULL, *tmp;
77 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +020078
79 assert_cfg80211_lock();
80
Johannes Berg7fee4772012-06-15 14:09:58 +020081 if (!info->attrs[NL80211_ATTR_WIPHY] &&
82 !info->attrs[NL80211_ATTR_IFINDEX])
83 return ERR_PTR(-EINVAL);
84
85 if (info->attrs[NL80211_ATTR_WIPHY])
86 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berga9455402012-06-15 13:32:49 +020087 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +020088
89 if (info->attrs[NL80211_ATTR_IFINDEX]) {
Johannes Berg7fee4772012-06-15 14:09:58 +020090 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
91 netdev = dev_get_by_index(genl_info_net(info), ifindex);
92 if (netdev) {
93 if (netdev->ieee80211_ptr)
94 tmp = wiphy_to_dev(
95 netdev->ieee80211_ptr->wiphy);
96 else
97 tmp = NULL;
98
99 dev_put(netdev);
100
101 /* not wireless device -- return error */
102 if (!tmp)
103 return ERR_PTR(-EINVAL);
104
105 /* mismatch -- return error */
106 if (rdev && tmp != rdev)
107 return ERR_PTR(-EINVAL);
108
109 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200110 }
Johannes Berga9455402012-06-15 13:32:49 +0200111 }
112
Johannes Berg7fee4772012-06-15 14:09:58 +0200113 if (rdev)
114 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200115
Johannes Berg7fee4772012-06-15 14:09:58 +0200116 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200117}
118
119/*
120 * This function returns a pointer to the driver
121 * that the genl_info item that is passed refers to.
122 * If successful, it returns non-NULL and also locks
123 * the driver's mutex!
124 *
125 * This means that you need to call cfg80211_unlock_rdev()
126 * before being allowed to acquire &cfg80211_mutex!
127 *
128 * This is necessary because we need to lock the global
129 * mutex to get an item off the list safely, and then
130 * we lock the rdev mutex so it doesn't go away under us.
131 *
132 * We don't want to keep cfg80211_mutex locked
133 * for all the time in order to allow requests on
134 * other interfaces to go through at the same time.
135 *
136 * The result of this can be a PTR_ERR and hence must
137 * be checked with IS_ERR() for errors.
138 */
139static struct cfg80211_registered_device *
140cfg80211_get_dev_from_info(struct genl_info *info)
141{
142 struct cfg80211_registered_device *rdev;
143
144 mutex_lock(&cfg80211_mutex);
145 rdev = __cfg80211_rdev_from_info(info);
146
147 /* if it is not an error we grab the lock on
148 * it to assure it won't be going away while
149 * we operate on it */
150 if (!IS_ERR(rdev))
151 mutex_lock(&rdev->mtx);
152
153 mutex_unlock(&cfg80211_mutex);
154
155 return rdev;
156}
157
Johannes Berg55682962007-09-20 13:09:35 -0400158/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000159static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400160 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
161 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700162 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200163 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200164 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530165 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200166 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
167 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
168 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
169 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100170 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400171
172 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
173 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
174 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100175
Eliad Pellere007b852011-11-24 18:13:56 +0200176 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
177 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100178
Johannes Bergb9454e82009-07-08 13:29:08 +0200179 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100180 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
181 .len = WLAN_MAX_KEY_LEN },
182 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
183 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
184 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200185 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200186 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100187
188 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
189 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
190 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
191 .len = IEEE80211_MAX_DATA_LEN },
192 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
193 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100194 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
195 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
196 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
197 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
198 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100199 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100200 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200201 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100202 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800203 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100204 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300205
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700206 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
207 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
208
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300209 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
210 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
211 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200212 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
213 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100214 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300215
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800216 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700217 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700218
Johannes Berg6c739412011-11-03 09:27:01 +0100219 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200220
221 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
222 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
223 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100224 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
225 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200226
227 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
228 .len = IEEE80211_MAX_SSID_LEN },
229 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200231 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300232 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300233 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300234 [NL80211_ATTR_STA_FLAGS2] = {
235 .len = sizeof(struct nl80211_sta_flag_update),
236 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300237 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300238 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
239 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200240 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
241 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
242 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200243 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100244 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100245 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
246 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100247 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
248 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200249 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200250 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200253 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200254 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300255 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200256 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300257 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
258 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200259 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900260 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
261 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100262 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100263 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100264 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200265 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700266 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300267 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200268 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200269 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300270 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300271 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
273 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
274 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530275 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300276 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530277 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300278 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
279 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
280 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
281 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
282 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100283 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200284 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700286 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800287 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
288 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
289 .len = NL80211_HT_CAPABILITY_LEN
290 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100291 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530292 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530293 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400294};
295
Johannes Berge31b8212010-10-05 19:39:30 +0200296/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000297static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200298 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200299 [NL80211_KEY_IDX] = { .type = NLA_U8 },
300 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200301 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200302 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
303 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200304 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100305 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
306};
307
308/* policy for the key default flags */
309static const struct nla_policy
310nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
311 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
312 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200313};
314
Johannes Bergff1b6e62011-05-04 15:37:28 +0200315/* policy for WoWLAN attributes */
316static const struct nla_policy
317nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
318 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
319 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
320 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
321 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200322 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
323 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
324 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
325 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326};
327
Johannes Berge5497d72011-07-05 16:35:40 +0200328/* policy for GTK rekey offload attributes */
329static const struct nla_policy
330nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
331 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
332 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
333 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
334};
335
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336static const struct nla_policy
337nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200338 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339 .len = IEEE80211_MAX_SSID_LEN },
340};
341
Holger Schuriga0438972009-11-11 11:30:02 +0100342/* ifidx get helper */
343static int nl80211_get_ifidx(struct netlink_callback *cb)
344{
345 int res;
346
347 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
348 nl80211_fam.attrbuf, nl80211_fam.maxattr,
349 nl80211_policy);
350 if (res)
351 return res;
352
353 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
354 return -EINVAL;
355
356 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
357 if (!res)
358 return -EINVAL;
359 return res;
360}
361
Johannes Berg67748892010-10-04 21:14:06 +0200362static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
363 struct netlink_callback *cb,
364 struct cfg80211_registered_device **rdev,
365 struct net_device **dev)
366{
367 int ifidx = cb->args[0];
368 int err;
369
370 if (!ifidx)
371 ifidx = nl80211_get_ifidx(cb);
372 if (ifidx < 0)
373 return ifidx;
374
375 cb->args[0] = ifidx;
376
377 rtnl_lock();
378
379 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
380 if (!*dev) {
381 err = -ENODEV;
382 goto out_rtnl;
383 }
384
385 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100386 if (IS_ERR(*rdev)) {
387 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200388 goto out_rtnl;
389 }
390
391 return 0;
392 out_rtnl:
393 rtnl_unlock();
394 return err;
395}
396
397static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
398{
399 cfg80211_unlock_rdev(rdev);
400 rtnl_unlock();
401}
402
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100403/* IE validation */
404static bool is_valid_ie_attr(const struct nlattr *attr)
405{
406 const u8 *pos;
407 int len;
408
409 if (!attr)
410 return true;
411
412 pos = nla_data(attr);
413 len = nla_len(attr);
414
415 while (len) {
416 u8 elemlen;
417
418 if (len < 2)
419 return false;
420 len -= 2;
421
422 elemlen = pos[1];
423 if (elemlen > len)
424 return false;
425
426 len -= elemlen;
427 pos += 2 + elemlen;
428 }
429
430 return true;
431}
432
Johannes Berg55682962007-09-20 13:09:35 -0400433/* message building helper */
434static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
435 int flags, u8 cmd)
436{
437 /* since there is no private header just add the generic one */
438 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
439}
440
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400441static int nl80211_msg_put_channel(struct sk_buff *msg,
442 struct ieee80211_channel *chan)
443{
David S. Miller9360ffd2012-03-29 04:41:26 -0400444 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
445 chan->center_freq))
446 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400447
David S. Miller9360ffd2012-03-29 04:41:26 -0400448 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
449 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
450 goto nla_put_failure;
451 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
452 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
453 goto nla_put_failure;
454 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
455 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
456 goto nla_put_failure;
457 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
458 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
459 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400460
David S. Miller9360ffd2012-03-29 04:41:26 -0400461 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
462 DBM_TO_MBM(chan->max_power)))
463 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400464
465 return 0;
466
467 nla_put_failure:
468 return -ENOBUFS;
469}
470
Johannes Berg55682962007-09-20 13:09:35 -0400471/* netlink command implementations */
472
Johannes Bergb9454e82009-07-08 13:29:08 +0200473struct key_parse {
474 struct key_params p;
475 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200476 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200477 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100478 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200479};
480
481static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
482{
483 struct nlattr *tb[NL80211_KEY_MAX + 1];
484 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
485 nl80211_key_policy);
486 if (err)
487 return err;
488
489 k->def = !!tb[NL80211_KEY_DEFAULT];
490 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
491
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100492 if (k->def) {
493 k->def_uni = true;
494 k->def_multi = true;
495 }
496 if (k->defmgmt)
497 k->def_multi = true;
498
Johannes Bergb9454e82009-07-08 13:29:08 +0200499 if (tb[NL80211_KEY_IDX])
500 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
501
502 if (tb[NL80211_KEY_DATA]) {
503 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
504 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
505 }
506
507 if (tb[NL80211_KEY_SEQ]) {
508 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
509 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
510 }
511
512 if (tb[NL80211_KEY_CIPHER])
513 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
514
Johannes Berge31b8212010-10-05 19:39:30 +0200515 if (tb[NL80211_KEY_TYPE]) {
516 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
517 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
518 return -EINVAL;
519 }
520
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100521 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
522 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100523 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
524 tb[NL80211_KEY_DEFAULT_TYPES],
525 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100526 if (err)
527 return err;
528
529 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
530 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
531 }
532
Johannes Bergb9454e82009-07-08 13:29:08 +0200533 return 0;
534}
535
536static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
537{
538 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
539 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
540 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
541 }
542
543 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
544 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
545 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
546 }
547
548 if (info->attrs[NL80211_ATTR_KEY_IDX])
549 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
550
551 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
552 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
553
554 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
555 k->defmgmt = !!info->attrs[NL80211_ATTR_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 Berge31b8212010-10-05 19:39:30 +0200564 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
565 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
566 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
567 return -EINVAL;
568 }
569
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100570 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
571 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
572 int err = nla_parse_nested(
573 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
574 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
575 nl80211_key_default_policy);
576 if (err)
577 return err;
578
579 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
580 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
581 }
582
Johannes Bergb9454e82009-07-08 13:29:08 +0200583 return 0;
584}
585
586static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
587{
588 int err;
589
590 memset(k, 0, sizeof(*k));
591 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200592 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200593
594 if (info->attrs[NL80211_ATTR_KEY])
595 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
596 else
597 err = nl80211_parse_key_old(info, k);
598
599 if (err)
600 return err;
601
602 if (k->def && k->defmgmt)
603 return -EINVAL;
604
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100605 if (k->defmgmt) {
606 if (k->def_uni || !k->def_multi)
607 return -EINVAL;
608 }
609
Johannes Bergb9454e82009-07-08 13:29:08 +0200610 if (k->idx != -1) {
611 if (k->defmgmt) {
612 if (k->idx < 4 || k->idx > 5)
613 return -EINVAL;
614 } else if (k->def) {
615 if (k->idx < 0 || k->idx > 3)
616 return -EINVAL;
617 } else {
618 if (k->idx < 0 || k->idx > 5)
619 return -EINVAL;
620 }
621 }
622
623 return 0;
624}
625
Johannes Bergfffd0932009-07-08 14:22:54 +0200626static struct cfg80211_cached_keys *
627nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
628 struct nlattr *keys)
629{
630 struct key_parse parse;
631 struct nlattr *key;
632 struct cfg80211_cached_keys *result;
633 int rem, err, def = 0;
634
635 result = kzalloc(sizeof(*result), GFP_KERNEL);
636 if (!result)
637 return ERR_PTR(-ENOMEM);
638
639 result->def = -1;
640 result->defmgmt = -1;
641
642 nla_for_each_nested(key, keys, rem) {
643 memset(&parse, 0, sizeof(parse));
644 parse.idx = -1;
645
646 err = nl80211_parse_key_new(key, &parse);
647 if (err)
648 goto error;
649 err = -EINVAL;
650 if (!parse.p.key)
651 goto error;
652 if (parse.idx < 0 || parse.idx > 4)
653 goto error;
654 if (parse.def) {
655 if (def)
656 goto error;
657 def = 1;
658 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100659 if (!parse.def_uni || !parse.def_multi)
660 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200661 } else if (parse.defmgmt)
662 goto error;
663 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200664 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200665 if (err)
666 goto error;
667 result->params[parse.idx].cipher = parse.p.cipher;
668 result->params[parse.idx].key_len = parse.p.key_len;
669 result->params[parse.idx].key = result->data[parse.idx];
670 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
671 }
672
673 return result;
674 error:
675 kfree(result);
676 return ERR_PTR(err);
677}
678
679static int nl80211_key_allowed(struct wireless_dev *wdev)
680{
681 ASSERT_WDEV_LOCK(wdev);
682
Johannes Bergfffd0932009-07-08 14:22:54 +0200683 switch (wdev->iftype) {
684 case NL80211_IFTYPE_AP:
685 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200686 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700687 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200688 break;
689 case NL80211_IFTYPE_ADHOC:
690 if (!wdev->current_bss)
691 return -ENOLINK;
692 break;
693 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200694 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200695 if (wdev->sme_state != CFG80211_SME_CONNECTED)
696 return -ENOLINK;
697 break;
698 default:
699 return -EINVAL;
700 }
701
702 return 0;
703}
704
Johannes Berg7527a782011-05-13 10:58:57 +0200705static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
706{
707 struct nlattr *nl_modes = nla_nest_start(msg, attr);
708 int i;
709
710 if (!nl_modes)
711 goto nla_put_failure;
712
713 i = 0;
714 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400715 if ((ifmodes & 1) && nla_put_flag(msg, i))
716 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200717 ifmodes >>= 1;
718 i++;
719 }
720
721 nla_nest_end(msg, nl_modes);
722 return 0;
723
724nla_put_failure:
725 return -ENOBUFS;
726}
727
728static int nl80211_put_iface_combinations(struct wiphy *wiphy,
729 struct sk_buff *msg)
730{
731 struct nlattr *nl_combis;
732 int i, j;
733
734 nl_combis = nla_nest_start(msg,
735 NL80211_ATTR_INTERFACE_COMBINATIONS);
736 if (!nl_combis)
737 goto nla_put_failure;
738
739 for (i = 0; i < wiphy->n_iface_combinations; i++) {
740 const struct ieee80211_iface_combination *c;
741 struct nlattr *nl_combi, *nl_limits;
742
743 c = &wiphy->iface_combinations[i];
744
745 nl_combi = nla_nest_start(msg, i + 1);
746 if (!nl_combi)
747 goto nla_put_failure;
748
749 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
750 if (!nl_limits)
751 goto nla_put_failure;
752
753 for (j = 0; j < c->n_limits; j++) {
754 struct nlattr *nl_limit;
755
756 nl_limit = nla_nest_start(msg, j + 1);
757 if (!nl_limit)
758 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400759 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
760 c->limits[j].max))
761 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200762 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
763 c->limits[j].types))
764 goto nla_put_failure;
765 nla_nest_end(msg, nl_limit);
766 }
767
768 nla_nest_end(msg, nl_limits);
769
David S. Miller9360ffd2012-03-29 04:41:26 -0400770 if (c->beacon_int_infra_match &&
771 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
772 goto nla_put_failure;
773 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
774 c->num_different_channels) ||
775 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
776 c->max_interfaces))
777 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200778
779 nla_nest_end(msg, nl_combi);
780 }
781
782 nla_nest_end(msg, nl_combis);
783
784 return 0;
785nla_put_failure:
786 return -ENOBUFS;
787}
788
Johannes Berg55682962007-09-20 13:09:35 -0400789static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
790 struct cfg80211_registered_device *dev)
791{
792 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100793 struct nlattr *nl_bands, *nl_band;
794 struct nlattr *nl_freqs, *nl_freq;
795 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100796 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100797 enum ieee80211_band band;
798 struct ieee80211_channel *chan;
799 struct ieee80211_rate *rate;
800 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200801 const struct ieee80211_txrx_stypes *mgmt_stypes =
802 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400803
804 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
805 if (!hdr)
806 return -1;
807
David S. Miller9360ffd2012-03-29 04:41:26 -0400808 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
809 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
810 nla_put_u32(msg, NL80211_ATTR_GENERATION,
811 cfg80211_rdev_list_generation) ||
812 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
813 dev->wiphy.retry_short) ||
814 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
815 dev->wiphy.retry_long) ||
816 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
817 dev->wiphy.frag_threshold) ||
818 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
819 dev->wiphy.rts_threshold) ||
820 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
821 dev->wiphy.coverage_class) ||
822 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
823 dev->wiphy.max_scan_ssids) ||
824 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
825 dev->wiphy.max_sched_scan_ssids) ||
826 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
827 dev->wiphy.max_scan_ie_len) ||
828 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
829 dev->wiphy.max_sched_scan_ie_len) ||
830 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
831 dev->wiphy.max_match_sets))
832 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200833
David S. Miller9360ffd2012-03-29 04:41:26 -0400834 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
835 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
836 goto nla_put_failure;
837 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
838 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
839 goto nla_put_failure;
840 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
841 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
842 goto nla_put_failure;
843 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
844 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
845 goto nla_put_failure;
846 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
847 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
848 goto nla_put_failure;
849 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
850 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
851 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200852
David S. Miller9360ffd2012-03-29 04:41:26 -0400853 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
854 sizeof(u32) * dev->wiphy.n_cipher_suites,
855 dev->wiphy.cipher_suites))
856 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100857
David S. Miller9360ffd2012-03-29 04:41:26 -0400858 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
859 dev->wiphy.max_num_pmkids))
860 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530861
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
863 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
864 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200865
David S. Miller9360ffd2012-03-29 04:41:26 -0400866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
867 dev->wiphy.available_antennas_tx) ||
868 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
869 dev->wiphy.available_antennas_rx))
870 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100871
David S. Miller9360ffd2012-03-29 04:41:26 -0400872 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
873 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
874 dev->wiphy.probe_resp_offload))
875 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200876
Bruno Randolf7f531e02010-12-16 11:30:22 +0900877 if ((dev->wiphy.available_antennas_tx ||
878 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900879 u32 tx_ant = 0, rx_ant = 0;
880 int res;
881 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
882 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400883 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
884 tx_ant) ||
885 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
886 rx_ant))
887 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900888 }
889 }
890
Johannes Berg7527a782011-05-13 10:58:57 +0200891 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
892 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700893 goto nla_put_failure;
894
Johannes Bergee688b002008-01-24 19:38:39 +0100895 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
896 if (!nl_bands)
897 goto nla_put_failure;
898
899 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
900 if (!dev->wiphy.bands[band])
901 continue;
902
903 nl_band = nla_nest_start(msg, band);
904 if (!nl_band)
905 goto nla_put_failure;
906
Johannes Bergd51626d2008-10-09 12:20:13 +0200907 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400908 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
909 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
910 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
911 &dev->wiphy.bands[band]->ht_cap.mcs) ||
912 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
913 dev->wiphy.bands[band]->ht_cap.cap) ||
914 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
915 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
916 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
917 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
918 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200919
Johannes Bergee688b002008-01-24 19:38:39 +0100920 /* add frequencies */
921 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
922 if (!nl_freqs)
923 goto nla_put_failure;
924
925 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
926 nl_freq = nla_nest_start(msg, i);
927 if (!nl_freq)
928 goto nla_put_failure;
929
930 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100931
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400932 if (nl80211_msg_put_channel(msg, chan))
933 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200934
Johannes Bergee688b002008-01-24 19:38:39 +0100935 nla_nest_end(msg, nl_freq);
936 }
937
938 nla_nest_end(msg, nl_freqs);
939
940 /* add bitrates */
941 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
942 if (!nl_rates)
943 goto nla_put_failure;
944
945 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
946 nl_rate = nla_nest_start(msg, i);
947 if (!nl_rate)
948 goto nla_put_failure;
949
950 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400951 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
952 rate->bitrate))
953 goto nla_put_failure;
954 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
955 nla_put_flag(msg,
956 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
957 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100958
959 nla_nest_end(msg, nl_rate);
960 }
961
962 nla_nest_end(msg, nl_rates);
963
964 nla_nest_end(msg, nl_band);
965 }
966 nla_nest_end(msg, nl_bands);
967
Johannes Berg8fdc6212009-03-14 09:34:01 +0100968 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
969 if (!nl_cmds)
970 goto nla_put_failure;
971
972 i = 0;
973#define CMD(op, n) \
974 do { \
975 if (dev->ops->op) { \
976 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400977 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
978 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100979 } \
980 } while (0)
981
982 CMD(add_virtual_intf, NEW_INTERFACE);
983 CMD(change_virtual_intf, SET_INTERFACE);
984 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100985 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100986 CMD(add_station, NEW_STATION);
987 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800988 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100989 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200990 CMD(auth, AUTHENTICATE);
991 CMD(assoc, ASSOCIATE);
992 CMD(deauth, DEAUTHENTICATE);
993 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200994 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100995 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100996 CMD(set_pmksa, SET_PMKSA);
997 CMD(del_pmksa, DEL_PMKSA);
998 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +0100999 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1000 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001001 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001002 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001003 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001004 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001005 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001006 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1007 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001008 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001009 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001010 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001011 i++;
1012 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1013 goto nla_put_failure;
1014 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001015 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001016 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1017 CMD(tdls_mgmt, TDLS_MGMT);
1018 CMD(tdls_oper, TDLS_OPER);
1019 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001020 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1021 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001022 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001023 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e7602302011-11-04 11:18:17 +01001024 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1025 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001026 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1027 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01001028 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001029
Kalle Valo4745fc02011-11-17 19:06:10 +02001030#ifdef CONFIG_NL80211_TESTMODE
1031 CMD(testmode_cmd, TESTMODE);
1032#endif
1033
Johannes Berg8fdc6212009-03-14 09:34:01 +01001034#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001035
Johannes Berg6829c872009-07-02 09:13:27 +02001036 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001037 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001038 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1039 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040 }
1041
Johannes Berg6829c872009-07-02 09:13:27 +02001042 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001043 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001044 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1045 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001046 }
1047
Johannes Berg8fdc6212009-03-14 09:34:01 +01001048 nla_nest_end(msg, nl_cmds);
1049
Johannes Berg7c4ef712011-11-18 15:33:48 +01001050 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1052 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1053 dev->wiphy.max_remain_on_channel_duration))
1054 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001055
David S. Miller9360ffd2012-03-29 04:41:26 -04001056 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1057 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1058 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001059
Johannes Berg2e161f72010-08-12 15:38:38 +02001060 if (mgmt_stypes) {
1061 u16 stypes;
1062 struct nlattr *nl_ftypes, *nl_ifs;
1063 enum nl80211_iftype ift;
1064
1065 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1066 if (!nl_ifs)
1067 goto nla_put_failure;
1068
1069 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1070 nl_ftypes = nla_nest_start(msg, ift);
1071 if (!nl_ftypes)
1072 goto nla_put_failure;
1073 i = 0;
1074 stypes = mgmt_stypes[ift].tx;
1075 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001076 if ((stypes & 1) &&
1077 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1078 (i << 4) | IEEE80211_FTYPE_MGMT))
1079 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001080 stypes >>= 1;
1081 i++;
1082 }
1083 nla_nest_end(msg, nl_ftypes);
1084 }
1085
Johannes Berg74b70a42010-08-24 12:15:53 +02001086 nla_nest_end(msg, nl_ifs);
1087
Johannes Berg2e161f72010-08-12 15:38:38 +02001088 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1089 if (!nl_ifs)
1090 goto nla_put_failure;
1091
1092 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1093 nl_ftypes = nla_nest_start(msg, ift);
1094 if (!nl_ftypes)
1095 goto nla_put_failure;
1096 i = 0;
1097 stypes = mgmt_stypes[ift].rx;
1098 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001099 if ((stypes & 1) &&
1100 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1101 (i << 4) | IEEE80211_FTYPE_MGMT))
1102 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001103 stypes >>= 1;
1104 i++;
1105 }
1106 nla_nest_end(msg, nl_ftypes);
1107 }
1108 nla_nest_end(msg, nl_ifs);
1109 }
1110
Johannes Bergff1b6e62011-05-04 15:37:28 +02001111 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1112 struct nlattr *nl_wowlan;
1113
1114 nl_wowlan = nla_nest_start(msg,
1115 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1116 if (!nl_wowlan)
1117 goto nla_put_failure;
1118
David S. Miller9360ffd2012-03-29 04:41:26 -04001119 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1120 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1121 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1122 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1123 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1124 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1125 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1126 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1127 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1128 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1129 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1130 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1131 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1132 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1133 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1135 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001136 if (dev->wiphy.wowlan.n_patterns) {
1137 struct nl80211_wowlan_pattern_support pat = {
1138 .max_patterns = dev->wiphy.wowlan.n_patterns,
1139 .min_pattern_len =
1140 dev->wiphy.wowlan.pattern_min_len,
1141 .max_pattern_len =
1142 dev->wiphy.wowlan.pattern_max_len,
1143 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001144 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1145 sizeof(pat), &pat))
1146 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001147 }
1148
1149 nla_nest_end(msg, nl_wowlan);
1150 }
1151
Johannes Berg7527a782011-05-13 10:58:57 +02001152 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1153 dev->wiphy.software_iftypes))
1154 goto nla_put_failure;
1155
1156 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1157 goto nla_put_failure;
1158
David S. Miller9360ffd2012-03-29 04:41:26 -04001159 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1160 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1161 dev->wiphy.ap_sme_capa))
1162 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001163
David S. Miller9360ffd2012-03-29 04:41:26 -04001164 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1165 dev->wiphy.features))
1166 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001167
David S. Miller9360ffd2012-03-29 04:41:26 -04001168 if (dev->wiphy.ht_capa_mod_mask &&
1169 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1170 sizeof(*dev->wiphy.ht_capa_mod_mask),
1171 dev->wiphy.ht_capa_mod_mask))
1172 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001173
Johannes Berg55682962007-09-20 13:09:35 -04001174 return genlmsg_end(msg, hdr);
1175
1176 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001177 genlmsg_cancel(msg, hdr);
1178 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001179}
1180
1181static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1182{
1183 int idx = 0;
1184 int start = cb->args[0];
1185 struct cfg80211_registered_device *dev;
1186
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001187 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001188 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001189 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1190 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001191 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001192 continue;
1193 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1194 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001195 dev) < 0) {
1196 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001197 break;
Julius Volzb4637272008-07-08 14:02:19 +02001198 }
Johannes Berg55682962007-09-20 13:09:35 -04001199 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001200 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001201
1202 cb->args[0] = idx;
1203
1204 return skb->len;
1205}
1206
1207static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1208{
1209 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001210 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001211
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001213 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001214 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001215
Johannes Berg4c476992010-10-04 21:36:35 +02001216 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1217 nlmsg_free(msg);
1218 return -ENOBUFS;
1219 }
Johannes Berg55682962007-09-20 13:09:35 -04001220
Johannes Berg134e6372009-07-10 09:51:34 +00001221 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001222}
1223
Jouni Malinen31888482008-10-30 16:59:24 +02001224static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1225 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1226 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1227 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1228 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1229 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1230};
1231
1232static int parse_txq_params(struct nlattr *tb[],
1233 struct ieee80211_txq_params *txq_params)
1234{
Johannes Berga3304b02012-03-28 11:04:24 +02001235 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001236 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1237 !tb[NL80211_TXQ_ATTR_AIFS])
1238 return -EINVAL;
1239
Johannes Berga3304b02012-03-28 11:04:24 +02001240 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001241 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1242 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1243 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1244 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1245
Johannes Berga3304b02012-03-28 11:04:24 +02001246 if (txq_params->ac >= NL80211_NUM_ACS)
1247 return -EINVAL;
1248
Jouni Malinen31888482008-10-30 16:59:24 +02001249 return 0;
1250}
1251
Johannes Bergf444de02010-05-05 15:25:02 +02001252static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1253{
1254 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001255 * You can only set the channel explicitly for WDS interfaces,
1256 * all others have their channel managed via their respective
1257 * "establish a connection" command (connect, join, ...)
1258 *
1259 * For AP/GO and mesh mode, the channel can be set with the
1260 * channel userspace API, but is only stored and passed to the
1261 * low-level driver when the AP starts or the mesh is joined.
1262 * This is for backward compatibility, userspace can also give
1263 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001264 *
1265 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001266 * whatever else is going on, so they have their own special
1267 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001268 */
1269 return !wdev ||
1270 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001271 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001272 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1273 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001274}
1275
Johannes Bergcd6c6592012-05-10 21:27:18 +02001276static bool nl80211_valid_channel_type(struct genl_info *info,
1277 enum nl80211_channel_type *channel_type)
1278{
1279 enum nl80211_channel_type tmp;
1280
1281 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1282 return false;
1283
1284 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1285 if (tmp != NL80211_CHAN_NO_HT &&
1286 tmp != NL80211_CHAN_HT20 &&
1287 tmp != NL80211_CHAN_HT40PLUS &&
1288 tmp != NL80211_CHAN_HT40MINUS)
1289 return false;
1290
1291 if (channel_type)
1292 *channel_type = tmp;
1293
1294 return true;
1295}
1296
Johannes Bergf444de02010-05-05 15:25:02 +02001297static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1298 struct wireless_dev *wdev,
1299 struct genl_info *info)
1300{
Johannes Bergaa430da2012-05-16 23:50:18 +02001301 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001302 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1303 u32 freq;
1304 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001305 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1306
1307 if (wdev)
1308 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001309
1310 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1311 return -EINVAL;
1312
1313 if (!nl80211_can_set_dev_channel(wdev))
1314 return -EOPNOTSUPP;
1315
Johannes Bergcd6c6592012-05-10 21:27:18 +02001316 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1317 !nl80211_valid_channel_type(info, &channel_type))
1318 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001319
1320 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1321
1322 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001323 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001324 case NL80211_IFTYPE_AP:
1325 case NL80211_IFTYPE_P2P_GO:
1326 if (wdev->beacon_interval) {
1327 result = -EBUSY;
1328 break;
1329 }
1330 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1331 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1332 channel,
1333 channel_type)) {
1334 result = -EINVAL;
1335 break;
1336 }
1337 wdev->preset_chan = channel;
1338 wdev->preset_chantype = channel_type;
1339 result = 0;
1340 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001341 case NL80211_IFTYPE_MESH_POINT:
1342 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1343 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001344 case NL80211_IFTYPE_MONITOR:
1345 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1346 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001347 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001348 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001349 }
1350 mutex_unlock(&rdev->devlist_mtx);
1351
1352 return result;
1353}
1354
1355static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1356{
Johannes Berg4c476992010-10-04 21:36:35 +02001357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1358 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001359
Johannes Berg4c476992010-10-04 21:36:35 +02001360 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001361}
1362
Bill Jordane8347eb2010-10-01 13:54:28 -04001363static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1364{
Johannes Berg43b19952010-10-07 13:10:30 +02001365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1366 struct net_device *dev = info->user_ptr[1];
1367 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001368 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001369
1370 if (!info->attrs[NL80211_ATTR_MAC])
1371 return -EINVAL;
1372
Johannes Berg43b19952010-10-07 13:10:30 +02001373 if (netif_running(dev))
1374 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001375
Johannes Berg43b19952010-10-07 13:10:30 +02001376 if (!rdev->ops->set_wds_peer)
1377 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001378
Johannes Berg43b19952010-10-07 13:10:30 +02001379 if (wdev->iftype != NL80211_IFTYPE_WDS)
1380 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001381
1382 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001383 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001384}
1385
1386
Johannes Berg55682962007-09-20 13:09:35 -04001387static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1388{
1389 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001390 struct net_device *netdev = NULL;
1391 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001392 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001393 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001394 u32 changed;
1395 u8 retry_short = 0, retry_long = 0;
1396 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001397 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001398
Johannes Bergf444de02010-05-05 15:25:02 +02001399 /*
1400 * Try to find the wiphy and netdev. Normally this
1401 * function shouldn't need the netdev, but this is
1402 * done for backward compatibility -- previously
1403 * setting the channel was done per wiphy, but now
1404 * it is per netdev. Previous userland like hostapd
1405 * also passed a netdev to set_wiphy, so that it is
1406 * possible to let that go to the right netdev!
1407 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001408 mutex_lock(&cfg80211_mutex);
1409
Johannes Bergf444de02010-05-05 15:25:02 +02001410 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1411 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1412
1413 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1414 if (netdev && netdev->ieee80211_ptr) {
1415 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1416 mutex_lock(&rdev->mtx);
1417 } else
1418 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001419 }
1420
Johannes Bergf444de02010-05-05 15:25:02 +02001421 if (!netdev) {
1422 rdev = __cfg80211_rdev_from_info(info);
1423 if (IS_ERR(rdev)) {
1424 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001425 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001426 }
1427 wdev = NULL;
1428 netdev = NULL;
1429 result = 0;
1430
1431 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001432 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001433 wdev = netdev->ieee80211_ptr;
1434 else
1435 wdev = NULL;
1436
1437 /*
1438 * end workaround code, by now the rdev is available
1439 * and locked, and wdev may or may not be NULL.
1440 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001441
1442 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001443 result = cfg80211_dev_rename(
1444 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001445
1446 mutex_unlock(&cfg80211_mutex);
1447
1448 if (result)
1449 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001450
Jouni Malinen31888482008-10-30 16:59:24 +02001451 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1452 struct ieee80211_txq_params txq_params;
1453 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1454
1455 if (!rdev->ops->set_txq_params) {
1456 result = -EOPNOTSUPP;
1457 goto bad_res;
1458 }
1459
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001460 if (!netdev) {
1461 result = -EINVAL;
1462 goto bad_res;
1463 }
1464
Johannes Berg133a3ff2011-11-03 14:50:13 +01001465 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1466 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1467 result = -EINVAL;
1468 goto bad_res;
1469 }
1470
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001471 if (!netif_running(netdev)) {
1472 result = -ENETDOWN;
1473 goto bad_res;
1474 }
1475
Jouni Malinen31888482008-10-30 16:59:24 +02001476 nla_for_each_nested(nl_txq_params,
1477 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1478 rem_txq_params) {
1479 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1480 nla_data(nl_txq_params),
1481 nla_len(nl_txq_params),
1482 txq_params_policy);
1483 result = parse_txq_params(tb, &txq_params);
1484 if (result)
1485 goto bad_res;
1486
1487 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001488 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001489 &txq_params);
1490 if (result)
1491 goto bad_res;
1492 }
1493 }
1494
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001495 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001496 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001497 if (result)
1498 goto bad_res;
1499 }
1500
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001501 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1502 enum nl80211_tx_power_setting type;
1503 int idx, mbm = 0;
1504
1505 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001506 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001507 goto bad_res;
1508 }
1509
1510 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1511 type = nla_get_u32(info->attrs[idx]);
1512
1513 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1514 (type != NL80211_TX_POWER_AUTOMATIC)) {
1515 result = -EINVAL;
1516 goto bad_res;
1517 }
1518
1519 if (type != NL80211_TX_POWER_AUTOMATIC) {
1520 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1521 mbm = nla_get_u32(info->attrs[idx]);
1522 }
1523
1524 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1525 if (result)
1526 goto bad_res;
1527 }
1528
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001529 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1530 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1531 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001532 if ((!rdev->wiphy.available_antennas_tx &&
1533 !rdev->wiphy.available_antennas_rx) ||
1534 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001535 result = -EOPNOTSUPP;
1536 goto bad_res;
1537 }
1538
1539 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1540 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1541
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001542 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001543 * available antenna masks, except for the "all" mask */
1544 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1545 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001546 result = -EINVAL;
1547 goto bad_res;
1548 }
1549
Bruno Randolf7f531e02010-12-16 11:30:22 +09001550 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1551 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001552
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001553 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1554 if (result)
1555 goto bad_res;
1556 }
1557
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001558 changed = 0;
1559
1560 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1561 retry_short = nla_get_u8(
1562 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1563 if (retry_short == 0) {
1564 result = -EINVAL;
1565 goto bad_res;
1566 }
1567 changed |= WIPHY_PARAM_RETRY_SHORT;
1568 }
1569
1570 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1571 retry_long = nla_get_u8(
1572 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1573 if (retry_long == 0) {
1574 result = -EINVAL;
1575 goto bad_res;
1576 }
1577 changed |= WIPHY_PARAM_RETRY_LONG;
1578 }
1579
1580 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1581 frag_threshold = nla_get_u32(
1582 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1583 if (frag_threshold < 256) {
1584 result = -EINVAL;
1585 goto bad_res;
1586 }
1587 if (frag_threshold != (u32) -1) {
1588 /*
1589 * Fragments (apart from the last one) are required to
1590 * have even length. Make the fragmentation code
1591 * simpler by stripping LSB should someone try to use
1592 * odd threshold value.
1593 */
1594 frag_threshold &= ~0x1;
1595 }
1596 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1597 }
1598
1599 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1600 rts_threshold = nla_get_u32(
1601 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1602 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1603 }
1604
Lukáš Turek81077e82009-12-21 22:50:47 +01001605 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1606 coverage_class = nla_get_u8(
1607 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1608 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1609 }
1610
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001611 if (changed) {
1612 u8 old_retry_short, old_retry_long;
1613 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001614 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001615
1616 if (!rdev->ops->set_wiphy_params) {
1617 result = -EOPNOTSUPP;
1618 goto bad_res;
1619 }
1620
1621 old_retry_short = rdev->wiphy.retry_short;
1622 old_retry_long = rdev->wiphy.retry_long;
1623 old_frag_threshold = rdev->wiphy.frag_threshold;
1624 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001625 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001626
1627 if (changed & WIPHY_PARAM_RETRY_SHORT)
1628 rdev->wiphy.retry_short = retry_short;
1629 if (changed & WIPHY_PARAM_RETRY_LONG)
1630 rdev->wiphy.retry_long = retry_long;
1631 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1632 rdev->wiphy.frag_threshold = frag_threshold;
1633 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1634 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001635 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1636 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001637
1638 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1639 if (result) {
1640 rdev->wiphy.retry_short = old_retry_short;
1641 rdev->wiphy.retry_long = old_retry_long;
1642 rdev->wiphy.frag_threshold = old_frag_threshold;
1643 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001644 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001645 }
1646 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001647
Johannes Berg306d6112008-12-08 12:39:04 +01001648 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001649 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001650 if (netdev)
1651 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001652 return result;
1653}
1654
1655
1656static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001657 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001658 struct net_device *dev)
1659{
1660 void *hdr;
1661
1662 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1663 if (!hdr)
1664 return -1;
1665
David S. Miller9360ffd2012-03-29 04:41:26 -04001666 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1667 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1668 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1669 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1670 dev->ieee80211_ptr->iftype) ||
1671 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1672 rdev->devlist_generation ^
1673 (cfg80211_rdev_list_generation << 2)))
1674 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001675
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001676 if (rdev->ops->get_channel) {
1677 struct ieee80211_channel *chan;
1678 enum nl80211_channel_type channel_type;
1679
1680 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001681 if (chan &&
1682 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1683 chan->center_freq) ||
1684 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1685 channel_type)))
1686 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001687 }
1688
Johannes Berg55682962007-09-20 13:09:35 -04001689 return genlmsg_end(msg, hdr);
1690
1691 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001692 genlmsg_cancel(msg, hdr);
1693 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001694}
1695
1696static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1697{
1698 int wp_idx = 0;
1699 int if_idx = 0;
1700 int wp_start = cb->args[0];
1701 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001702 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001703 struct wireless_dev *wdev;
1704
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001705 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001706 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1707 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001708 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001709 if (wp_idx < wp_start) {
1710 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001711 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001712 }
Johannes Berg55682962007-09-20 13:09:35 -04001713 if_idx = 0;
1714
Johannes Bergf5ea9122009-08-07 16:17:38 +02001715 mutex_lock(&rdev->devlist_mtx);
1716 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001717 if (if_idx < if_start) {
1718 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001719 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001720 }
Johannes Berg55682962007-09-20 13:09:35 -04001721 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1722 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001723 rdev, wdev->netdev) < 0) {
1724 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001725 goto out;
1726 }
1727 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001728 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001729 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001730
1731 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001732 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001733 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001734 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001735
1736 cb->args[0] = wp_idx;
1737 cb->args[1] = if_idx;
1738
1739 return skb->len;
1740}
1741
1742static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1743{
1744 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001745 struct cfg80211_registered_device *dev = info->user_ptr[0];
1746 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001747
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001748 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001749 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001750 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001751
Johannes Bergd7264052009-04-19 16:23:20 +02001752 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001753 dev, netdev) < 0) {
1754 nlmsg_free(msg);
1755 return -ENOBUFS;
1756 }
Johannes Berg55682962007-09-20 13:09:35 -04001757
Johannes Berg134e6372009-07-10 09:51:34 +00001758 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001759}
1760
Michael Wu66f7ac52008-01-31 19:48:22 +01001761static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1762 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1763 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1764 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1765 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1766 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1767};
1768
1769static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1770{
1771 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1772 int flag;
1773
1774 *mntrflags = 0;
1775
1776 if (!nla)
1777 return -EINVAL;
1778
1779 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1780 nla, mntr_flags_policy))
1781 return -EINVAL;
1782
1783 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1784 if (flags[flag])
1785 *mntrflags |= (1<<flag);
1786
1787 return 0;
1788}
1789
Johannes Berg9bc383d2009-11-19 11:55:19 +01001790static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001791 struct net_device *netdev, u8 use_4addr,
1792 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001793{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001794 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001795 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001796 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001797 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001798 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001799
1800 switch (iftype) {
1801 case NL80211_IFTYPE_AP_VLAN:
1802 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1803 return 0;
1804 break;
1805 case NL80211_IFTYPE_STATION:
1806 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1807 return 0;
1808 break;
1809 default:
1810 break;
1811 }
1812
1813 return -EOPNOTSUPP;
1814}
1815
Johannes Berg55682962007-09-20 13:09:35 -04001816static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1817{
Johannes Berg4c476992010-10-04 21:36:35 +02001818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001819 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001820 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001821 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001822 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001823 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001824 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001825
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001826 memset(&params, 0, sizeof(params));
1827
Johannes Berg04a773a2009-04-19 21:24:32 +02001828 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001829
Johannes Berg723b0382008-09-16 20:22:09 +02001830 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001831 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001832 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001833 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001834 if (ntype > NL80211_IFTYPE_MAX)
1835 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001836 }
1837
Johannes Berg92ffe052008-09-16 20:39:36 +02001838 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001839 struct wireless_dev *wdev = dev->ieee80211_ptr;
1840
Johannes Berg4c476992010-10-04 21:36:35 +02001841 if (ntype != NL80211_IFTYPE_MESH_POINT)
1842 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001843 if (netif_running(dev))
1844 return -EBUSY;
1845
1846 wdev_lock(wdev);
1847 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1848 IEEE80211_MAX_MESH_ID_LEN);
1849 wdev->mesh_id_up_len =
1850 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1851 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1852 wdev->mesh_id_up_len);
1853 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001854 }
1855
Felix Fietkau8b787642009-11-10 18:53:10 +01001856 if (info->attrs[NL80211_ATTR_4ADDR]) {
1857 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1858 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001859 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001860 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001861 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001862 } else {
1863 params.use_4addr = -1;
1864 }
1865
Johannes Berg92ffe052008-09-16 20:39:36 +02001866 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001867 if (ntype != NL80211_IFTYPE_MONITOR)
1868 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001869 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1870 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001871 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001872 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001873
1874 flags = &_flags;
1875 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001876 }
Johannes Berg3b858752009-03-12 09:55:09 +01001877
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001878 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001879 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001880 else
1881 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001882
Johannes Berg9bc383d2009-11-19 11:55:19 +01001883 if (!err && params.use_4addr != -1)
1884 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1885
Johannes Berg55682962007-09-20 13:09:35 -04001886 return err;
1887}
1888
1889static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1890{
Johannes Berg4c476992010-10-04 21:36:35 +02001891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001892 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001893 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001894 int err;
1895 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001896 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001897
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001898 memset(&params, 0, sizeof(params));
1899
Johannes Berg55682962007-09-20 13:09:35 -04001900 if (!info->attrs[NL80211_ATTR_IFNAME])
1901 return -EINVAL;
1902
1903 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1904 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1905 if (type > NL80211_IFTYPE_MAX)
1906 return -EINVAL;
1907 }
1908
Johannes Berg79c97e92009-07-07 03:56:12 +02001909 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001910 !(rdev->wiphy.interface_modes & (1 << type)))
1911 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001912
Johannes Berg9bc383d2009-11-19 11:55:19 +01001913 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001914 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001915 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001916 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001917 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001918 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001919
Michael Wu66f7ac52008-01-31 19:48:22 +01001920 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1921 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1922 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001923 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001924 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001925 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001926 if (IS_ERR(dev))
1927 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001928
Johannes Berg29cbe682010-12-03 09:20:44 +01001929 if (type == NL80211_IFTYPE_MESH_POINT &&
1930 info->attrs[NL80211_ATTR_MESH_ID]) {
1931 struct wireless_dev *wdev = dev->ieee80211_ptr;
1932
1933 wdev_lock(wdev);
1934 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1935 IEEE80211_MAX_MESH_ID_LEN);
1936 wdev->mesh_id_up_len =
1937 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1938 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1939 wdev->mesh_id_up_len);
1940 wdev_unlock(wdev);
1941 }
1942
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001943 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001944}
1945
1946static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1947{
Johannes Berg4c476992010-10-04 21:36:35 +02001948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1949 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001950
Johannes Berg4c476992010-10-04 21:36:35 +02001951 if (!rdev->ops->del_virtual_intf)
1952 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001953
Johannes Berg4c476992010-10-04 21:36:35 +02001954 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001955}
1956
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001957static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1958{
1959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1960 struct net_device *dev = info->user_ptr[1];
1961 u16 noack_map;
1962
1963 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1964 return -EINVAL;
1965
1966 if (!rdev->ops->set_noack_map)
1967 return -EOPNOTSUPP;
1968
1969 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1970
1971 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1972}
1973
Johannes Berg41ade002007-12-19 02:03:29 +01001974struct get_key_cookie {
1975 struct sk_buff *msg;
1976 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001977 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001978};
1979
1980static void get_key_callback(void *c, struct key_params *params)
1981{
Johannes Bergb9454e82009-07-08 13:29:08 +02001982 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001983 struct get_key_cookie *cookie = c;
1984
David S. Miller9360ffd2012-03-29 04:41:26 -04001985 if ((params->key &&
1986 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1987 params->key_len, params->key)) ||
1988 (params->seq &&
1989 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
1990 params->seq_len, params->seq)) ||
1991 (params->cipher &&
1992 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1993 params->cipher)))
1994 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01001995
Johannes Bergb9454e82009-07-08 13:29:08 +02001996 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1997 if (!key)
1998 goto nla_put_failure;
1999
David S. Miller9360ffd2012-03-29 04:41:26 -04002000 if ((params->key &&
2001 nla_put(cookie->msg, NL80211_KEY_DATA,
2002 params->key_len, params->key)) ||
2003 (params->seq &&
2004 nla_put(cookie->msg, NL80211_KEY_SEQ,
2005 params->seq_len, params->seq)) ||
2006 (params->cipher &&
2007 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2008 params->cipher)))
2009 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002010
David S. Miller9360ffd2012-03-29 04:41:26 -04002011 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2012 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002013
2014 nla_nest_end(cookie->msg, key);
2015
Johannes Berg41ade002007-12-19 02:03:29 +01002016 return;
2017 nla_put_failure:
2018 cookie->error = 1;
2019}
2020
2021static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2022{
Johannes Berg4c476992010-10-04 21:36:35 +02002023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002024 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002025 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002026 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002027 const u8 *mac_addr = NULL;
2028 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002029 struct get_key_cookie cookie = {
2030 .error = 0,
2031 };
2032 void *hdr;
2033 struct sk_buff *msg;
2034
2035 if (info->attrs[NL80211_ATTR_KEY_IDX])
2036 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2037
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002038 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002039 return -EINVAL;
2040
2041 if (info->attrs[NL80211_ATTR_MAC])
2042 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2043
Johannes Berge31b8212010-10-05 19:39:30 +02002044 pairwise = !!mac_addr;
2045 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2046 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2047 if (kt >= NUM_NL80211_KEYTYPES)
2048 return -EINVAL;
2049 if (kt != NL80211_KEYTYPE_GROUP &&
2050 kt != NL80211_KEYTYPE_PAIRWISE)
2051 return -EINVAL;
2052 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2053 }
2054
Johannes Berg4c476992010-10-04 21:36:35 +02002055 if (!rdev->ops->get_key)
2056 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002057
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002059 if (!msg)
2060 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002061
2062 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2063 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002064 if (IS_ERR(hdr))
2065 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002066
2067 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002068 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002069
David S. Miller9360ffd2012-03-29 04:41:26 -04002070 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2071 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2072 goto nla_put_failure;
2073 if (mac_addr &&
2074 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2075 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002076
Johannes Berge31b8212010-10-05 19:39:30 +02002077 if (pairwise && mac_addr &&
2078 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2079 return -ENOENT;
2080
2081 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2082 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002083
2084 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002085 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002086
2087 if (cookie.error)
2088 goto nla_put_failure;
2089
2090 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002091 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002092
2093 nla_put_failure:
2094 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002095 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002096 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002097 return err;
2098}
2099
2100static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2101{
Johannes Berg4c476992010-10-04 21:36:35 +02002102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002103 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002104 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002105 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002106
Johannes Bergb9454e82009-07-08 13:29:08 +02002107 err = nl80211_parse_key(info, &key);
2108 if (err)
2109 return err;
2110
2111 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002112 return -EINVAL;
2113
Johannes Bergb9454e82009-07-08 13:29:08 +02002114 /* only support setting default key */
2115 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002116 return -EINVAL;
2117
Johannes Bergfffd0932009-07-08 14:22:54 +02002118 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002119
2120 if (key.def) {
2121 if (!rdev->ops->set_default_key) {
2122 err = -EOPNOTSUPP;
2123 goto out;
2124 }
2125
2126 err = nl80211_key_allowed(dev->ieee80211_ptr);
2127 if (err)
2128 goto out;
2129
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002130 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2131 key.def_uni, key.def_multi);
2132
2133 if (err)
2134 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002135
Johannes Berg3d23e342009-09-29 23:27:28 +02002136#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002137 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002138#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002139 } else {
2140 if (key.def_uni || !key.def_multi) {
2141 err = -EINVAL;
2142 goto out;
2143 }
2144
2145 if (!rdev->ops->set_default_mgmt_key) {
2146 err = -EOPNOTSUPP;
2147 goto out;
2148 }
2149
2150 err = nl80211_key_allowed(dev->ieee80211_ptr);
2151 if (err)
2152 goto out;
2153
2154 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2155 dev, key.idx);
2156 if (err)
2157 goto out;
2158
2159#ifdef CONFIG_CFG80211_WEXT
2160 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2161#endif
2162 }
2163
2164 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002165 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002166
Johannes Berg41ade002007-12-19 02:03:29 +01002167 return err;
2168}
2169
2170static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2171{
Johannes Berg4c476992010-10-04 21:36:35 +02002172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002173 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002174 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002175 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002176 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002177
Johannes Bergb9454e82009-07-08 13:29:08 +02002178 err = nl80211_parse_key(info, &key);
2179 if (err)
2180 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002181
Johannes Bergb9454e82009-07-08 13:29:08 +02002182 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002183 return -EINVAL;
2184
Johannes Berg41ade002007-12-19 02:03:29 +01002185 if (info->attrs[NL80211_ATTR_MAC])
2186 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2187
Johannes Berge31b8212010-10-05 19:39:30 +02002188 if (key.type == -1) {
2189 if (mac_addr)
2190 key.type = NL80211_KEYTYPE_PAIRWISE;
2191 else
2192 key.type = NL80211_KEYTYPE_GROUP;
2193 }
2194
2195 /* for now */
2196 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2197 key.type != NL80211_KEYTYPE_GROUP)
2198 return -EINVAL;
2199
Johannes Berg4c476992010-10-04 21:36:35 +02002200 if (!rdev->ops->add_key)
2201 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002202
Johannes Berge31b8212010-10-05 19:39:30 +02002203 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2204 key.type == NL80211_KEYTYPE_PAIRWISE,
2205 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002206 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002207
2208 wdev_lock(dev->ieee80211_ptr);
2209 err = nl80211_key_allowed(dev->ieee80211_ptr);
2210 if (!err)
2211 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002212 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002213 mac_addr, &key.p);
2214 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002215
Johannes Berg41ade002007-12-19 02:03:29 +01002216 return err;
2217}
2218
2219static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2220{
Johannes Berg4c476992010-10-04 21:36:35 +02002221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002222 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002223 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002224 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002225 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002226
Johannes Bergb9454e82009-07-08 13:29:08 +02002227 err = nl80211_parse_key(info, &key);
2228 if (err)
2229 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002230
2231 if (info->attrs[NL80211_ATTR_MAC])
2232 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2233
Johannes Berge31b8212010-10-05 19:39:30 +02002234 if (key.type == -1) {
2235 if (mac_addr)
2236 key.type = NL80211_KEYTYPE_PAIRWISE;
2237 else
2238 key.type = NL80211_KEYTYPE_GROUP;
2239 }
2240
2241 /* for now */
2242 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2243 key.type != NL80211_KEYTYPE_GROUP)
2244 return -EINVAL;
2245
Johannes Berg4c476992010-10-04 21:36:35 +02002246 if (!rdev->ops->del_key)
2247 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002248
Johannes Bergfffd0932009-07-08 14:22:54 +02002249 wdev_lock(dev->ieee80211_ptr);
2250 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002251
2252 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2253 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2254 err = -ENOENT;
2255
Johannes Bergfffd0932009-07-08 14:22:54 +02002256 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002257 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2258 key.type == NL80211_KEYTYPE_PAIRWISE,
2259 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002260
Johannes Berg3d23e342009-09-29 23:27:28 +02002261#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002262 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002263 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002264 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002265 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002266 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2267 }
2268#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002269 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002270
Johannes Berg41ade002007-12-19 02:03:29 +01002271 return err;
2272}
2273
Johannes Berg88600202012-02-13 15:17:18 +01002274static int nl80211_parse_beacon(struct genl_info *info,
2275 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002276{
Johannes Berg88600202012-02-13 15:17:18 +01002277 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002278
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002279 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2280 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2281 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2282 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002283 return -EINVAL;
2284
Johannes Berg88600202012-02-13 15:17:18 +01002285 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002286
Johannes Berged1b6cc2007-12-19 02:03:32 +01002287 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002288 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2289 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2290 if (!bcn->head_len)
2291 return -EINVAL;
2292 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002293 }
2294
2295 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002296 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2297 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002298 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002299 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002300 }
2301
Johannes Berg4c476992010-10-04 21:36:35 +02002302 if (!haveinfo)
2303 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002304
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002305 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002306 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2307 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002308 }
2309
2310 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002311 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002312 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002313 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002314 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2315 }
2316
2317 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002318 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002319 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002320 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002321 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2322 }
2323
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002324 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002325 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002326 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002327 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002328 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2329 }
2330
Johannes Berg88600202012-02-13 15:17:18 +01002331 return 0;
2332}
2333
2334static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2335{
2336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2337 struct net_device *dev = info->user_ptr[1];
2338 struct wireless_dev *wdev = dev->ieee80211_ptr;
2339 struct cfg80211_ap_settings params;
2340 int err;
2341
2342 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2343 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2344 return -EOPNOTSUPP;
2345
2346 if (!rdev->ops->start_ap)
2347 return -EOPNOTSUPP;
2348
2349 if (wdev->beacon_interval)
2350 return -EALREADY;
2351
2352 memset(&params, 0, sizeof(params));
2353
2354 /* these are required for START_AP */
2355 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2356 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2357 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2358 return -EINVAL;
2359
2360 err = nl80211_parse_beacon(info, &params.beacon);
2361 if (err)
2362 return err;
2363
2364 params.beacon_interval =
2365 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2366 params.dtim_period =
2367 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2368
2369 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2370 if (err)
2371 return err;
2372
2373 /*
2374 * In theory, some of these attributes should be required here
2375 * but since they were not used when the command was originally
2376 * added, keep them optional for old user space programs to let
2377 * them continue to work with drivers that do not need the
2378 * additional information -- drivers must check!
2379 */
2380 if (info->attrs[NL80211_ATTR_SSID]) {
2381 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2382 params.ssid_len =
2383 nla_len(info->attrs[NL80211_ATTR_SSID]);
2384 if (params.ssid_len == 0 ||
2385 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2386 return -EINVAL;
2387 }
2388
2389 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2390 params.hidden_ssid = nla_get_u32(
2391 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2392 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2393 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2394 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2395 return -EINVAL;
2396 }
2397
2398 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2399
2400 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2401 params.auth_type = nla_get_u32(
2402 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2403 if (!nl80211_valid_auth_type(params.auth_type))
2404 return -EINVAL;
2405 } else
2406 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2407
2408 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2409 NL80211_MAX_NR_CIPHER_SUITES);
2410 if (err)
2411 return err;
2412
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302413 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2414 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2415 return -EOPNOTSUPP;
2416 params.inactivity_timeout = nla_get_u16(
2417 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2418 }
2419
Johannes Bergaa430da2012-05-16 23:50:18 +02002420 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2421 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2422
2423 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2424 !nl80211_valid_channel_type(info, &channel_type))
2425 return -EINVAL;
2426
2427 params.channel = rdev_freq_to_chan(rdev,
2428 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2429 channel_type);
2430 if (!params.channel)
2431 return -EINVAL;
2432 params.channel_type = channel_type;
2433 } else if (wdev->preset_chan) {
2434 params.channel = wdev->preset_chan;
2435 params.channel_type = wdev->preset_chantype;
2436 } else
2437 return -EINVAL;
2438
2439 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2440 params.channel_type))
2441 return -EINVAL;
2442
Johannes Berg88600202012-02-13 15:17:18 +01002443 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2444 if (!err)
2445 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002446 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002447}
2448
Johannes Berg88600202012-02-13 15:17:18 +01002449static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2450{
2451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2452 struct net_device *dev = info->user_ptr[1];
2453 struct wireless_dev *wdev = dev->ieee80211_ptr;
2454 struct cfg80211_beacon_data params;
2455 int err;
2456
2457 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2458 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2459 return -EOPNOTSUPP;
2460
2461 if (!rdev->ops->change_beacon)
2462 return -EOPNOTSUPP;
2463
2464 if (!wdev->beacon_interval)
2465 return -EINVAL;
2466
2467 err = nl80211_parse_beacon(info, &params);
2468 if (err)
2469 return err;
2470
2471 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2472}
2473
2474static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002475{
Johannes Berg4c476992010-10-04 21:36:35 +02002476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2477 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002478 struct wireless_dev *wdev = dev->ieee80211_ptr;
2479 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002480
Johannes Berg88600202012-02-13 15:17:18 +01002481 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002482 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002483
Johannes Berg074ac8d2010-09-16 14:58:22 +02002484 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002485 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2486 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002487
Johannes Berg88600202012-02-13 15:17:18 +01002488 if (!wdev->beacon_interval)
2489 return -ENOENT;
2490
2491 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002492 if (!err)
2493 wdev->beacon_interval = 0;
2494 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002495}
2496
Johannes Berg5727ef12007-12-19 02:03:34 +01002497static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2498 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2499 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2500 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002501 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002502 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002503 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002504};
2505
Johannes Bergeccb8e82009-05-11 21:57:56 +03002506static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002507 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002508 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002509{
2510 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002511 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002512 int flag;
2513
Johannes Bergeccb8e82009-05-11 21:57:56 +03002514 /*
2515 * Try parsing the new attribute first so userspace
2516 * can specify both for older kernels.
2517 */
2518 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2519 if (nla) {
2520 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002521
Johannes Bergeccb8e82009-05-11 21:57:56 +03002522 sta_flags = nla_data(nla);
2523 params->sta_flags_mask = sta_flags->mask;
2524 params->sta_flags_set = sta_flags->set;
2525 if ((params->sta_flags_mask |
2526 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2527 return -EINVAL;
2528 return 0;
2529 }
2530
2531 /* if present, parse the old attribute */
2532
2533 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002534 if (!nla)
2535 return 0;
2536
2537 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2538 nla, sta_flags_policy))
2539 return -EINVAL;
2540
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002541 /*
2542 * Only allow certain flags for interface types so that
2543 * other attributes are silently ignored. Remember that
2544 * this is backward compatibility code with old userspace
2545 * and shouldn't be hit in other cases anyway.
2546 */
2547 switch (iftype) {
2548 case NL80211_IFTYPE_AP:
2549 case NL80211_IFTYPE_AP_VLAN:
2550 case NL80211_IFTYPE_P2P_GO:
2551 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2552 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2553 BIT(NL80211_STA_FLAG_WME) |
2554 BIT(NL80211_STA_FLAG_MFP);
2555 break;
2556 case NL80211_IFTYPE_P2P_CLIENT:
2557 case NL80211_IFTYPE_STATION:
2558 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2559 BIT(NL80211_STA_FLAG_TDLS_PEER);
2560 break;
2561 case NL80211_IFTYPE_MESH_POINT:
2562 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2563 BIT(NL80211_STA_FLAG_MFP) |
2564 BIT(NL80211_STA_FLAG_AUTHORIZED);
2565 default:
2566 return -EINVAL;
2567 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002568
Johannes Berg3383b5a2012-05-10 20:14:43 +02002569 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2570 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002571 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002572
Johannes Berg3383b5a2012-05-10 20:14:43 +02002573 /* no longer support new API additions in old API */
2574 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2575 return -EINVAL;
2576 }
2577 }
2578
Johannes Berg5727ef12007-12-19 02:03:34 +01002579 return 0;
2580}
2581
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002582static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2583 int attr)
2584{
2585 struct nlattr *rate;
2586 u16 bitrate;
2587
2588 rate = nla_nest_start(msg, attr);
2589 if (!rate)
2590 goto nla_put_failure;
2591
2592 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2593 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002594 if ((bitrate > 0 &&
2595 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2596 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2597 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2598 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2599 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2600 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2601 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2602 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002603
2604 nla_nest_end(msg, rate);
2605 return true;
2606
2607nla_put_failure:
2608 return false;
2609}
2610
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002611static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002612 int flags,
2613 struct cfg80211_registered_device *rdev,
2614 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002615 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002616{
2617 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002618 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002619
2620 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2621 if (!hdr)
2622 return -1;
2623
David S. Miller9360ffd2012-03-29 04:41:26 -04002624 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2625 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2626 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2627 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002628
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002629 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2630 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002631 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002632 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2633 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2634 sinfo->connected_time))
2635 goto nla_put_failure;
2636 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2637 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2638 sinfo->inactive_time))
2639 goto nla_put_failure;
2640 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2641 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2642 sinfo->rx_bytes))
2643 goto nla_put_failure;
2644 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2645 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2646 sinfo->tx_bytes))
2647 goto nla_put_failure;
2648 if ((sinfo->filled & STATION_INFO_LLID) &&
2649 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2650 goto nla_put_failure;
2651 if ((sinfo->filled & STATION_INFO_PLID) &&
2652 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2653 goto nla_put_failure;
2654 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2655 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2656 sinfo->plink_state))
2657 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002658 switch (rdev->wiphy.signal_type) {
2659 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002660 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2661 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2662 sinfo->signal))
2663 goto nla_put_failure;
2664 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2665 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2666 sinfo->signal_avg))
2667 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002668 break;
2669 default:
2670 break;
2671 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002672 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002673 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2674 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002675 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002676 }
2677 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2678 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2679 NL80211_STA_INFO_RX_BITRATE))
2680 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002681 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002682 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2683 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2684 sinfo->rx_packets))
2685 goto nla_put_failure;
2686 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2687 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2688 sinfo->tx_packets))
2689 goto nla_put_failure;
2690 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2691 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2692 sinfo->tx_retries))
2693 goto nla_put_failure;
2694 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2695 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2696 sinfo->tx_failed))
2697 goto nla_put_failure;
2698 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2699 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2700 sinfo->beacon_loss_count))
2701 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002702 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2703 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2704 if (!bss_param)
2705 goto nla_put_failure;
2706
David S. Miller9360ffd2012-03-29 04:41:26 -04002707 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2708 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2709 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2710 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2711 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2712 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2713 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2714 sinfo->bss_param.dtim_period) ||
2715 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2716 sinfo->bss_param.beacon_interval))
2717 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002718
2719 nla_nest_end(msg, bss_param);
2720 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002721 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2722 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2723 sizeof(struct nl80211_sta_flag_update),
2724 &sinfo->sta_flags))
2725 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002726 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2727 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2728 sinfo->t_offset))
2729 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002730 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002731
David S. Miller9360ffd2012-03-29 04:41:26 -04002732 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2733 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2734 sinfo->assoc_req_ies))
2735 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002736
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002737 return genlmsg_end(msg, hdr);
2738
2739 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002740 genlmsg_cancel(msg, hdr);
2741 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002742}
2743
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002744static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002745 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002746{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002747 struct station_info sinfo;
2748 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002749 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002750 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002751 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002753
Johannes Berg67748892010-10-04 21:14:06 +02002754 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2755 if (err)
2756 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002757
2758 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002759 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002760 goto out_err;
2761 }
2762
Johannes Bergbba95fe2008-07-29 13:22:51 +02002763 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002764 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002765 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2766 mac_addr, &sinfo);
2767 if (err == -ENOENT)
2768 break;
2769 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002770 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002771
2772 if (nl80211_send_station(skb,
2773 NETLINK_CB(cb->skb).pid,
2774 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002775 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002776 &sinfo) < 0)
2777 goto out;
2778
2779 sta_idx++;
2780 }
2781
2782
2783 out:
2784 cb->args[1] = sta_idx;
2785 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002786 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002787 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002788
2789 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002791
Johannes Berg5727ef12007-12-19 02:03:34 +01002792static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2793{
Johannes Berg4c476992010-10-04 21:36:35 +02002794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2795 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002796 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002797 struct sk_buff *msg;
2798 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002799 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002800
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002801 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002802
2803 if (!info->attrs[NL80211_ATTR_MAC])
2804 return -EINVAL;
2805
2806 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2807
Johannes Berg4c476992010-10-04 21:36:35 +02002808 if (!rdev->ops->get_station)
2809 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002810
Johannes Berg79c97e92009-07-07 03:56:12 +02002811 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002812 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002813 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002814
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002816 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002817 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002818
2819 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002820 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002821 nlmsg_free(msg);
2822 return -ENOBUFS;
2823 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002824
Johannes Berg4c476992010-10-04 21:36:35 +02002825 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002826}
2827
2828/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002829 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002830 */
Johannes Berg80b99892011-11-18 16:23:01 +01002831static struct net_device *get_vlan(struct genl_info *info,
2832 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002833{
Johannes Berg463d0182009-07-14 00:33:35 +02002834 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002835 struct net_device *v;
2836 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002837
Johannes Berg80b99892011-11-18 16:23:01 +01002838 if (!vlanattr)
2839 return NULL;
2840
2841 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2842 if (!v)
2843 return ERR_PTR(-ENODEV);
2844
2845 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2846 ret = -EINVAL;
2847 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002848 }
Johannes Berg80b99892011-11-18 16:23:01 +01002849
2850 if (!netif_running(v)) {
2851 ret = -ENETDOWN;
2852 goto error;
2853 }
2854
2855 return v;
2856 error:
2857 dev_put(v);
2858 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002859}
2860
2861static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2862{
Johannes Berg4c476992010-10-04 21:36:35 +02002863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002864 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002865 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002866 struct station_parameters params;
2867 u8 *mac_addr = NULL;
2868
2869 memset(&params, 0, sizeof(params));
2870
2871 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002872 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002873
2874 if (info->attrs[NL80211_ATTR_STA_AID])
2875 return -EINVAL;
2876
2877 if (!info->attrs[NL80211_ATTR_MAC])
2878 return -EINVAL;
2879
2880 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2881
2882 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2883 params.supported_rates =
2884 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2885 params.supported_rates_len =
2886 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2887 }
2888
2889 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2890 params.listen_interval =
2891 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2892
Jouni Malinen36aedc902008-08-25 11:58:58 +03002893 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2894 params.ht_capa =
2895 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2896
Johannes Bergbdd90d52011-12-14 12:20:27 +01002897 if (!rdev->ops->change_station)
2898 return -EOPNOTSUPP;
2899
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002900 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002901 return -EINVAL;
2902
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002903 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2904 params.plink_action =
2905 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2906
Javier Cardona9c3990a2011-05-03 16:57:11 -07002907 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2908 params.plink_state =
2909 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2910
Johannes Berga97f4422009-06-18 17:23:43 +02002911 switch (dev->ieee80211_ptr->iftype) {
2912 case NL80211_IFTYPE_AP:
2913 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002914 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002915 /* disallow mesh-specific things */
2916 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002917 return -EINVAL;
2918
2919 /* TDLS can't be set, ... */
2920 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2921 return -EINVAL;
2922 /*
2923 * ... but don't bother the driver with it. This works around
2924 * a hostapd/wpa_supplicant issue -- it always includes the
2925 * TLDS_PEER flag in the mask even for AP mode.
2926 */
2927 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2928
2929 /* accept only the listed bits */
2930 if (params.sta_flags_mask &
2931 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2932 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2933 BIT(NL80211_STA_FLAG_WME) |
2934 BIT(NL80211_STA_FLAG_MFP)))
2935 return -EINVAL;
2936
2937 /* must be last in here for error handling */
2938 params.vlan = get_vlan(info, rdev);
2939 if (IS_ERR(params.vlan))
2940 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002941 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002942 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002943 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002944 /*
2945 * Don't allow userspace to change the TDLS_PEER flag,
2946 * but silently ignore attempts to change it since we
2947 * don't have state here to verify that it doesn't try
2948 * to change the flag.
2949 */
2950 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002951 /* fall through */
2952 case NL80211_IFTYPE_ADHOC:
2953 /* disallow things sta doesn't support */
2954 if (params.plink_action)
2955 return -EINVAL;
2956 if (params.ht_capa)
2957 return -EINVAL;
2958 if (params.listen_interval >= 0)
2959 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002960 /* reject any changes other than AUTHORIZED */
2961 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2962 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002963 break;
2964 case NL80211_IFTYPE_MESH_POINT:
2965 /* disallow things mesh doesn't support */
2966 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002967 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002968 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002969 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002970 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002971 return -EINVAL;
2972 /*
2973 * No special handling for TDLS here -- the userspace
2974 * mesh code doesn't have this bug.
2975 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002976 if (params.sta_flags_mask &
2977 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002978 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002979 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002980 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002981 break;
2982 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002983 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002984 }
2985
Johannes Bergbdd90d52011-12-14 12:20:27 +01002986 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002987
Johannes Berg79c97e92009-07-07 03:56:12 +02002988 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002989
Johannes Berg5727ef12007-12-19 02:03:34 +01002990 if (params.vlan)
2991 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002992
Johannes Berg5727ef12007-12-19 02:03:34 +01002993 return err;
2994}
2995
Eliad Pellerc75786c2011-08-23 14:37:46 +03002996static struct nla_policy
2997nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2998 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2999 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3000};
3001
Johannes Berg5727ef12007-12-19 02:03:34 +01003002static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3003{
Johannes Berg4c476992010-10-04 21:36:35 +02003004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003005 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003006 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003007 struct station_parameters params;
3008 u8 *mac_addr = NULL;
3009
3010 memset(&params, 0, sizeof(params));
3011
3012 if (!info->attrs[NL80211_ATTR_MAC])
3013 return -EINVAL;
3014
Johannes Berg5727ef12007-12-19 02:03:34 +01003015 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3016 return -EINVAL;
3017
3018 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3019 return -EINVAL;
3020
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003021 if (!info->attrs[NL80211_ATTR_STA_AID])
3022 return -EINVAL;
3023
Johannes Berg5727ef12007-12-19 02:03:34 +01003024 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3025 params.supported_rates =
3026 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3027 params.supported_rates_len =
3028 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3029 params.listen_interval =
3030 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003031
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003032 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3033 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3034 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003035
Jouni Malinen36aedc902008-08-25 11:58:58 +03003036 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3037 params.ht_capa =
3038 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003039
Javier Cardona96b78df2011-04-07 15:08:33 -07003040 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3041 params.plink_action =
3042 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3043
Johannes Bergbdd90d52011-12-14 12:20:27 +01003044 if (!rdev->ops->add_station)
3045 return -EOPNOTSUPP;
3046
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003047 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003048 return -EINVAL;
3049
Johannes Bergbdd90d52011-12-14 12:20:27 +01003050 switch (dev->ieee80211_ptr->iftype) {
3051 case NL80211_IFTYPE_AP:
3052 case NL80211_IFTYPE_AP_VLAN:
3053 case NL80211_IFTYPE_P2P_GO:
3054 /* parse WME attributes if sta is WME capable */
3055 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3056 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3057 info->attrs[NL80211_ATTR_STA_WME]) {
3058 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3059 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003060
Johannes Bergbdd90d52011-12-14 12:20:27 +01003061 nla = info->attrs[NL80211_ATTR_STA_WME];
3062 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3063 nl80211_sta_wme_policy);
3064 if (err)
3065 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003066
Johannes Bergbdd90d52011-12-14 12:20:27 +01003067 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3068 params.uapsd_queues =
3069 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3070 if (params.uapsd_queues &
3071 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3072 return -EINVAL;
3073
3074 if (tb[NL80211_STA_WME_MAX_SP])
3075 params.max_sp =
3076 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3077
3078 if (params.max_sp &
3079 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3080 return -EINVAL;
3081
3082 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3083 }
3084 /* TDLS peers cannot be added */
3085 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003086 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003087 /* but don't bother the driver with it */
3088 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003089
Johannes Bergbdd90d52011-12-14 12:20:27 +01003090 /* must be last in here for error handling */
3091 params.vlan = get_vlan(info, rdev);
3092 if (IS_ERR(params.vlan))
3093 return PTR_ERR(params.vlan);
3094 break;
3095 case NL80211_IFTYPE_MESH_POINT:
3096 /* TDLS peers cannot be added */
3097 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003098 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003099 break;
3100 case NL80211_IFTYPE_STATION:
3101 /* Only TDLS peers can be added */
3102 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3103 return -EINVAL;
3104 /* Can only add if TDLS ... */
3105 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3106 return -EOPNOTSUPP;
3107 /* ... with external setup is supported */
3108 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3109 return -EOPNOTSUPP;
3110 break;
3111 default:
3112 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003113 }
3114
Johannes Bergbdd90d52011-12-14 12:20:27 +01003115 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003116
Johannes Berg79c97e92009-07-07 03:56:12 +02003117 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003118
Johannes Berg5727ef12007-12-19 02:03:34 +01003119 if (params.vlan)
3120 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003121 return err;
3122}
3123
3124static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3125{
Johannes Berg4c476992010-10-04 21:36:35 +02003126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3127 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003128 u8 *mac_addr = NULL;
3129
3130 if (info->attrs[NL80211_ATTR_MAC])
3131 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3132
Johannes Berge80cf852009-05-11 14:43:13 +02003133 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003134 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003135 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003136 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3137 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003138
Johannes Berg4c476992010-10-04 21:36:35 +02003139 if (!rdev->ops->del_station)
3140 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003141
Johannes Berg4c476992010-10-04 21:36:35 +02003142 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003143}
3144
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003145static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3146 int flags, struct net_device *dev,
3147 u8 *dst, u8 *next_hop,
3148 struct mpath_info *pinfo)
3149{
3150 void *hdr;
3151 struct nlattr *pinfoattr;
3152
3153 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3154 if (!hdr)
3155 return -1;
3156
David S. Miller9360ffd2012-03-29 04:41:26 -04003157 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3158 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3159 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3160 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3161 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003162
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003163 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3164 if (!pinfoattr)
3165 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003166 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3167 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3168 pinfo->frame_qlen))
3169 goto nla_put_failure;
3170 if (((pinfo->filled & MPATH_INFO_SN) &&
3171 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3172 ((pinfo->filled & MPATH_INFO_METRIC) &&
3173 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3174 pinfo->metric)) ||
3175 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3176 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3177 pinfo->exptime)) ||
3178 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3179 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3180 pinfo->flags)) ||
3181 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3182 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3183 pinfo->discovery_timeout)) ||
3184 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3185 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3186 pinfo->discovery_retries)))
3187 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003188
3189 nla_nest_end(msg, pinfoattr);
3190
3191 return genlmsg_end(msg, hdr);
3192
3193 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003194 genlmsg_cancel(msg, hdr);
3195 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003196}
3197
3198static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003199 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003200{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003201 struct mpath_info pinfo;
3202 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003203 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003204 u8 dst[ETH_ALEN];
3205 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003206 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003207 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003208
Johannes Berg67748892010-10-04 21:14:06 +02003209 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3210 if (err)
3211 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003212
3213 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003214 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003215 goto out_err;
3216 }
3217
Jouni Malineneec60b02009-03-20 21:21:19 +02003218 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3219 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003220 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003221 }
3222
Johannes Bergbba95fe2008-07-29 13:22:51 +02003223 while (1) {
3224 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3225 dst, next_hop, &pinfo);
3226 if (err == -ENOENT)
3227 break;
3228 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003229 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003230
3231 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3232 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3233 netdev, dst, next_hop,
3234 &pinfo) < 0)
3235 goto out;
3236
3237 path_idx++;
3238 }
3239
3240
3241 out:
3242 cb->args[1] = path_idx;
3243 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003244 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003245 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003246 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003247}
3248
3249static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3250{
Johannes Berg4c476992010-10-04 21:36:35 +02003251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003252 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003253 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003254 struct mpath_info pinfo;
3255 struct sk_buff *msg;
3256 u8 *dst = NULL;
3257 u8 next_hop[ETH_ALEN];
3258
3259 memset(&pinfo, 0, sizeof(pinfo));
3260
3261 if (!info->attrs[NL80211_ATTR_MAC])
3262 return -EINVAL;
3263
3264 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3265
Johannes Berg4c476992010-10-04 21:36:35 +02003266 if (!rdev->ops->get_mpath)
3267 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003268
Johannes Berg4c476992010-10-04 21:36:35 +02003269 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3270 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003271
Johannes Berg79c97e92009-07-07 03:56:12 +02003272 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003273 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003274 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003275
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003277 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003278 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003279
3280 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003281 dev, dst, next_hop, &pinfo) < 0) {
3282 nlmsg_free(msg);
3283 return -ENOBUFS;
3284 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003285
Johannes Berg4c476992010-10-04 21:36:35 +02003286 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003287}
3288
3289static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3290{
Johannes Berg4c476992010-10-04 21:36:35 +02003291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3292 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003293 u8 *dst = NULL;
3294 u8 *next_hop = NULL;
3295
3296 if (!info->attrs[NL80211_ATTR_MAC])
3297 return -EINVAL;
3298
3299 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3300 return -EINVAL;
3301
3302 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3303 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3304
Johannes Berg4c476992010-10-04 21:36:35 +02003305 if (!rdev->ops->change_mpath)
3306 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003307
Johannes Berg4c476992010-10-04 21:36:35 +02003308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3309 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003310
Johannes Berg4c476992010-10-04 21:36:35 +02003311 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003312}
Johannes Berg4c476992010-10-04 21:36:35 +02003313
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003314static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3315{
Johannes Berg4c476992010-10-04 21:36:35 +02003316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3317 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003318 u8 *dst = NULL;
3319 u8 *next_hop = NULL;
3320
3321 if (!info->attrs[NL80211_ATTR_MAC])
3322 return -EINVAL;
3323
3324 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3325 return -EINVAL;
3326
3327 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3328 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3329
Johannes Berg4c476992010-10-04 21:36:35 +02003330 if (!rdev->ops->add_mpath)
3331 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003332
Johannes Berg4c476992010-10-04 21:36:35 +02003333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3334 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003335
Johannes Berg4c476992010-10-04 21:36:35 +02003336 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003337}
3338
3339static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3340{
Johannes Berg4c476992010-10-04 21:36:35 +02003341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3342 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003343 u8 *dst = NULL;
3344
3345 if (info->attrs[NL80211_ATTR_MAC])
3346 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3347
Johannes Berg4c476992010-10-04 21:36:35 +02003348 if (!rdev->ops->del_mpath)
3349 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003350
Johannes Berg4c476992010-10-04 21:36:35 +02003351 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003352}
3353
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003354static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3355{
Johannes Berg4c476992010-10-04 21:36:35 +02003356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3357 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003358 struct bss_parameters params;
3359
3360 memset(&params, 0, sizeof(params));
3361 /* default to not changing parameters */
3362 params.use_cts_prot = -1;
3363 params.use_short_preamble = -1;
3364 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003365 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003366 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003367
3368 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3369 params.use_cts_prot =
3370 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3371 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3372 params.use_short_preamble =
3373 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3374 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3375 params.use_short_slot_time =
3376 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003377 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3378 params.basic_rates =
3379 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3380 params.basic_rates_len =
3381 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3382 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003383 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3384 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003385 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3386 params.ht_opmode =
3387 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003388
Johannes Berg4c476992010-10-04 21:36:35 +02003389 if (!rdev->ops->change_bss)
3390 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003391
Johannes Berg074ac8d2010-09-16 14:58:22 +02003392 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003393 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3394 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003395
Johannes Berg4c476992010-10-04 21:36:35 +02003396 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003397}
3398
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003399static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003400 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3401 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3402 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3403 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3404 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3405 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3406};
3407
3408static int parse_reg_rule(struct nlattr *tb[],
3409 struct ieee80211_reg_rule *reg_rule)
3410{
3411 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3412 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3413
3414 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3415 return -EINVAL;
3416 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3417 return -EINVAL;
3418 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3419 return -EINVAL;
3420 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3421 return -EINVAL;
3422 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3423 return -EINVAL;
3424
3425 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3426
3427 freq_range->start_freq_khz =
3428 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3429 freq_range->end_freq_khz =
3430 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3431 freq_range->max_bandwidth_khz =
3432 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3433
3434 power_rule->max_eirp =
3435 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3436
3437 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3438 power_rule->max_antenna_gain =
3439 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3440
3441 return 0;
3442}
3443
3444static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3445{
3446 int r;
3447 char *data = NULL;
3448
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003449 /*
3450 * You should only get this when cfg80211 hasn't yet initialized
3451 * completely when built-in to the kernel right between the time
3452 * window between nl80211_init() and regulatory_init(), if that is
3453 * even possible.
3454 */
3455 mutex_lock(&cfg80211_mutex);
3456 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003457 mutex_unlock(&cfg80211_mutex);
3458 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003459 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003460 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003461
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003462 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3463 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003464
3465 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3466
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003467 r = regulatory_hint_user(data);
3468
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003469 return r;
3470}
3471
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003472static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003473 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003474{
Johannes Berg4c476992010-10-04 21:36:35 +02003475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003476 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003477 struct wireless_dev *wdev = dev->ieee80211_ptr;
3478 struct mesh_config cur_params;
3479 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003480 void *hdr;
3481 struct nlattr *pinfoattr;
3482 struct sk_buff *msg;
3483
Johannes Berg29cbe682010-12-03 09:20:44 +01003484 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3485 return -EOPNOTSUPP;
3486
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003487 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003488 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003489
Johannes Berg29cbe682010-12-03 09:20:44 +01003490 wdev_lock(wdev);
3491 /* If not connected, get default parameters */
3492 if (!wdev->mesh_id_len)
3493 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3494 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003495 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003496 &cur_params);
3497 wdev_unlock(wdev);
3498
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003499 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003500 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003501
3502 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003504 if (!msg)
3505 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003506 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003507 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003508 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003509 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003510 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003511 if (!pinfoattr)
3512 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003513 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3514 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3515 cur_params.dot11MeshRetryTimeout) ||
3516 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3517 cur_params.dot11MeshConfirmTimeout) ||
3518 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3519 cur_params.dot11MeshHoldingTimeout) ||
3520 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3521 cur_params.dot11MeshMaxPeerLinks) ||
3522 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3523 cur_params.dot11MeshMaxRetries) ||
3524 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3525 cur_params.dot11MeshTTL) ||
3526 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3527 cur_params.element_ttl) ||
3528 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3529 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003530 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3531 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003532 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3533 cur_params.dot11MeshHWMPmaxPREQretries) ||
3534 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3535 cur_params.path_refresh_time) ||
3536 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3537 cur_params.min_discovery_timeout) ||
3538 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3539 cur_params.dot11MeshHWMPactivePathTimeout) ||
3540 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3541 cur_params.dot11MeshHWMPpreqMinInterval) ||
3542 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3543 cur_params.dot11MeshHWMPperrMinInterval) ||
3544 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3545 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3546 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3547 cur_params.dot11MeshHWMPRootMode) ||
3548 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3549 cur_params.dot11MeshHWMPRannInterval) ||
3550 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3551 cur_params.dot11MeshGateAnnouncementProtocol) ||
3552 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3553 cur_params.dot11MeshForwarding) ||
3554 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003555 cur_params.rssi_threshold) ||
3556 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003557 cur_params.ht_opmode) ||
3558 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3559 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3560 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003561 cur_params.dot11MeshHWMProotInterval) ||
3562 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3563 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003564 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003565 nla_nest_end(msg, pinfoattr);
3566 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003567 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003568
Johannes Berg3b858752009-03-12 09:55:09 +01003569 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003570 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003571 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003572 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003573 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003574}
3575
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003576static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003577 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3578 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3579 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3580 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3581 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3582 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003583 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003584 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003585 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003586 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3587 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3588 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3589 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3590 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003591 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003592 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003593 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003594 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003595 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003596 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003597 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3598 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003599 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3600 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003601 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003602};
3603
Javier Cardonac80d5452010-12-16 17:37:49 -08003604static const struct nla_policy
3605 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003606 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003607 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3608 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003609 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003610 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003611 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003612 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003613};
3614
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003615static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003616 struct mesh_config *cfg,
3617 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003618{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003619 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003620 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003621
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003622#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3623do {\
3624 if (table[attr_num]) {\
3625 cfg->param = nla_fn(table[attr_num]); \
3626 mask |= (1 << (attr_num - 1)); \
3627 } \
3628} while (0);\
3629
3630
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003631 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003632 return -EINVAL;
3633 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003634 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003635 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003636 return -EINVAL;
3637
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003638 /* This makes sure that there aren't more than 32 mesh config
3639 * parameters (otherwise our bitfield scheme would not work.) */
3640 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3641
3642 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003643 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003644 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3645 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003646 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003647 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3648 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003649 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003650 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3651 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003652 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003653 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3654 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003656 mask, NL80211_MESHCONF_MAX_RETRIES,
3657 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003658 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003659 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003660 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003661 mask, NL80211_MESHCONF_ELEMENT_TTL,
3662 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003664 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3665 nla_get_u8);
3666 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3667 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3668 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003670 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3671 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003673 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3674 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003676 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3677 nla_get_u16);
3678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3679 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3680 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003682 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3683 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003685 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3686 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003688 dot11MeshHWMPnetDiameterTraversalTime, mask,
3689 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3690 nla_get_u16);
3691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3692 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3694 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3695 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003697 dot11MeshGateAnnouncementProtocol, mask,
3698 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3699 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003701 mask, NL80211_MESHCONF_FORWARDING,
3702 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003704 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3705 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003706 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003707 mask, NL80211_MESHCONF_HT_OPMODE,
3708 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3710 mask,
3711 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3712 nla_get_u32);
3713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3714 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3715 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3717 dot11MeshHWMPconfirmationInterval, mask,
3718 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3719 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003720 if (mask_out)
3721 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003722
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003723 return 0;
3724
3725#undef FILL_IN_MESH_PARAM_IF_SET
3726}
3727
Javier Cardonac80d5452010-12-16 17:37:49 -08003728static int nl80211_parse_mesh_setup(struct genl_info *info,
3729 struct mesh_setup *setup)
3730{
3731 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3732
3733 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3734 return -EINVAL;
3735 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3736 info->attrs[NL80211_ATTR_MESH_SETUP],
3737 nl80211_mesh_setup_params_policy))
3738 return -EINVAL;
3739
Javier Cardonad299a1f2012-03-31 11:31:33 -07003740 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3741 setup->sync_method =
3742 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3743 IEEE80211_SYNC_METHOD_VENDOR :
3744 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3745
Javier Cardonac80d5452010-12-16 17:37:49 -08003746 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3747 setup->path_sel_proto =
3748 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3749 IEEE80211_PATH_PROTOCOL_VENDOR :
3750 IEEE80211_PATH_PROTOCOL_HWMP;
3751
3752 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3753 setup->path_metric =
3754 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3755 IEEE80211_PATH_METRIC_VENDOR :
3756 IEEE80211_PATH_METRIC_AIRTIME;
3757
Javier Cardona581a8b02011-04-07 15:08:27 -07003758
3759 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003760 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003761 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003762 if (!is_valid_ie_attr(ieattr))
3763 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003764 setup->ie = nla_data(ieattr);
3765 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003766 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003767 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3768 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003769
3770 return 0;
3771}
3772
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003773static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003774 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003775{
3776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3777 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003778 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003779 struct mesh_config cfg;
3780 u32 mask;
3781 int err;
3782
Johannes Berg29cbe682010-12-03 09:20:44 +01003783 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3784 return -EOPNOTSUPP;
3785
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003786 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003787 return -EOPNOTSUPP;
3788
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003789 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003790 if (err)
3791 return err;
3792
Johannes Berg29cbe682010-12-03 09:20:44 +01003793 wdev_lock(wdev);
3794 if (!wdev->mesh_id_len)
3795 err = -ENOLINK;
3796
3797 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003798 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003799 mask, &cfg);
3800
3801 wdev_unlock(wdev);
3802
3803 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003804}
3805
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003806static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3807{
3808 struct sk_buff *msg;
3809 void *hdr = NULL;
3810 struct nlattr *nl_reg_rules;
3811 unsigned int i;
3812 int err = -EINVAL;
3813
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003814 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003815
3816 if (!cfg80211_regdomain)
3817 goto out;
3818
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003820 if (!msg) {
3821 err = -ENOBUFS;
3822 goto out;
3823 }
3824
3825 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3826 NL80211_CMD_GET_REG);
3827 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003828 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003829
David S. Miller9360ffd2012-03-29 04:41:26 -04003830 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3831 cfg80211_regdomain->alpha2) ||
3832 (cfg80211_regdomain->dfs_region &&
3833 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3834 cfg80211_regdomain->dfs_region)))
3835 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003836
3837 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3838 if (!nl_reg_rules)
3839 goto nla_put_failure;
3840
3841 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3842 struct nlattr *nl_reg_rule;
3843 const struct ieee80211_reg_rule *reg_rule;
3844 const struct ieee80211_freq_range *freq_range;
3845 const struct ieee80211_power_rule *power_rule;
3846
3847 reg_rule = &cfg80211_regdomain->reg_rules[i];
3848 freq_range = &reg_rule->freq_range;
3849 power_rule = &reg_rule->power_rule;
3850
3851 nl_reg_rule = nla_nest_start(msg, i);
3852 if (!nl_reg_rule)
3853 goto nla_put_failure;
3854
David S. Miller9360ffd2012-03-29 04:41:26 -04003855 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3856 reg_rule->flags) ||
3857 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3858 freq_range->start_freq_khz) ||
3859 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3860 freq_range->end_freq_khz) ||
3861 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3862 freq_range->max_bandwidth_khz) ||
3863 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3864 power_rule->max_antenna_gain) ||
3865 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3866 power_rule->max_eirp))
3867 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003868
3869 nla_nest_end(msg, nl_reg_rule);
3870 }
3871
3872 nla_nest_end(msg, nl_reg_rules);
3873
3874 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003875 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003876 goto out;
3877
3878nla_put_failure:
3879 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003880put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003881 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003882 err = -EMSGSIZE;
3883out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003884 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003885 return err;
3886}
3887
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003888static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3889{
3890 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3891 struct nlattr *nl_reg_rule;
3892 char *alpha2 = NULL;
3893 int rem_reg_rules = 0, r = 0;
3894 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003895 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003896 struct ieee80211_regdomain *rd = NULL;
3897
3898 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3899 return -EINVAL;
3900
3901 if (!info->attrs[NL80211_ATTR_REG_RULES])
3902 return -EINVAL;
3903
3904 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3905
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003906 if (info->attrs[NL80211_ATTR_DFS_REGION])
3907 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3908
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003909 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3910 rem_reg_rules) {
3911 num_rules++;
3912 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003913 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003914 }
3915
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003916 mutex_lock(&cfg80211_mutex);
3917
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003918 if (!reg_is_valid_request(alpha2)) {
3919 r = -EINVAL;
3920 goto bad_reg;
3921 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003922
3923 size_of_regd = sizeof(struct ieee80211_regdomain) +
3924 (num_rules * sizeof(struct ieee80211_reg_rule));
3925
3926 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003927 if (!rd) {
3928 r = -ENOMEM;
3929 goto bad_reg;
3930 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003931
3932 rd->n_reg_rules = num_rules;
3933 rd->alpha2[0] = alpha2[0];
3934 rd->alpha2[1] = alpha2[1];
3935
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003936 /*
3937 * Disable DFS master mode if the DFS region was
3938 * not supported or known on this kernel.
3939 */
3940 if (reg_supported_dfs_region(dfs_region))
3941 rd->dfs_region = dfs_region;
3942
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003943 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3944 rem_reg_rules) {
3945 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3946 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3947 reg_rule_policy);
3948 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3949 if (r)
3950 goto bad_reg;
3951
3952 rule_idx++;
3953
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003954 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3955 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003956 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003957 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003958 }
3959
3960 BUG_ON(rule_idx != num_rules);
3961
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003962 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003963
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003964 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003965
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003966 return r;
3967
Johannes Bergd2372b32008-10-24 20:32:20 +02003968 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003969 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003970 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003971 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003972}
3973
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003974static int validate_scan_freqs(struct nlattr *freqs)
3975{
3976 struct nlattr *attr1, *attr2;
3977 int n_channels = 0, tmp1, tmp2;
3978
3979 nla_for_each_nested(attr1, freqs, tmp1) {
3980 n_channels++;
3981 /*
3982 * Some hardware has a limited channel list for
3983 * scanning, and it is pretty much nonsensical
3984 * to scan for a channel twice, so disallow that
3985 * and don't require drivers to check that the
3986 * channel list they get isn't longer than what
3987 * they can scan, as long as they can scan all
3988 * the channels they registered at once.
3989 */
3990 nla_for_each_nested(attr2, freqs, tmp2)
3991 if (attr1 != attr2 &&
3992 nla_get_u32(attr1) == nla_get_u32(attr2))
3993 return 0;
3994 }
3995
3996 return n_channels;
3997}
3998
Johannes Berg2a519312009-02-10 21:25:55 +01003999static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4000{
Johannes Berg4c476992010-10-04 21:36:35 +02004001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4002 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004003 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004004 struct nlattr *attr;
4005 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004006 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004007 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004008
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004009 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4010 return -EINVAL;
4011
Johannes Berg79c97e92009-07-07 03:56:12 +02004012 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004013
Johannes Berg4c476992010-10-04 21:36:35 +02004014 if (!rdev->ops->scan)
4015 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004016
Johannes Berg4c476992010-10-04 21:36:35 +02004017 if (rdev->scan_req)
4018 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004019
4020 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004021 n_channels = validate_scan_freqs(
4022 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004023 if (!n_channels)
4024 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004025 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004026 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004027 n_channels = 0;
4028
Johannes Berg2a519312009-02-10 21:25:55 +01004029 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4030 if (wiphy->bands[band])
4031 n_channels += wiphy->bands[band]->n_channels;
4032 }
4033
4034 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4035 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4036 n_ssids++;
4037
Johannes Berg4c476992010-10-04 21:36:35 +02004038 if (n_ssids > wiphy->max_scan_ssids)
4039 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004040
Jouni Malinen70692ad2009-02-16 19:39:13 +02004041 if (info->attrs[NL80211_ATTR_IE])
4042 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4043 else
4044 ie_len = 0;
4045
Johannes Berg4c476992010-10-04 21:36:35 +02004046 if (ie_len > wiphy->max_scan_ie_len)
4047 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004048
Johannes Berg2a519312009-02-10 21:25:55 +01004049 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004050 + sizeof(*request->ssids) * n_ssids
4051 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004052 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004053 if (!request)
4054 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004055
Johannes Berg2a519312009-02-10 21:25:55 +01004056 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004057 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004058 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004059 if (ie_len) {
4060 if (request->ssids)
4061 request->ie = (void *)(request->ssids + n_ssids);
4062 else
4063 request->ie = (void *)(request->channels + n_channels);
4064 }
Johannes Berg2a519312009-02-10 21:25:55 +01004065
Johannes Berg584991d2009-11-02 13:32:03 +01004066 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004067 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4068 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004069 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004070 struct ieee80211_channel *chan;
4071
4072 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4073
4074 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004075 err = -EINVAL;
4076 goto out_free;
4077 }
Johannes Berg584991d2009-11-02 13:32:03 +01004078
4079 /* ignore disabled channels */
4080 if (chan->flags & IEEE80211_CHAN_DISABLED)
4081 continue;
4082
4083 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004084 i++;
4085 }
4086 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004087 enum ieee80211_band band;
4088
Johannes Berg2a519312009-02-10 21:25:55 +01004089 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004090 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4091 int j;
4092 if (!wiphy->bands[band])
4093 continue;
4094 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004095 struct ieee80211_channel *chan;
4096
4097 chan = &wiphy->bands[band]->channels[j];
4098
4099 if (chan->flags & IEEE80211_CHAN_DISABLED)
4100 continue;
4101
4102 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004103 i++;
4104 }
4105 }
4106 }
4107
Johannes Berg584991d2009-11-02 13:32:03 +01004108 if (!i) {
4109 err = -EINVAL;
4110 goto out_free;
4111 }
4112
4113 request->n_channels = i;
4114
Johannes Berg2a519312009-02-10 21:25:55 +01004115 i = 0;
4116 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4117 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004118 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004119 err = -EINVAL;
4120 goto out_free;
4121 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004122 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004123 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004124 i++;
4125 }
4126 }
4127
Jouni Malinen70692ad2009-02-16 19:39:13 +02004128 if (info->attrs[NL80211_ATTR_IE]) {
4129 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004130 memcpy((void *)request->ie,
4131 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004132 request->ie_len);
4133 }
4134
Johannes Berg34850ab2011-07-18 18:08:35 +02004135 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004136 if (wiphy->bands[i])
4137 request->rates[i] =
4138 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004139
4140 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4141 nla_for_each_nested(attr,
4142 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4143 tmp) {
4144 enum ieee80211_band band = nla_type(attr);
4145
Dan Carpenter84404622011-07-29 11:52:18 +03004146 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004147 err = -EINVAL;
4148 goto out_free;
4149 }
4150 err = ieee80211_get_ratemask(wiphy->bands[band],
4151 nla_data(attr),
4152 nla_len(attr),
4153 &request->rates[band]);
4154 if (err)
4155 goto out_free;
4156 }
4157 }
4158
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304159 request->no_cck =
4160 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4161
Johannes Berg463d0182009-07-14 00:33:35 +02004162 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004163 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004164
Johannes Berg79c97e92009-07-07 03:56:12 +02004165 rdev->scan_req = request;
4166 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004167
Johannes Berg463d0182009-07-14 00:33:35 +02004168 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004169 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004170 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004171 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004172 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004173 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004174 kfree(request);
4175 }
Johannes Berg3b858752009-03-12 09:55:09 +01004176
Johannes Berg2a519312009-02-10 21:25:55 +01004177 return err;
4178}
4179
Luciano Coelho807f8a82011-05-11 17:09:35 +03004180static int nl80211_start_sched_scan(struct sk_buff *skb,
4181 struct genl_info *info)
4182{
4183 struct cfg80211_sched_scan_request *request;
4184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4185 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004186 struct nlattr *attr;
4187 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004188 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004189 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004190 enum ieee80211_band band;
4191 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004192 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004193
4194 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4195 !rdev->ops->sched_scan_start)
4196 return -EOPNOTSUPP;
4197
4198 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4199 return -EINVAL;
4200
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004201 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4202 return -EINVAL;
4203
4204 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4205 if (interval == 0)
4206 return -EINVAL;
4207
Luciano Coelho807f8a82011-05-11 17:09:35 +03004208 wiphy = &rdev->wiphy;
4209
4210 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4211 n_channels = validate_scan_freqs(
4212 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4213 if (!n_channels)
4214 return -EINVAL;
4215 } else {
4216 n_channels = 0;
4217
4218 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4219 if (wiphy->bands[band])
4220 n_channels += wiphy->bands[band]->n_channels;
4221 }
4222
4223 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4224 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4225 tmp)
4226 n_ssids++;
4227
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004228 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004229 return -EINVAL;
4230
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004231 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4232 nla_for_each_nested(attr,
4233 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4234 tmp)
4235 n_match_sets++;
4236
4237 if (n_match_sets > wiphy->max_match_sets)
4238 return -EINVAL;
4239
Luciano Coelho807f8a82011-05-11 17:09:35 +03004240 if (info->attrs[NL80211_ATTR_IE])
4241 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4242 else
4243 ie_len = 0;
4244
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004245 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004246 return -EINVAL;
4247
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004248 mutex_lock(&rdev->sched_scan_mtx);
4249
4250 if (rdev->sched_scan_req) {
4251 err = -EINPROGRESS;
4252 goto out;
4253 }
4254
Luciano Coelho807f8a82011-05-11 17:09:35 +03004255 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004256 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004257 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004258 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004259 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004260 if (!request) {
4261 err = -ENOMEM;
4262 goto out;
4263 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004264
4265 if (n_ssids)
4266 request->ssids = (void *)&request->channels[n_channels];
4267 request->n_ssids = n_ssids;
4268 if (ie_len) {
4269 if (request->ssids)
4270 request->ie = (void *)(request->ssids + n_ssids);
4271 else
4272 request->ie = (void *)(request->channels + n_channels);
4273 }
4274
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004275 if (n_match_sets) {
4276 if (request->ie)
4277 request->match_sets = (void *)(request->ie + ie_len);
4278 else if (request->ssids)
4279 request->match_sets =
4280 (void *)(request->ssids + n_ssids);
4281 else
4282 request->match_sets =
4283 (void *)(request->channels + n_channels);
4284 }
4285 request->n_match_sets = n_match_sets;
4286
Luciano Coelho807f8a82011-05-11 17:09:35 +03004287 i = 0;
4288 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4289 /* user specified, bail out if channel not found */
4290 nla_for_each_nested(attr,
4291 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4292 tmp) {
4293 struct ieee80211_channel *chan;
4294
4295 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4296
4297 if (!chan) {
4298 err = -EINVAL;
4299 goto out_free;
4300 }
4301
4302 /* ignore disabled channels */
4303 if (chan->flags & IEEE80211_CHAN_DISABLED)
4304 continue;
4305
4306 request->channels[i] = chan;
4307 i++;
4308 }
4309 } else {
4310 /* all channels */
4311 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4312 int j;
4313 if (!wiphy->bands[band])
4314 continue;
4315 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4316 struct ieee80211_channel *chan;
4317
4318 chan = &wiphy->bands[band]->channels[j];
4319
4320 if (chan->flags & IEEE80211_CHAN_DISABLED)
4321 continue;
4322
4323 request->channels[i] = chan;
4324 i++;
4325 }
4326 }
4327 }
4328
4329 if (!i) {
4330 err = -EINVAL;
4331 goto out_free;
4332 }
4333
4334 request->n_channels = i;
4335
4336 i = 0;
4337 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4338 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4339 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004340 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004341 err = -EINVAL;
4342 goto out_free;
4343 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004344 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004345 memcpy(request->ssids[i].ssid, nla_data(attr),
4346 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004347 i++;
4348 }
4349 }
4350
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004351 i = 0;
4352 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4353 nla_for_each_nested(attr,
4354 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4355 tmp) {
4356 struct nlattr *ssid;
4357
4358 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4359 nla_data(attr), nla_len(attr),
4360 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004361 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004362 if (ssid) {
4363 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4364 err = -EINVAL;
4365 goto out_free;
4366 }
4367 memcpy(request->match_sets[i].ssid.ssid,
4368 nla_data(ssid), nla_len(ssid));
4369 request->match_sets[i].ssid.ssid_len =
4370 nla_len(ssid);
4371 }
4372 i++;
4373 }
4374 }
4375
Luciano Coelho807f8a82011-05-11 17:09:35 +03004376 if (info->attrs[NL80211_ATTR_IE]) {
4377 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4378 memcpy((void *)request->ie,
4379 nla_data(info->attrs[NL80211_ATTR_IE]),
4380 request->ie_len);
4381 }
4382
4383 request->dev = dev;
4384 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004385 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004386
4387 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4388 if (!err) {
4389 rdev->sched_scan_req = request;
4390 nl80211_send_sched_scan(rdev, dev,
4391 NL80211_CMD_START_SCHED_SCAN);
4392 goto out;
4393 }
4394
4395out_free:
4396 kfree(request);
4397out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004398 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004399 return err;
4400}
4401
4402static int nl80211_stop_sched_scan(struct sk_buff *skb,
4403 struct genl_info *info)
4404{
4405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004406 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004407
4408 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4409 !rdev->ops->sched_scan_stop)
4410 return -EOPNOTSUPP;
4411
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004412 mutex_lock(&rdev->sched_scan_mtx);
4413 err = __cfg80211_stop_sched_scan(rdev, false);
4414 mutex_unlock(&rdev->sched_scan_mtx);
4415
4416 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004417}
4418
Johannes Berg9720bb32011-06-21 09:45:33 +02004419static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4420 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004421 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004422 struct wireless_dev *wdev,
4423 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004424{
Johannes Berg48ab9052009-07-10 18:42:31 +02004425 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004426 void *hdr;
4427 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004428
4429 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004430
Johannes Berg9720bb32011-06-21 09:45:33 +02004431 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004432 NL80211_CMD_NEW_SCAN_RESULTS);
4433 if (!hdr)
4434 return -1;
4435
Johannes Berg9720bb32011-06-21 09:45:33 +02004436 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4437
David S. Miller9360ffd2012-03-29 04:41:26 -04004438 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4439 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4440 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004441
4442 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4443 if (!bss)
4444 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004445 if ((!is_zero_ether_addr(res->bssid) &&
4446 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4447 (res->information_elements && res->len_information_elements &&
4448 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4449 res->len_information_elements,
4450 res->information_elements)) ||
4451 (res->beacon_ies && res->len_beacon_ies &&
4452 res->beacon_ies != res->information_elements &&
4453 nla_put(msg, NL80211_BSS_BEACON_IES,
4454 res->len_beacon_ies, res->beacon_ies)))
4455 goto nla_put_failure;
4456 if (res->tsf &&
4457 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4458 goto nla_put_failure;
4459 if (res->beacon_interval &&
4460 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4461 goto nla_put_failure;
4462 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4463 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4464 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4465 jiffies_to_msecs(jiffies - intbss->ts)))
4466 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004467
Johannes Berg77965c92009-02-18 18:45:06 +01004468 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004469 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004470 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4471 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004472 break;
4473 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004474 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4475 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004476 break;
4477 default:
4478 break;
4479 }
4480
Johannes Berg48ab9052009-07-10 18:42:31 +02004481 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004482 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004483 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004484 if (intbss == wdev->current_bss &&
4485 nla_put_u32(msg, NL80211_BSS_STATUS,
4486 NL80211_BSS_STATUS_ASSOCIATED))
4487 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004488 break;
4489 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004490 if (intbss == wdev->current_bss &&
4491 nla_put_u32(msg, NL80211_BSS_STATUS,
4492 NL80211_BSS_STATUS_IBSS_JOINED))
4493 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004494 break;
4495 default:
4496 break;
4497 }
4498
Johannes Berg2a519312009-02-10 21:25:55 +01004499 nla_nest_end(msg, bss);
4500
4501 return genlmsg_end(msg, hdr);
4502
4503 nla_put_failure:
4504 genlmsg_cancel(msg, hdr);
4505 return -EMSGSIZE;
4506}
4507
4508static int nl80211_dump_scan(struct sk_buff *skb,
4509 struct netlink_callback *cb)
4510{
Johannes Berg48ab9052009-07-10 18:42:31 +02004511 struct cfg80211_registered_device *rdev;
4512 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004513 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004514 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004515 int start = cb->args[1], idx = 0;
4516 int err;
4517
Johannes Berg67748892010-10-04 21:14:06 +02004518 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4519 if (err)
4520 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004521
Johannes Berg48ab9052009-07-10 18:42:31 +02004522 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004523
Johannes Berg48ab9052009-07-10 18:42:31 +02004524 wdev_lock(wdev);
4525 spin_lock_bh(&rdev->bss_lock);
4526 cfg80211_bss_expire(rdev);
4527
Johannes Berg9720bb32011-06-21 09:45:33 +02004528 cb->seq = rdev->bss_generation;
4529
Johannes Berg48ab9052009-07-10 18:42:31 +02004530 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004531 if (++idx <= start)
4532 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004533 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004534 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004535 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004536 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004537 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004538 }
4539 }
4540
Johannes Berg48ab9052009-07-10 18:42:31 +02004541 spin_unlock_bh(&rdev->bss_lock);
4542 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004543
4544 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004545 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004546
Johannes Berg67748892010-10-04 21:14:06 +02004547 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004548}
4549
Holger Schurig61fa7132009-11-11 12:25:40 +01004550static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4551 int flags, struct net_device *dev,
4552 struct survey_info *survey)
4553{
4554 void *hdr;
4555 struct nlattr *infoattr;
4556
Holger Schurig61fa7132009-11-11 12:25:40 +01004557 hdr = nl80211hdr_put(msg, pid, seq, flags,
4558 NL80211_CMD_NEW_SURVEY_RESULTS);
4559 if (!hdr)
4560 return -ENOMEM;
4561
David S. Miller9360ffd2012-03-29 04:41:26 -04004562 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4563 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004564
4565 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4566 if (!infoattr)
4567 goto nla_put_failure;
4568
David S. Miller9360ffd2012-03-29 04:41:26 -04004569 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4570 survey->channel->center_freq))
4571 goto nla_put_failure;
4572
4573 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4574 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4575 goto nla_put_failure;
4576 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4577 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4578 goto nla_put_failure;
4579 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4580 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4581 survey->channel_time))
4582 goto nla_put_failure;
4583 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4584 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4585 survey->channel_time_busy))
4586 goto nla_put_failure;
4587 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4588 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4589 survey->channel_time_ext_busy))
4590 goto nla_put_failure;
4591 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4592 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4593 survey->channel_time_rx))
4594 goto nla_put_failure;
4595 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4596 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4597 survey->channel_time_tx))
4598 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004599
4600 nla_nest_end(msg, infoattr);
4601
4602 return genlmsg_end(msg, hdr);
4603
4604 nla_put_failure:
4605 genlmsg_cancel(msg, hdr);
4606 return -EMSGSIZE;
4607}
4608
4609static int nl80211_dump_survey(struct sk_buff *skb,
4610 struct netlink_callback *cb)
4611{
4612 struct survey_info survey;
4613 struct cfg80211_registered_device *dev;
4614 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004615 int survey_idx = cb->args[1];
4616 int res;
4617
Johannes Berg67748892010-10-04 21:14:06 +02004618 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4619 if (res)
4620 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004621
4622 if (!dev->ops->dump_survey) {
4623 res = -EOPNOTSUPP;
4624 goto out_err;
4625 }
4626
4627 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004628 struct ieee80211_channel *chan;
4629
Holger Schurig61fa7132009-11-11 12:25:40 +01004630 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4631 &survey);
4632 if (res == -ENOENT)
4633 break;
4634 if (res)
4635 goto out_err;
4636
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004637 /* Survey without a channel doesn't make sense */
4638 if (!survey.channel) {
4639 res = -EINVAL;
4640 goto out;
4641 }
4642
4643 chan = ieee80211_get_channel(&dev->wiphy,
4644 survey.channel->center_freq);
4645 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4646 survey_idx++;
4647 continue;
4648 }
4649
Holger Schurig61fa7132009-11-11 12:25:40 +01004650 if (nl80211_send_survey(skb,
4651 NETLINK_CB(cb->skb).pid,
4652 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4653 netdev,
4654 &survey) < 0)
4655 goto out;
4656 survey_idx++;
4657 }
4658
4659 out:
4660 cb->args[1] = survey_idx;
4661 res = skb->len;
4662 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004663 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004664 return res;
4665}
4666
Jouni Malinen255e7372009-03-20 21:21:17 +02004667static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4668{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004669 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004670}
4671
Samuel Ortizb23aa672009-07-01 21:26:54 +02004672static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4673{
4674 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4675 NL80211_WPA_VERSION_2));
4676}
4677
Jouni Malinen636a5d32009-03-19 13:39:22 +02004678static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4679{
Johannes Berg4c476992010-10-04 21:36:35 +02004680 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4681 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004682 struct ieee80211_channel *chan;
4683 const u8 *bssid, *ssid, *ie = NULL;
4684 int err, ssid_len, ie_len = 0;
4685 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004686 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004687 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004688
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004689 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4690 return -EINVAL;
4691
4692 if (!info->attrs[NL80211_ATTR_MAC])
4693 return -EINVAL;
4694
Jouni Malinen17780922009-03-27 20:52:47 +02004695 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4696 return -EINVAL;
4697
Johannes Berg19957bb2009-07-02 17:20:43 +02004698 if (!info->attrs[NL80211_ATTR_SSID])
4699 return -EINVAL;
4700
4701 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4702 return -EINVAL;
4703
Johannes Bergfffd0932009-07-08 14:22:54 +02004704 err = nl80211_parse_key(info, &key);
4705 if (err)
4706 return err;
4707
4708 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004709 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4710 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004711 if (!key.p.key || !key.p.key_len)
4712 return -EINVAL;
4713 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4714 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4715 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4716 key.p.key_len != WLAN_KEY_LEN_WEP104))
4717 return -EINVAL;
4718 if (key.idx > 4)
4719 return -EINVAL;
4720 } else {
4721 key.p.key_len = 0;
4722 key.p.key = NULL;
4723 }
4724
Johannes Bergafea0b72010-08-10 09:46:42 +02004725 if (key.idx >= 0) {
4726 int i;
4727 bool ok = false;
4728 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4729 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4730 ok = true;
4731 break;
4732 }
4733 }
Johannes Berg4c476992010-10-04 21:36:35 +02004734 if (!ok)
4735 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004736 }
4737
Johannes Berg4c476992010-10-04 21:36:35 +02004738 if (!rdev->ops->auth)
4739 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004740
Johannes Berg074ac8d2010-09-16 14:58:22 +02004741 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004742 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4743 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004744
Johannes Berg19957bb2009-07-02 17:20:43 +02004745 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004746 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004747 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004748 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4749 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004750
Johannes Berg19957bb2009-07-02 17:20:43 +02004751 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4752 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4753
4754 if (info->attrs[NL80211_ATTR_IE]) {
4755 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4756 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4757 }
4758
4759 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004760 if (!nl80211_valid_auth_type(auth_type))
4761 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004762
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004763 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4764
Johannes Berg95de8172012-01-20 13:55:25 +01004765 /*
4766 * Since we no longer track auth state, ignore
4767 * requests to only change local state.
4768 */
4769 if (local_state_change)
4770 return 0;
4771
Johannes Berg4c476992010-10-04 21:36:35 +02004772 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4773 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004774 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004775}
4776
Johannes Bergc0692b82010-08-27 14:26:53 +03004777static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4778 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004779 struct cfg80211_crypto_settings *settings,
4780 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004781{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004782 memset(settings, 0, sizeof(*settings));
4783
Samuel Ortizb23aa672009-07-01 21:26:54 +02004784 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4785
Johannes Bergc0692b82010-08-27 14:26:53 +03004786 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4787 u16 proto;
4788 proto = nla_get_u16(
4789 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4790 settings->control_port_ethertype = cpu_to_be16(proto);
4791 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4792 proto != ETH_P_PAE)
4793 return -EINVAL;
4794 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4795 settings->control_port_no_encrypt = true;
4796 } else
4797 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4798
Samuel Ortizb23aa672009-07-01 21:26:54 +02004799 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4800 void *data;
4801 int len, i;
4802
4803 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4804 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4805 settings->n_ciphers_pairwise = len / sizeof(u32);
4806
4807 if (len % sizeof(u32))
4808 return -EINVAL;
4809
Johannes Berg3dc27d22009-07-02 21:36:37 +02004810 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004811 return -EINVAL;
4812
4813 memcpy(settings->ciphers_pairwise, data, len);
4814
4815 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004816 if (!cfg80211_supported_cipher_suite(
4817 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004818 settings->ciphers_pairwise[i]))
4819 return -EINVAL;
4820 }
4821
4822 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4823 settings->cipher_group =
4824 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004825 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4826 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004827 return -EINVAL;
4828 }
4829
4830 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4831 settings->wpa_versions =
4832 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4833 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4834 return -EINVAL;
4835 }
4836
4837 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4838 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004839 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004840
4841 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4842 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4843 settings->n_akm_suites = len / sizeof(u32);
4844
4845 if (len % sizeof(u32))
4846 return -EINVAL;
4847
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004848 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4849 return -EINVAL;
4850
Samuel Ortizb23aa672009-07-01 21:26:54 +02004851 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004852 }
4853
4854 return 0;
4855}
4856
Jouni Malinen636a5d32009-03-19 13:39:22 +02004857static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4858{
Johannes Berg4c476992010-10-04 21:36:35 +02004859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4860 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004861 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004862 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004863 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004864 int err, ssid_len, ie_len = 0;
4865 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004866 u32 flags = 0;
4867 struct ieee80211_ht_cap *ht_capa = NULL;
4868 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004869
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004870 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4871 return -EINVAL;
4872
4873 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004874 !info->attrs[NL80211_ATTR_SSID] ||
4875 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004876 return -EINVAL;
4877
Johannes Berg4c476992010-10-04 21:36:35 +02004878 if (!rdev->ops->assoc)
4879 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004880
Johannes Berg074ac8d2010-09-16 14:58:22 +02004881 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004882 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4883 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004884
Johannes Berg19957bb2009-07-02 17:20:43 +02004885 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004886
Johannes Berg19957bb2009-07-02 17:20:43 +02004887 chan = ieee80211_get_channel(&rdev->wiphy,
4888 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004889 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4890 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004891
Johannes Berg19957bb2009-07-02 17:20:43 +02004892 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4893 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004894
4895 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004896 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4897 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004898 }
4899
Jouni Malinendc6382c2009-05-06 22:09:37 +03004900 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004901 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004902 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004903 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004904 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004905 else if (mfp != NL80211_MFP_NO)
4906 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004907 }
4908
Johannes Berg3e5d7642009-07-07 14:37:26 +02004909 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4910 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4911
Ben Greear7e7c8922011-11-18 11:31:59 -08004912 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4913 flags |= ASSOC_REQ_DISABLE_HT;
4914
4915 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4916 ht_capa_mask =
4917 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4918
4919 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4920 if (!ht_capa_mask)
4921 return -EINVAL;
4922 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4923 }
4924
Johannes Bergc0692b82010-08-27 14:26:53 +03004925 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004926 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004927 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4928 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004929 &crypto, flags, ht_capa,
4930 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004931
Jouni Malinen636a5d32009-03-19 13:39:22 +02004932 return err;
4933}
4934
4935static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4936{
Johannes Berg4c476992010-10-04 21:36:35 +02004937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4938 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004939 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004940 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004941 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004942 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004943
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004944 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4945 return -EINVAL;
4946
4947 if (!info->attrs[NL80211_ATTR_MAC])
4948 return -EINVAL;
4949
4950 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4951 return -EINVAL;
4952
Johannes Berg4c476992010-10-04 21:36:35 +02004953 if (!rdev->ops->deauth)
4954 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004955
Johannes Berg074ac8d2010-09-16 14:58:22 +02004956 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004957 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4958 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004959
Johannes Berg19957bb2009-07-02 17:20:43 +02004960 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004961
Johannes Berg19957bb2009-07-02 17:20:43 +02004962 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4963 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004964 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004965 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004966 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004967
4968 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004969 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4970 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004971 }
4972
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004973 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4974
Johannes Berg4c476992010-10-04 21:36:35 +02004975 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4976 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004977}
4978
4979static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4980{
Johannes Berg4c476992010-10-04 21:36:35 +02004981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4982 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004983 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004984 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004985 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004986 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004987
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004988 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4989 return -EINVAL;
4990
4991 if (!info->attrs[NL80211_ATTR_MAC])
4992 return -EINVAL;
4993
4994 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4995 return -EINVAL;
4996
Johannes Berg4c476992010-10-04 21:36:35 +02004997 if (!rdev->ops->disassoc)
4998 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004999
Johannes Berg074ac8d2010-09-16 14:58:22 +02005000 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005001 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5002 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005003
Johannes Berg19957bb2009-07-02 17:20:43 +02005004 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005005
Johannes Berg19957bb2009-07-02 17:20:43 +02005006 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5007 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005008 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005009 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005010 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005011
5012 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005013 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5014 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005015 }
5016
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005017 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5018
Johannes Berg4c476992010-10-04 21:36:35 +02005019 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5020 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005021}
5022
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005023static bool
5024nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5025 int mcast_rate[IEEE80211_NUM_BANDS],
5026 int rateval)
5027{
5028 struct wiphy *wiphy = &rdev->wiphy;
5029 bool found = false;
5030 int band, i;
5031
5032 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5033 struct ieee80211_supported_band *sband;
5034
5035 sband = wiphy->bands[band];
5036 if (!sband)
5037 continue;
5038
5039 for (i = 0; i < sband->n_bitrates; i++) {
5040 if (sband->bitrates[i].bitrate == rateval) {
5041 mcast_rate[band] = i + 1;
5042 found = true;
5043 break;
5044 }
5045 }
5046 }
5047
5048 return found;
5049}
5050
Johannes Berg04a773a2009-04-19 21:24:32 +02005051static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5052{
Johannes Berg4c476992010-10-04 21:36:35 +02005053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5054 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005055 struct cfg80211_ibss_params ibss;
5056 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005057 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005058 int err;
5059
Johannes Berg8e30bc52009-04-22 17:45:38 +02005060 memset(&ibss, 0, sizeof(ibss));
5061
Johannes Berg04a773a2009-04-19 21:24:32 +02005062 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5063 return -EINVAL;
5064
5065 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5066 !info->attrs[NL80211_ATTR_SSID] ||
5067 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5068 return -EINVAL;
5069
Johannes Berg8e30bc52009-04-22 17:45:38 +02005070 ibss.beacon_interval = 100;
5071
5072 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5073 ibss.beacon_interval =
5074 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5075 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5076 return -EINVAL;
5077 }
5078
Johannes Berg4c476992010-10-04 21:36:35 +02005079 if (!rdev->ops->join_ibss)
5080 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005081
Johannes Berg4c476992010-10-04 21:36:35 +02005082 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5083 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005084
Johannes Berg79c97e92009-07-07 03:56:12 +02005085 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005086
Johannes Berg39193492011-09-16 13:45:25 +02005087 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005088 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005089
5090 if (!is_valid_ether_addr(ibss.bssid))
5091 return -EINVAL;
5092 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005093 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5094 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5095
5096 if (info->attrs[NL80211_ATTR_IE]) {
5097 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5098 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5099 }
5100
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005101 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5102 enum nl80211_channel_type channel_type;
5103
Johannes Bergcd6c6592012-05-10 21:27:18 +02005104 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005105 return -EINVAL;
5106
5107 if (channel_type != NL80211_CHAN_NO_HT &&
5108 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5109 return -EINVAL;
5110
5111 ibss.channel_type = channel_type;
5112 } else {
5113 ibss.channel_type = NL80211_CHAN_NO_HT;
5114 }
5115
5116 ibss.channel = rdev_freq_to_chan(rdev,
5117 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5118 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005119 if (!ibss.channel ||
5120 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005121 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5122 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005123
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005124 /* Both channels should be able to initiate communication */
5125 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5126 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5127 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5128 ibss.channel_type))
5129 return -EINVAL;
5130
Johannes Berg04a773a2009-04-19 21:24:32 +02005131 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005132 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005133
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005134 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5135 u8 *rates =
5136 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5137 int n_rates =
5138 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5139 struct ieee80211_supported_band *sband =
5140 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005141
Johannes Berg34850ab2011-07-18 18:08:35 +02005142 err = ieee80211_get_ratemask(sband, rates, n_rates,
5143 &ibss.basic_rates);
5144 if (err)
5145 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005146 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005147
5148 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5149 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5150 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5151 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005152
Johannes Berg4c476992010-10-04 21:36:35 +02005153 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5154 connkeys = nl80211_parse_connkeys(rdev,
5155 info->attrs[NL80211_ATTR_KEYS]);
5156 if (IS_ERR(connkeys))
5157 return PTR_ERR(connkeys);
5158 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005159
Antonio Quartulli267335d2012-01-31 20:25:47 +01005160 ibss.control_port =
5161 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5162
Johannes Berg4c476992010-10-04 21:36:35 +02005163 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005164 if (err)
5165 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005166 return err;
5167}
5168
5169static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5170{
Johannes Berg4c476992010-10-04 21:36:35 +02005171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5172 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005173
Johannes Berg4c476992010-10-04 21:36:35 +02005174 if (!rdev->ops->leave_ibss)
5175 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005176
Johannes Berg4c476992010-10-04 21:36:35 +02005177 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5178 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005179
Johannes Berg4c476992010-10-04 21:36:35 +02005180 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005181}
5182
Johannes Bergaff89a92009-07-01 21:26:51 +02005183#ifdef CONFIG_NL80211_TESTMODE
5184static struct genl_multicast_group nl80211_testmode_mcgrp = {
5185 .name = "testmode",
5186};
5187
5188static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5189{
Johannes Berg4c476992010-10-04 21:36:35 +02005190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005191 int err;
5192
5193 if (!info->attrs[NL80211_ATTR_TESTDATA])
5194 return -EINVAL;
5195
Johannes Bergaff89a92009-07-01 21:26:51 +02005196 err = -EOPNOTSUPP;
5197 if (rdev->ops->testmode_cmd) {
5198 rdev->testmode_info = info;
5199 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5200 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5201 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5202 rdev->testmode_info = NULL;
5203 }
5204
Johannes Bergaff89a92009-07-01 21:26:51 +02005205 return err;
5206}
5207
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005208static int nl80211_testmode_dump(struct sk_buff *skb,
5209 struct netlink_callback *cb)
5210{
Johannes Berg00918d32011-12-13 17:22:05 +01005211 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005212 int err;
5213 long phy_idx;
5214 void *data = NULL;
5215 int data_len = 0;
5216
5217 if (cb->args[0]) {
5218 /*
5219 * 0 is a valid index, but not valid for args[0],
5220 * so we need to offset by 1.
5221 */
5222 phy_idx = cb->args[0] - 1;
5223 } else {
5224 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5225 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5226 nl80211_policy);
5227 if (err)
5228 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005229 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
5230 phy_idx = nla_get_u32(
5231 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
5232 } else {
5233 struct net_device *netdev;
5234
5235 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
5236 nl80211_fam.attrbuf,
5237 &rdev, &netdev);
5238 if (err)
5239 return err;
5240 dev_put(netdev);
5241 phy_idx = rdev->wiphy_idx;
5242 cfg80211_unlock_rdev(rdev);
5243 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005244 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5245 cb->args[1] =
5246 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5247 }
5248
5249 if (cb->args[1]) {
5250 data = nla_data((void *)cb->args[1]);
5251 data_len = nla_len((void *)cb->args[1]);
5252 }
5253
5254 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005255 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5256 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005257 mutex_unlock(&cfg80211_mutex);
5258 return -ENOENT;
5259 }
Johannes Berg00918d32011-12-13 17:22:05 +01005260 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005261 mutex_unlock(&cfg80211_mutex);
5262
Johannes Berg00918d32011-12-13 17:22:05 +01005263 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005264 err = -EOPNOTSUPP;
5265 goto out_err;
5266 }
5267
5268 while (1) {
5269 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5270 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5271 NL80211_CMD_TESTMODE);
5272 struct nlattr *tmdata;
5273
David S. Miller9360ffd2012-03-29 04:41:26 -04005274 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005275 genlmsg_cancel(skb, hdr);
5276 break;
5277 }
5278
5279 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5280 if (!tmdata) {
5281 genlmsg_cancel(skb, hdr);
5282 break;
5283 }
Johannes Berg00918d32011-12-13 17:22:05 +01005284 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5285 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005286 nla_nest_end(skb, tmdata);
5287
5288 if (err == -ENOBUFS || err == -ENOENT) {
5289 genlmsg_cancel(skb, hdr);
5290 break;
5291 } else if (err) {
5292 genlmsg_cancel(skb, hdr);
5293 goto out_err;
5294 }
5295
5296 genlmsg_end(skb, hdr);
5297 }
5298
5299 err = skb->len;
5300 /* see above */
5301 cb->args[0] = phy_idx + 1;
5302 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005303 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005304 return err;
5305}
5306
Johannes Bergaff89a92009-07-01 21:26:51 +02005307static struct sk_buff *
5308__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5309 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5310{
5311 struct sk_buff *skb;
5312 void *hdr;
5313 struct nlattr *data;
5314
5315 skb = nlmsg_new(approxlen + 100, gfp);
5316 if (!skb)
5317 return NULL;
5318
5319 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5320 if (!hdr) {
5321 kfree_skb(skb);
5322 return NULL;
5323 }
5324
David S. Miller9360ffd2012-03-29 04:41:26 -04005325 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5326 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005327 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5328
5329 ((void **)skb->cb)[0] = rdev;
5330 ((void **)skb->cb)[1] = hdr;
5331 ((void **)skb->cb)[2] = data;
5332
5333 return skb;
5334
5335 nla_put_failure:
5336 kfree_skb(skb);
5337 return NULL;
5338}
5339
5340struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5341 int approxlen)
5342{
5343 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5344
5345 if (WARN_ON(!rdev->testmode_info))
5346 return NULL;
5347
5348 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5349 rdev->testmode_info->snd_pid,
5350 rdev->testmode_info->snd_seq,
5351 GFP_KERNEL);
5352}
5353EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5354
5355int cfg80211_testmode_reply(struct sk_buff *skb)
5356{
5357 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5358 void *hdr = ((void **)skb->cb)[1];
5359 struct nlattr *data = ((void **)skb->cb)[2];
5360
5361 if (WARN_ON(!rdev->testmode_info)) {
5362 kfree_skb(skb);
5363 return -EINVAL;
5364 }
5365
5366 nla_nest_end(skb, data);
5367 genlmsg_end(skb, hdr);
5368 return genlmsg_reply(skb, rdev->testmode_info);
5369}
5370EXPORT_SYMBOL(cfg80211_testmode_reply);
5371
5372struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5373 int approxlen, gfp_t gfp)
5374{
5375 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5376
5377 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5378}
5379EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5380
5381void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5382{
5383 void *hdr = ((void **)skb->cb)[1];
5384 struct nlattr *data = ((void **)skb->cb)[2];
5385
5386 nla_nest_end(skb, data);
5387 genlmsg_end(skb, hdr);
5388 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5389}
5390EXPORT_SYMBOL(cfg80211_testmode_event);
5391#endif
5392
Samuel Ortizb23aa672009-07-01 21:26:54 +02005393static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5394{
Johannes Berg4c476992010-10-04 21:36:35 +02005395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5396 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005397 struct cfg80211_connect_params connect;
5398 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005399 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005400 int err;
5401
5402 memset(&connect, 0, sizeof(connect));
5403
5404 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5405 return -EINVAL;
5406
5407 if (!info->attrs[NL80211_ATTR_SSID] ||
5408 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5409 return -EINVAL;
5410
5411 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5412 connect.auth_type =
5413 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5414 if (!nl80211_valid_auth_type(connect.auth_type))
5415 return -EINVAL;
5416 } else
5417 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5418
5419 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5420
Johannes Bergc0692b82010-08-27 14:26:53 +03005421 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005422 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005423 if (err)
5424 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005425
Johannes Berg074ac8d2010-09-16 14:58:22 +02005426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005427 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5428 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005429
Johannes Berg79c97e92009-07-07 03:56:12 +02005430 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005431
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305432 connect.bg_scan_period = -1;
5433 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5434 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5435 connect.bg_scan_period =
5436 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5437 }
5438
Samuel Ortizb23aa672009-07-01 21:26:54 +02005439 if (info->attrs[NL80211_ATTR_MAC])
5440 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5441 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5442 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5443
5444 if (info->attrs[NL80211_ATTR_IE]) {
5445 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5446 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5447 }
5448
5449 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5450 connect.channel =
5451 ieee80211_get_channel(wiphy,
5452 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5453 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005454 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5455 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005456 }
5457
Johannes Bergfffd0932009-07-08 14:22:54 +02005458 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5459 connkeys = nl80211_parse_connkeys(rdev,
5460 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005461 if (IS_ERR(connkeys))
5462 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005463 }
5464
Ben Greear7e7c8922011-11-18 11:31:59 -08005465 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5466 connect.flags |= ASSOC_REQ_DISABLE_HT;
5467
5468 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5469 memcpy(&connect.ht_capa_mask,
5470 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5471 sizeof(connect.ht_capa_mask));
5472
5473 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5474 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5475 return -EINVAL;
5476 memcpy(&connect.ht_capa,
5477 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5478 sizeof(connect.ht_capa));
5479 }
5480
Johannes Bergfffd0932009-07-08 14:22:54 +02005481 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005482 if (err)
5483 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005484 return err;
5485}
5486
5487static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5488{
Johannes Berg4c476992010-10-04 21:36:35 +02005489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5490 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005491 u16 reason;
5492
5493 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5494 reason = WLAN_REASON_DEAUTH_LEAVING;
5495 else
5496 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5497
5498 if (reason == 0)
5499 return -EINVAL;
5500
Johannes Berg074ac8d2010-09-16 14:58:22 +02005501 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005502 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5503 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005504
Johannes Berg4c476992010-10-04 21:36:35 +02005505 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005506}
5507
Johannes Berg463d0182009-07-14 00:33:35 +02005508static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5509{
Johannes Berg4c476992010-10-04 21:36:35 +02005510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005511 struct net *net;
5512 int err;
5513 u32 pid;
5514
5515 if (!info->attrs[NL80211_ATTR_PID])
5516 return -EINVAL;
5517
5518 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5519
Johannes Berg463d0182009-07-14 00:33:35 +02005520 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005521 if (IS_ERR(net))
5522 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005523
5524 err = 0;
5525
5526 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005527 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5528 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005529
Johannes Berg463d0182009-07-14 00:33:35 +02005530 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005531 return err;
5532}
5533
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005534static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5535{
Johannes Berg4c476992010-10-04 21:36:35 +02005536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005537 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5538 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005539 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005540 struct cfg80211_pmksa pmksa;
5541
5542 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5543
5544 if (!info->attrs[NL80211_ATTR_MAC])
5545 return -EINVAL;
5546
5547 if (!info->attrs[NL80211_ATTR_PMKID])
5548 return -EINVAL;
5549
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005550 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5551 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5552
Johannes Berg074ac8d2010-09-16 14:58:22 +02005553 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005554 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5555 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005556
5557 switch (info->genlhdr->cmd) {
5558 case NL80211_CMD_SET_PMKSA:
5559 rdev_ops = rdev->ops->set_pmksa;
5560 break;
5561 case NL80211_CMD_DEL_PMKSA:
5562 rdev_ops = rdev->ops->del_pmksa;
5563 break;
5564 default:
5565 WARN_ON(1);
5566 break;
5567 }
5568
Johannes Berg4c476992010-10-04 21:36:35 +02005569 if (!rdev_ops)
5570 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005571
Johannes Berg4c476992010-10-04 21:36:35 +02005572 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005573}
5574
5575static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5576{
Johannes Berg4c476992010-10-04 21:36:35 +02005577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5578 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005579
Johannes Berg074ac8d2010-09-16 14:58:22 +02005580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005581 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5582 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005583
Johannes Berg4c476992010-10-04 21:36:35 +02005584 if (!rdev->ops->flush_pmksa)
5585 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005586
Johannes Berg4c476992010-10-04 21:36:35 +02005587 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005588}
5589
Arik Nemtsov109086c2011-09-28 14:12:50 +03005590static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5591{
5592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5593 struct net_device *dev = info->user_ptr[1];
5594 u8 action_code, dialog_token;
5595 u16 status_code;
5596 u8 *peer;
5597
5598 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5599 !rdev->ops->tdls_mgmt)
5600 return -EOPNOTSUPP;
5601
5602 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5603 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5604 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5605 !info->attrs[NL80211_ATTR_IE] ||
5606 !info->attrs[NL80211_ATTR_MAC])
5607 return -EINVAL;
5608
5609 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5610 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5611 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5612 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5613
5614 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5615 dialog_token, status_code,
5616 nla_data(info->attrs[NL80211_ATTR_IE]),
5617 nla_len(info->attrs[NL80211_ATTR_IE]));
5618}
5619
5620static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5621{
5622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5623 struct net_device *dev = info->user_ptr[1];
5624 enum nl80211_tdls_operation operation;
5625 u8 *peer;
5626
5627 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5628 !rdev->ops->tdls_oper)
5629 return -EOPNOTSUPP;
5630
5631 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5632 !info->attrs[NL80211_ATTR_MAC])
5633 return -EINVAL;
5634
5635 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5636 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5637
5638 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5639}
5640
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005641static int nl80211_remain_on_channel(struct sk_buff *skb,
5642 struct genl_info *info)
5643{
Johannes Berg4c476992010-10-04 21:36:35 +02005644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5645 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005646 struct ieee80211_channel *chan;
5647 struct sk_buff *msg;
5648 void *hdr;
5649 u64 cookie;
5650 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5651 u32 freq, duration;
5652 int err;
5653
5654 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5655 !info->attrs[NL80211_ATTR_DURATION])
5656 return -EINVAL;
5657
5658 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5659
Johannes Berg7c4ef712011-11-18 15:33:48 +01005660 if (!rdev->ops->remain_on_channel ||
5661 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005662 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005663
Johannes Bergebf348f2012-06-01 12:50:54 +02005664 /*
5665 * We should be on that channel for at least a minimum amount of
5666 * time (10ms) but no longer than the driver supports.
5667 */
5668 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5669 duration > rdev->wiphy.max_remain_on_channel_duration)
5670 return -EINVAL;
5671
Johannes Bergcd6c6592012-05-10 21:27:18 +02005672 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5673 !nl80211_valid_channel_type(info, &channel_type))
5674 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005675
5676 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5677 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005678 if (chan == NULL)
5679 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005680
5681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005682 if (!msg)
5683 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005684
5685 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5686 NL80211_CMD_REMAIN_ON_CHANNEL);
5687
5688 if (IS_ERR(hdr)) {
5689 err = PTR_ERR(hdr);
5690 goto free_msg;
5691 }
5692
5693 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5694 channel_type, duration, &cookie);
5695
5696 if (err)
5697 goto free_msg;
5698
David S. Miller9360ffd2012-03-29 04:41:26 -04005699 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5700 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005701
5702 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005703
5704 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005705
5706 nla_put_failure:
5707 err = -ENOBUFS;
5708 free_msg:
5709 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005710 return err;
5711}
5712
5713static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5714 struct genl_info *info)
5715{
Johannes Berg4c476992010-10-04 21:36:35 +02005716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5717 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005718 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005719
5720 if (!info->attrs[NL80211_ATTR_COOKIE])
5721 return -EINVAL;
5722
Johannes Berg4c476992010-10-04 21:36:35 +02005723 if (!rdev->ops->cancel_remain_on_channel)
5724 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005725
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005726 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5727
Johannes Berg4c476992010-10-04 21:36:35 +02005728 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005729}
5730
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005731static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5732 u8 *rates, u8 rates_len)
5733{
5734 u8 i;
5735 u32 mask = 0;
5736
5737 for (i = 0; i < rates_len; i++) {
5738 int rate = (rates[i] & 0x7f) * 5;
5739 int ridx;
5740 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5741 struct ieee80211_rate *srate =
5742 &sband->bitrates[ridx];
5743 if (rate == srate->bitrate) {
5744 mask |= 1 << ridx;
5745 break;
5746 }
5747 }
5748 if (ridx == sband->n_bitrates)
5749 return 0; /* rate not found */
5750 }
5751
5752 return mask;
5753}
5754
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005755static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5756 u8 *rates, u8 rates_len,
5757 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5758{
5759 u8 i;
5760
5761 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5762
5763 for (i = 0; i < rates_len; i++) {
5764 int ridx, rbit;
5765
5766 ridx = rates[i] / 8;
5767 rbit = BIT(rates[i] % 8);
5768
5769 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005770 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005771 return false;
5772
5773 /* check availability */
5774 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5775 mcs[ridx] |= rbit;
5776 else
5777 return false;
5778 }
5779
5780 return true;
5781}
5782
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005783static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005784 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5785 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005786 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5787 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005788};
5789
5790static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5791 struct genl_info *info)
5792{
5793 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005795 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005796 int rem, i;
5797 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005798 struct nlattr *tx_rates;
5799 struct ieee80211_supported_band *sband;
5800
5801 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5802 return -EINVAL;
5803
Johannes Berg4c476992010-10-04 21:36:35 +02005804 if (!rdev->ops->set_bitrate_mask)
5805 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005806
5807 memset(&mask, 0, sizeof(mask));
5808 /* Default to all rates enabled */
5809 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5810 sband = rdev->wiphy.bands[i];
5811 mask.control[i].legacy =
5812 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005813 if (sband)
5814 memcpy(mask.control[i].mcs,
5815 sband->ht_cap.mcs.rx_mask,
5816 sizeof(mask.control[i].mcs));
5817 else
5818 memset(mask.control[i].mcs, 0,
5819 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005820 }
5821
5822 /*
5823 * The nested attribute uses enum nl80211_band as the index. This maps
5824 * directly to the enum ieee80211_band values used in cfg80211.
5825 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005826 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005827 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5828 {
5829 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005830 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5831 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005832 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005833 if (sband == NULL)
5834 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005835 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5836 nla_len(tx_rates), nl80211_txattr_policy);
5837 if (tb[NL80211_TXRATE_LEGACY]) {
5838 mask.control[band].legacy = rateset_to_mask(
5839 sband,
5840 nla_data(tb[NL80211_TXRATE_LEGACY]),
5841 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305842 if ((mask.control[band].legacy == 0) &&
5843 nla_len(tb[NL80211_TXRATE_LEGACY]))
5844 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005845 }
5846 if (tb[NL80211_TXRATE_MCS]) {
5847 if (!ht_rateset_to_mask(
5848 sband,
5849 nla_data(tb[NL80211_TXRATE_MCS]),
5850 nla_len(tb[NL80211_TXRATE_MCS]),
5851 mask.control[band].mcs))
5852 return -EINVAL;
5853 }
5854
5855 if (mask.control[band].legacy == 0) {
5856 /* don't allow empty legacy rates if HT
5857 * is not even supported. */
5858 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5859 return -EINVAL;
5860
5861 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5862 if (mask.control[band].mcs[i])
5863 break;
5864
5865 /* legacy and mcs rates may not be both empty */
5866 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005867 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005868 }
5869 }
5870
Johannes Berg4c476992010-10-04 21:36:35 +02005871 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005872}
5873
Johannes Berg2e161f72010-08-12 15:38:38 +02005874static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005875{
Johannes Berg4c476992010-10-04 21:36:35 +02005876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5877 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005878 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005879
5880 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5881 return -EINVAL;
5882
Johannes Berg2e161f72010-08-12 15:38:38 +02005883 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5884 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005885
Johannes Berg9d38d852010-06-09 17:20:33 +02005886 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005887 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5889 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5890 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5893 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005894
5895 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005896 if (!rdev->ops->mgmt_tx)
5897 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005898
Johannes Berg4c476992010-10-04 21:36:35 +02005899 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005900 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005901 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5902 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005903}
5904
Johannes Berg2e161f72010-08-12 15:38:38 +02005905static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005906{
Johannes Berg4c476992010-10-04 21:36:35 +02005907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5908 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005909 struct ieee80211_channel *chan;
5910 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005911 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005912 u32 freq;
5913 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005914 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005915 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005916 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005917 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005918 bool offchan, no_cck, dont_wait_for_ack;
5919
5920 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005921
5922 if (!info->attrs[NL80211_ATTR_FRAME] ||
5923 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5924 return -EINVAL;
5925
Johannes Berg4c476992010-10-04 21:36:35 +02005926 if (!rdev->ops->mgmt_tx)
5927 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005928
Johannes Berg9d38d852010-06-09 17:20:33 +02005929 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005930 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5932 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005935 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5936 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005937
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005938 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005939 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005940 return -EINVAL;
5941 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005942
5943 /*
5944 * We should wait on the channel for at least a minimum amount
5945 * of time (10ms) but no longer than the driver supports.
5946 */
5947 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5948 wait > rdev->wiphy.max_remain_on_channel_duration)
5949 return -EINVAL;
5950
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005951 }
5952
Jouni Malinen026331c2010-02-15 12:53:10 +02005953 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005954 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005955 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005956 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005957 }
5958
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005959 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5960
Johannes Berg7c4ef712011-11-18 15:33:48 +01005961 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5962 return -EINVAL;
5963
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305964 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5965
Jouni Malinen026331c2010-02-15 12:53:10 +02005966 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5967 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005968 if (chan == NULL)
5969 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005970
Johannes Berge247bd902011-11-04 11:18:21 +01005971 if (!dont_wait_for_ack) {
5972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5973 if (!msg)
5974 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005975
Johannes Berge247bd902011-11-04 11:18:21 +01005976 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5977 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005978
Johannes Berge247bd902011-11-04 11:18:21 +01005979 if (IS_ERR(hdr)) {
5980 err = PTR_ERR(hdr);
5981 goto free_msg;
5982 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005983 }
Johannes Berge247bd902011-11-04 11:18:21 +01005984
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005985 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5986 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005987 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5988 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005989 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005990 if (err)
5991 goto free_msg;
5992
Johannes Berge247bd902011-11-04 11:18:21 +01005993 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04005994 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5995 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02005996
Johannes Berge247bd902011-11-04 11:18:21 +01005997 genlmsg_end(msg, hdr);
5998 return genlmsg_reply(msg, info);
5999 }
6000
6001 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006002
6003 nla_put_failure:
6004 err = -ENOBUFS;
6005 free_msg:
6006 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006007 return err;
6008}
6009
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006010static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6011{
6012 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6013 struct net_device *dev = info->user_ptr[1];
6014 u64 cookie;
6015
6016 if (!info->attrs[NL80211_ATTR_COOKIE])
6017 return -EINVAL;
6018
6019 if (!rdev->ops->mgmt_tx_cancel_wait)
6020 return -EOPNOTSUPP;
6021
6022 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6023 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6025 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6028 return -EOPNOTSUPP;
6029
6030 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6031
6032 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6033}
6034
Kalle Valoffb9eb32010-02-17 17:58:10 +02006035static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6036{
Johannes Berg4c476992010-10-04 21:36:35 +02006037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006038 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006039 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006040 u8 ps_state;
6041 bool state;
6042 int err;
6043
Johannes Berg4c476992010-10-04 21:36:35 +02006044 if (!info->attrs[NL80211_ATTR_PS_STATE])
6045 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006046
6047 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6048
Johannes Berg4c476992010-10-04 21:36:35 +02006049 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6050 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006051
6052 wdev = dev->ieee80211_ptr;
6053
Johannes Berg4c476992010-10-04 21:36:35 +02006054 if (!rdev->ops->set_power_mgmt)
6055 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006056
6057 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6058
6059 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006060 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006061
Johannes Berg4c476992010-10-04 21:36:35 +02006062 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6063 wdev->ps_timeout);
6064 if (!err)
6065 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006066 return err;
6067}
6068
6069static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6070{
Johannes Berg4c476992010-10-04 21:36:35 +02006071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006072 enum nl80211_ps_state ps_state;
6073 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006074 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006075 struct sk_buff *msg;
6076 void *hdr;
6077 int err;
6078
Kalle Valoffb9eb32010-02-17 17:58:10 +02006079 wdev = dev->ieee80211_ptr;
6080
Johannes Berg4c476992010-10-04 21:36:35 +02006081 if (!rdev->ops->set_power_mgmt)
6082 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006083
6084 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006085 if (!msg)
6086 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006087
6088 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6089 NL80211_CMD_GET_POWER_SAVE);
6090 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006091 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006092 goto free_msg;
6093 }
6094
6095 if (wdev->ps)
6096 ps_state = NL80211_PS_ENABLED;
6097 else
6098 ps_state = NL80211_PS_DISABLED;
6099
David S. Miller9360ffd2012-03-29 04:41:26 -04006100 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6101 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006102
6103 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006104 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006105
Johannes Berg4c476992010-10-04 21:36:35 +02006106 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006107 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006108 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006109 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110 return err;
6111}
6112
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006113static struct nla_policy
6114nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6115 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6116 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6117 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6118};
6119
6120static int nl80211_set_cqm_rssi(struct genl_info *info,
6121 s32 threshold, u32 hysteresis)
6122{
Johannes Berg4c476992010-10-04 21:36:35 +02006123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006124 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006125 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006126
6127 if (threshold > 0)
6128 return -EINVAL;
6129
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006130 wdev = dev->ieee80211_ptr;
6131
Johannes Berg4c476992010-10-04 21:36:35 +02006132 if (!rdev->ops->set_cqm_rssi_config)
6133 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006134
Johannes Berg074ac8d2010-09-16 14:58:22 +02006135 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006136 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6137 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006138
Johannes Berg4c476992010-10-04 21:36:35 +02006139 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6140 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006141}
6142
6143static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6144{
6145 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6146 struct nlattr *cqm;
6147 int err;
6148
6149 cqm = info->attrs[NL80211_ATTR_CQM];
6150 if (!cqm) {
6151 err = -EINVAL;
6152 goto out;
6153 }
6154
6155 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6156 nl80211_attr_cqm_policy);
6157 if (err)
6158 goto out;
6159
6160 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6161 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6162 s32 threshold;
6163 u32 hysteresis;
6164 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6165 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6166 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6167 } else
6168 err = -EINVAL;
6169
6170out:
6171 return err;
6172}
6173
Johannes Berg29cbe682010-12-03 09:20:44 +01006174static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6175{
6176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6177 struct net_device *dev = info->user_ptr[1];
6178 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006179 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006180 int err;
6181
6182 /* start with default */
6183 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006184 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006185
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006186 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006187 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006188 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006189 if (err)
6190 return err;
6191 }
6192
6193 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6194 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6195 return -EINVAL;
6196
Javier Cardonac80d5452010-12-16 17:37:49 -08006197 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6198 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6199
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006200 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6201 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6202 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6203 return -EINVAL;
6204
Javier Cardonac80d5452010-12-16 17:37:49 -08006205 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6206 /* parse additional setup parameters if given */
6207 err = nl80211_parse_mesh_setup(info, &setup);
6208 if (err)
6209 return err;
6210 }
6211
Johannes Bergcc1d2802012-05-16 23:50:20 +02006212 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6213 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6214
6215 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6216 !nl80211_valid_channel_type(info, &channel_type))
6217 return -EINVAL;
6218
6219 setup.channel = rdev_freq_to_chan(rdev,
6220 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6221 channel_type);
6222 if (!setup.channel)
6223 return -EINVAL;
6224 setup.channel_type = channel_type;
6225 } else {
6226 /* cfg80211_join_mesh() will sort it out */
6227 setup.channel = NULL;
6228 }
6229
Javier Cardonac80d5452010-12-16 17:37:49 -08006230 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006231}
6232
6233static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6234{
6235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6236 struct net_device *dev = info->user_ptr[1];
6237
6238 return cfg80211_leave_mesh(rdev, dev);
6239}
6240
Johannes Bergff1b6e62011-05-04 15:37:28 +02006241static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6242{
6243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6244 struct sk_buff *msg;
6245 void *hdr;
6246
6247 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6248 return -EOPNOTSUPP;
6249
6250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6251 if (!msg)
6252 return -ENOMEM;
6253
6254 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6255 NL80211_CMD_GET_WOWLAN);
6256 if (!hdr)
6257 goto nla_put_failure;
6258
6259 if (rdev->wowlan) {
6260 struct nlattr *nl_wowlan;
6261
6262 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6263 if (!nl_wowlan)
6264 goto nla_put_failure;
6265
David S. Miller9360ffd2012-03-29 04:41:26 -04006266 if ((rdev->wowlan->any &&
6267 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6268 (rdev->wowlan->disconnect &&
6269 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6270 (rdev->wowlan->magic_pkt &&
6271 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6272 (rdev->wowlan->gtk_rekey_failure &&
6273 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6274 (rdev->wowlan->eap_identity_req &&
6275 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6276 (rdev->wowlan->four_way_handshake &&
6277 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6278 (rdev->wowlan->rfkill_release &&
6279 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6280 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006281 if (rdev->wowlan->n_patterns) {
6282 struct nlattr *nl_pats, *nl_pat;
6283 int i, pat_len;
6284
6285 nl_pats = nla_nest_start(msg,
6286 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6287 if (!nl_pats)
6288 goto nla_put_failure;
6289
6290 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6291 nl_pat = nla_nest_start(msg, i + 1);
6292 if (!nl_pat)
6293 goto nla_put_failure;
6294 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006295 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6296 DIV_ROUND_UP(pat_len, 8),
6297 rdev->wowlan->patterns[i].mask) ||
6298 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6299 pat_len,
6300 rdev->wowlan->patterns[i].pattern))
6301 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006302 nla_nest_end(msg, nl_pat);
6303 }
6304 nla_nest_end(msg, nl_pats);
6305 }
6306
6307 nla_nest_end(msg, nl_wowlan);
6308 }
6309
6310 genlmsg_end(msg, hdr);
6311 return genlmsg_reply(msg, info);
6312
6313nla_put_failure:
6314 nlmsg_free(msg);
6315 return -ENOBUFS;
6316}
6317
6318static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6319{
6320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6321 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6322 struct cfg80211_wowlan no_triggers = {};
6323 struct cfg80211_wowlan new_triggers = {};
6324 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6325 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006326 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006327
6328 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6329 return -EOPNOTSUPP;
6330
6331 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6332 goto no_triggers;
6333
6334 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6335 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6336 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6337 nl80211_wowlan_policy);
6338 if (err)
6339 return err;
6340
6341 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6342 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6343 return -EINVAL;
6344 new_triggers.any = true;
6345 }
6346
6347 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6348 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6349 return -EINVAL;
6350 new_triggers.disconnect = true;
6351 }
6352
6353 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6354 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6355 return -EINVAL;
6356 new_triggers.magic_pkt = true;
6357 }
6358
Johannes Berg77dbbb12011-07-13 10:48:55 +02006359 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6360 return -EINVAL;
6361
6362 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6363 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6364 return -EINVAL;
6365 new_triggers.gtk_rekey_failure = true;
6366 }
6367
6368 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6369 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6370 return -EINVAL;
6371 new_triggers.eap_identity_req = true;
6372 }
6373
6374 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6375 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6376 return -EINVAL;
6377 new_triggers.four_way_handshake = true;
6378 }
6379
6380 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6381 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6382 return -EINVAL;
6383 new_triggers.rfkill_release = true;
6384 }
6385
Johannes Bergff1b6e62011-05-04 15:37:28 +02006386 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6387 struct nlattr *pat;
6388 int n_patterns = 0;
6389 int rem, pat_len, mask_len;
6390 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6391
6392 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6393 rem)
6394 n_patterns++;
6395 if (n_patterns > wowlan->n_patterns)
6396 return -EINVAL;
6397
6398 new_triggers.patterns = kcalloc(n_patterns,
6399 sizeof(new_triggers.patterns[0]),
6400 GFP_KERNEL);
6401 if (!new_triggers.patterns)
6402 return -ENOMEM;
6403
6404 new_triggers.n_patterns = n_patterns;
6405 i = 0;
6406
6407 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6408 rem) {
6409 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6410 nla_data(pat), nla_len(pat), NULL);
6411 err = -EINVAL;
6412 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6413 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6414 goto error;
6415 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6416 mask_len = DIV_ROUND_UP(pat_len, 8);
6417 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6418 mask_len)
6419 goto error;
6420 if (pat_len > wowlan->pattern_max_len ||
6421 pat_len < wowlan->pattern_min_len)
6422 goto error;
6423
6424 new_triggers.patterns[i].mask =
6425 kmalloc(mask_len + pat_len, GFP_KERNEL);
6426 if (!new_triggers.patterns[i].mask) {
6427 err = -ENOMEM;
6428 goto error;
6429 }
6430 new_triggers.patterns[i].pattern =
6431 new_triggers.patterns[i].mask + mask_len;
6432 memcpy(new_triggers.patterns[i].mask,
6433 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6434 mask_len);
6435 new_triggers.patterns[i].pattern_len = pat_len;
6436 memcpy(new_triggers.patterns[i].pattern,
6437 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6438 pat_len);
6439 i++;
6440 }
6441 }
6442
6443 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6444 struct cfg80211_wowlan *ntrig;
6445 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6446 GFP_KERNEL);
6447 if (!ntrig) {
6448 err = -ENOMEM;
6449 goto error;
6450 }
6451 cfg80211_rdev_free_wowlan(rdev);
6452 rdev->wowlan = ntrig;
6453 } else {
6454 no_triggers:
6455 cfg80211_rdev_free_wowlan(rdev);
6456 rdev->wowlan = NULL;
6457 }
6458
Johannes Berg6d525632012-04-04 15:05:25 +02006459 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6460 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6461
Johannes Bergff1b6e62011-05-04 15:37:28 +02006462 return 0;
6463 error:
6464 for (i = 0; i < new_triggers.n_patterns; i++)
6465 kfree(new_triggers.patterns[i].mask);
6466 kfree(new_triggers.patterns);
6467 return err;
6468}
6469
Johannes Berge5497d72011-07-05 16:35:40 +02006470static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6471{
6472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6473 struct net_device *dev = info->user_ptr[1];
6474 struct wireless_dev *wdev = dev->ieee80211_ptr;
6475 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6476 struct cfg80211_gtk_rekey_data rekey_data;
6477 int err;
6478
6479 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6480 return -EINVAL;
6481
6482 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6483 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6484 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6485 nl80211_rekey_policy);
6486 if (err)
6487 return err;
6488
6489 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6490 return -ERANGE;
6491 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6492 return -ERANGE;
6493 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6494 return -ERANGE;
6495
6496 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6497 NL80211_KEK_LEN);
6498 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6499 NL80211_KCK_LEN);
6500 memcpy(rekey_data.replay_ctr,
6501 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6502 NL80211_REPLAY_CTR_LEN);
6503
6504 wdev_lock(wdev);
6505 if (!wdev->current_bss) {
6506 err = -ENOTCONN;
6507 goto out;
6508 }
6509
6510 if (!rdev->ops->set_rekey_data) {
6511 err = -EOPNOTSUPP;
6512 goto out;
6513 }
6514
6515 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6516 out:
6517 wdev_unlock(wdev);
6518 return err;
6519}
6520
Johannes Berg28946da2011-11-04 11:18:12 +01006521static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6522 struct genl_info *info)
6523{
6524 struct net_device *dev = info->user_ptr[1];
6525 struct wireless_dev *wdev = dev->ieee80211_ptr;
6526
6527 if (wdev->iftype != NL80211_IFTYPE_AP &&
6528 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6529 return -EINVAL;
6530
6531 if (wdev->ap_unexpected_nlpid)
6532 return -EBUSY;
6533
6534 wdev->ap_unexpected_nlpid = info->snd_pid;
6535 return 0;
6536}
6537
Johannes Berg7f6cf312011-11-04 11:18:15 +01006538static int nl80211_probe_client(struct sk_buff *skb,
6539 struct genl_info *info)
6540{
6541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6542 struct net_device *dev = info->user_ptr[1];
6543 struct wireless_dev *wdev = dev->ieee80211_ptr;
6544 struct sk_buff *msg;
6545 void *hdr;
6546 const u8 *addr;
6547 u64 cookie;
6548 int err;
6549
6550 if (wdev->iftype != NL80211_IFTYPE_AP &&
6551 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6552 return -EOPNOTSUPP;
6553
6554 if (!info->attrs[NL80211_ATTR_MAC])
6555 return -EINVAL;
6556
6557 if (!rdev->ops->probe_client)
6558 return -EOPNOTSUPP;
6559
6560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6561 if (!msg)
6562 return -ENOMEM;
6563
6564 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6565 NL80211_CMD_PROBE_CLIENT);
6566
6567 if (IS_ERR(hdr)) {
6568 err = PTR_ERR(hdr);
6569 goto free_msg;
6570 }
6571
6572 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6573
6574 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6575 if (err)
6576 goto free_msg;
6577
David S. Miller9360ffd2012-03-29 04:41:26 -04006578 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6579 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006580
6581 genlmsg_end(msg, hdr);
6582
6583 return genlmsg_reply(msg, info);
6584
6585 nla_put_failure:
6586 err = -ENOBUFS;
6587 free_msg:
6588 nlmsg_free(msg);
6589 return err;
6590}
6591
Johannes Berg5e7602302011-11-04 11:18:17 +01006592static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6593{
6594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6595
6596 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6597 return -EOPNOTSUPP;
6598
6599 if (rdev->ap_beacons_nlpid)
6600 return -EBUSY;
6601
6602 rdev->ap_beacons_nlpid = info->snd_pid;
6603
6604 return 0;
6605}
6606
Johannes Berg4c476992010-10-04 21:36:35 +02006607#define NL80211_FLAG_NEED_WIPHY 0x01
6608#define NL80211_FLAG_NEED_NETDEV 0x02
6609#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006610#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6611#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6612 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006613
6614static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6615 struct genl_info *info)
6616{
6617 struct cfg80211_registered_device *rdev;
6618 struct net_device *dev;
6619 int err;
6620 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6621
6622 if (rtnl)
6623 rtnl_lock();
6624
6625 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6626 rdev = cfg80211_get_dev_from_info(info);
6627 if (IS_ERR(rdev)) {
6628 if (rtnl)
6629 rtnl_unlock();
6630 return PTR_ERR(rdev);
6631 }
6632 info->user_ptr[0] = rdev;
6633 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006634 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6635 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006636 if (err) {
6637 if (rtnl)
6638 rtnl_unlock();
6639 return err;
6640 }
Johannes Berg41265712010-10-04 21:14:05 +02006641 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6642 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006643 cfg80211_unlock_rdev(rdev);
6644 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006645 if (rtnl)
6646 rtnl_unlock();
6647 return -ENETDOWN;
6648 }
Johannes Berg4c476992010-10-04 21:36:35 +02006649 info->user_ptr[0] = rdev;
6650 info->user_ptr[1] = dev;
6651 }
6652
6653 return 0;
6654}
6655
6656static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6657 struct genl_info *info)
6658{
6659 if (info->user_ptr[0])
6660 cfg80211_unlock_rdev(info->user_ptr[0]);
6661 if (info->user_ptr[1])
6662 dev_put(info->user_ptr[1]);
6663 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6664 rtnl_unlock();
6665}
6666
Johannes Berg55682962007-09-20 13:09:35 -04006667static struct genl_ops nl80211_ops[] = {
6668 {
6669 .cmd = NL80211_CMD_GET_WIPHY,
6670 .doit = nl80211_get_wiphy,
6671 .dumpit = nl80211_dump_wiphy,
6672 .policy = nl80211_policy,
6673 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006674 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006675 },
6676 {
6677 .cmd = NL80211_CMD_SET_WIPHY,
6678 .doit = nl80211_set_wiphy,
6679 .policy = nl80211_policy,
6680 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006681 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006682 },
6683 {
6684 .cmd = NL80211_CMD_GET_INTERFACE,
6685 .doit = nl80211_get_interface,
6686 .dumpit = nl80211_dump_interface,
6687 .policy = nl80211_policy,
6688 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006689 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006690 },
6691 {
6692 .cmd = NL80211_CMD_SET_INTERFACE,
6693 .doit = nl80211_set_interface,
6694 .policy = nl80211_policy,
6695 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006696 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6697 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006698 },
6699 {
6700 .cmd = NL80211_CMD_NEW_INTERFACE,
6701 .doit = nl80211_new_interface,
6702 .policy = nl80211_policy,
6703 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006704 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6705 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006706 },
6707 {
6708 .cmd = NL80211_CMD_DEL_INTERFACE,
6709 .doit = nl80211_del_interface,
6710 .policy = nl80211_policy,
6711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6713 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006714 },
Johannes Berg41ade002007-12-19 02:03:29 +01006715 {
6716 .cmd = NL80211_CMD_GET_KEY,
6717 .doit = nl80211_get_key,
6718 .policy = nl80211_policy,
6719 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006720 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006721 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006722 },
6723 {
6724 .cmd = NL80211_CMD_SET_KEY,
6725 .doit = nl80211_set_key,
6726 .policy = nl80211_policy,
6727 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006729 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006730 },
6731 {
6732 .cmd = NL80211_CMD_NEW_KEY,
6733 .doit = nl80211_new_key,
6734 .policy = nl80211_policy,
6735 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006737 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006738 },
6739 {
6740 .cmd = NL80211_CMD_DEL_KEY,
6741 .doit = nl80211_del_key,
6742 .policy = nl80211_policy,
6743 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006745 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006746 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006747 {
6748 .cmd = NL80211_CMD_SET_BEACON,
6749 .policy = nl80211_policy,
6750 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006751 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006753 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006754 },
6755 {
Johannes Berg88600202012-02-13 15:17:18 +01006756 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006757 .policy = nl80211_policy,
6758 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006759 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006760 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006761 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006762 },
6763 {
Johannes Berg88600202012-02-13 15:17:18 +01006764 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006765 .policy = nl80211_policy,
6766 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006767 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006769 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006770 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006771 {
6772 .cmd = NL80211_CMD_GET_STATION,
6773 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006774 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006775 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6777 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006778 },
6779 {
6780 .cmd = NL80211_CMD_SET_STATION,
6781 .doit = nl80211_set_station,
6782 .policy = nl80211_policy,
6783 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006785 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006786 },
6787 {
6788 .cmd = NL80211_CMD_NEW_STATION,
6789 .doit = nl80211_new_station,
6790 .policy = nl80211_policy,
6791 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006793 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006794 },
6795 {
6796 .cmd = NL80211_CMD_DEL_STATION,
6797 .doit = nl80211_del_station,
6798 .policy = nl80211_policy,
6799 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006801 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006802 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006803 {
6804 .cmd = NL80211_CMD_GET_MPATH,
6805 .doit = nl80211_get_mpath,
6806 .dumpit = nl80211_dump_mpath,
6807 .policy = nl80211_policy,
6808 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006810 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006811 },
6812 {
6813 .cmd = NL80211_CMD_SET_MPATH,
6814 .doit = nl80211_set_mpath,
6815 .policy = nl80211_policy,
6816 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006817 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006818 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006819 },
6820 {
6821 .cmd = NL80211_CMD_NEW_MPATH,
6822 .doit = nl80211_new_mpath,
6823 .policy = nl80211_policy,
6824 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006825 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006826 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006827 },
6828 {
6829 .cmd = NL80211_CMD_DEL_MPATH,
6830 .doit = nl80211_del_mpath,
6831 .policy = nl80211_policy,
6832 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006834 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006835 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006836 {
6837 .cmd = NL80211_CMD_SET_BSS,
6838 .doit = nl80211_set_bss,
6839 .policy = nl80211_policy,
6840 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006841 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006842 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006843 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006844 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006845 .cmd = NL80211_CMD_GET_REG,
6846 .doit = nl80211_get_reg,
6847 .policy = nl80211_policy,
6848 /* can be retrieved by unprivileged users */
6849 },
6850 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006851 .cmd = NL80211_CMD_SET_REG,
6852 .doit = nl80211_set_reg,
6853 .policy = nl80211_policy,
6854 .flags = GENL_ADMIN_PERM,
6855 },
6856 {
6857 .cmd = NL80211_CMD_REQ_SET_REG,
6858 .doit = nl80211_req_set_reg,
6859 .policy = nl80211_policy,
6860 .flags = GENL_ADMIN_PERM,
6861 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006862 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006863 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6864 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006865 .policy = nl80211_policy,
6866 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006868 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006869 },
6870 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006871 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6872 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006873 .policy = nl80211_policy,
6874 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006876 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006877 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006878 {
Johannes Berg2a519312009-02-10 21:25:55 +01006879 .cmd = NL80211_CMD_TRIGGER_SCAN,
6880 .doit = nl80211_trigger_scan,
6881 .policy = nl80211_policy,
6882 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006883 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006884 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006885 },
6886 {
6887 .cmd = NL80211_CMD_GET_SCAN,
6888 .policy = nl80211_policy,
6889 .dumpit = nl80211_dump_scan,
6890 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006891 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006892 .cmd = NL80211_CMD_START_SCHED_SCAN,
6893 .doit = nl80211_start_sched_scan,
6894 .policy = nl80211_policy,
6895 .flags = GENL_ADMIN_PERM,
6896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6897 NL80211_FLAG_NEED_RTNL,
6898 },
6899 {
6900 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6901 .doit = nl80211_stop_sched_scan,
6902 .policy = nl80211_policy,
6903 .flags = GENL_ADMIN_PERM,
6904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6905 NL80211_FLAG_NEED_RTNL,
6906 },
6907 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006908 .cmd = NL80211_CMD_AUTHENTICATE,
6909 .doit = nl80211_authenticate,
6910 .policy = nl80211_policy,
6911 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006913 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006914 },
6915 {
6916 .cmd = NL80211_CMD_ASSOCIATE,
6917 .doit = nl80211_associate,
6918 .policy = nl80211_policy,
6919 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006921 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006922 },
6923 {
6924 .cmd = NL80211_CMD_DEAUTHENTICATE,
6925 .doit = nl80211_deauthenticate,
6926 .policy = nl80211_policy,
6927 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006928 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006929 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006930 },
6931 {
6932 .cmd = NL80211_CMD_DISASSOCIATE,
6933 .doit = nl80211_disassociate,
6934 .policy = nl80211_policy,
6935 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006937 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006938 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006939 {
6940 .cmd = NL80211_CMD_JOIN_IBSS,
6941 .doit = nl80211_join_ibss,
6942 .policy = nl80211_policy,
6943 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006945 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006946 },
6947 {
6948 .cmd = NL80211_CMD_LEAVE_IBSS,
6949 .doit = nl80211_leave_ibss,
6950 .policy = nl80211_policy,
6951 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006953 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006954 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006955#ifdef CONFIG_NL80211_TESTMODE
6956 {
6957 .cmd = NL80211_CMD_TESTMODE,
6958 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006959 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006960 .policy = nl80211_policy,
6961 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006962 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6963 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006964 },
6965#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006966 {
6967 .cmd = NL80211_CMD_CONNECT,
6968 .doit = nl80211_connect,
6969 .policy = nl80211_policy,
6970 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006971 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006972 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973 },
6974 {
6975 .cmd = NL80211_CMD_DISCONNECT,
6976 .doit = nl80211_disconnect,
6977 .policy = nl80211_policy,
6978 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006979 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006980 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006981 },
Johannes Berg463d0182009-07-14 00:33:35 +02006982 {
6983 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6984 .doit = nl80211_wiphy_netns,
6985 .policy = nl80211_policy,
6986 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006987 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6988 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006989 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006990 {
6991 .cmd = NL80211_CMD_GET_SURVEY,
6992 .policy = nl80211_policy,
6993 .dumpit = nl80211_dump_survey,
6994 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006995 {
6996 .cmd = NL80211_CMD_SET_PMKSA,
6997 .doit = nl80211_setdel_pmksa,
6998 .policy = nl80211_policy,
6999 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007000 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007001 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007002 },
7003 {
7004 .cmd = NL80211_CMD_DEL_PMKSA,
7005 .doit = nl80211_setdel_pmksa,
7006 .policy = nl80211_policy,
7007 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007009 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007010 },
7011 {
7012 .cmd = NL80211_CMD_FLUSH_PMKSA,
7013 .doit = nl80211_flush_pmksa,
7014 .policy = nl80211_policy,
7015 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007017 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007018 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007019 {
7020 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7021 .doit = nl80211_remain_on_channel,
7022 .policy = nl80211_policy,
7023 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007025 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007026 },
7027 {
7028 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7029 .doit = nl80211_cancel_remain_on_channel,
7030 .policy = nl80211_policy,
7031 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007033 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007034 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007035 {
7036 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7037 .doit = nl80211_set_tx_bitrate_mask,
7038 .policy = nl80211_policy,
7039 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007040 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7041 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007042 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007043 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007044 .cmd = NL80211_CMD_REGISTER_FRAME,
7045 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007046 .policy = nl80211_policy,
7047 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007048 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7049 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007050 },
7051 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007052 .cmd = NL80211_CMD_FRAME,
7053 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007054 .policy = nl80211_policy,
7055 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007057 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007058 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007059 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007060 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7061 .doit = nl80211_tx_mgmt_cancel_wait,
7062 .policy = nl80211_policy,
7063 .flags = GENL_ADMIN_PERM,
7064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7065 NL80211_FLAG_NEED_RTNL,
7066 },
7067 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007068 .cmd = NL80211_CMD_SET_POWER_SAVE,
7069 .doit = nl80211_set_power_save,
7070 .policy = nl80211_policy,
7071 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007072 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7073 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007074 },
7075 {
7076 .cmd = NL80211_CMD_GET_POWER_SAVE,
7077 .doit = nl80211_get_power_save,
7078 .policy = nl80211_policy,
7079 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007080 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7081 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007082 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007083 {
7084 .cmd = NL80211_CMD_SET_CQM,
7085 .doit = nl80211_set_cqm,
7086 .policy = nl80211_policy,
7087 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007088 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7089 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007090 },
Johannes Bergf444de02010-05-05 15:25:02 +02007091 {
7092 .cmd = NL80211_CMD_SET_CHANNEL,
7093 .doit = nl80211_set_channel,
7094 .policy = nl80211_policy,
7095 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007096 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7097 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007098 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007099 {
7100 .cmd = NL80211_CMD_SET_WDS_PEER,
7101 .doit = nl80211_set_wds_peer,
7102 .policy = nl80211_policy,
7103 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007104 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7105 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007106 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007107 {
7108 .cmd = NL80211_CMD_JOIN_MESH,
7109 .doit = nl80211_join_mesh,
7110 .policy = nl80211_policy,
7111 .flags = GENL_ADMIN_PERM,
7112 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7113 NL80211_FLAG_NEED_RTNL,
7114 },
7115 {
7116 .cmd = NL80211_CMD_LEAVE_MESH,
7117 .doit = nl80211_leave_mesh,
7118 .policy = nl80211_policy,
7119 .flags = GENL_ADMIN_PERM,
7120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7121 NL80211_FLAG_NEED_RTNL,
7122 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02007123 {
7124 .cmd = NL80211_CMD_GET_WOWLAN,
7125 .doit = nl80211_get_wowlan,
7126 .policy = nl80211_policy,
7127 /* can be retrieved by unprivileged users */
7128 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7129 NL80211_FLAG_NEED_RTNL,
7130 },
7131 {
7132 .cmd = NL80211_CMD_SET_WOWLAN,
7133 .doit = nl80211_set_wowlan,
7134 .policy = nl80211_policy,
7135 .flags = GENL_ADMIN_PERM,
7136 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7137 NL80211_FLAG_NEED_RTNL,
7138 },
Johannes Berge5497d72011-07-05 16:35:40 +02007139 {
7140 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7141 .doit = nl80211_set_rekey_data,
7142 .policy = nl80211_policy,
7143 .flags = GENL_ADMIN_PERM,
7144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7145 NL80211_FLAG_NEED_RTNL,
7146 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007147 {
7148 .cmd = NL80211_CMD_TDLS_MGMT,
7149 .doit = nl80211_tdls_mgmt,
7150 .policy = nl80211_policy,
7151 .flags = GENL_ADMIN_PERM,
7152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7153 NL80211_FLAG_NEED_RTNL,
7154 },
7155 {
7156 .cmd = NL80211_CMD_TDLS_OPER,
7157 .doit = nl80211_tdls_oper,
7158 .policy = nl80211_policy,
7159 .flags = GENL_ADMIN_PERM,
7160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7161 NL80211_FLAG_NEED_RTNL,
7162 },
Johannes Berg28946da2011-11-04 11:18:12 +01007163 {
7164 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7165 .doit = nl80211_register_unexpected_frame,
7166 .policy = nl80211_policy,
7167 .flags = GENL_ADMIN_PERM,
7168 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7169 NL80211_FLAG_NEED_RTNL,
7170 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007171 {
7172 .cmd = NL80211_CMD_PROBE_CLIENT,
7173 .doit = nl80211_probe_client,
7174 .policy = nl80211_policy,
7175 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007177 NL80211_FLAG_NEED_RTNL,
7178 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007179 {
7180 .cmd = NL80211_CMD_REGISTER_BEACONS,
7181 .doit = nl80211_register_beacons,
7182 .policy = nl80211_policy,
7183 .flags = GENL_ADMIN_PERM,
7184 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7185 NL80211_FLAG_NEED_RTNL,
7186 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007187 {
7188 .cmd = NL80211_CMD_SET_NOACK_MAP,
7189 .doit = nl80211_set_noack_map,
7190 .policy = nl80211_policy,
7191 .flags = GENL_ADMIN_PERM,
7192 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7193 NL80211_FLAG_NEED_RTNL,
7194 },
7195
Johannes Berg55682962007-09-20 13:09:35 -04007196};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007197
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007198static struct genl_multicast_group nl80211_mlme_mcgrp = {
7199 .name = "mlme",
7200};
Johannes Berg55682962007-09-20 13:09:35 -04007201
7202/* multicast groups */
7203static struct genl_multicast_group nl80211_config_mcgrp = {
7204 .name = "config",
7205};
Johannes Berg2a519312009-02-10 21:25:55 +01007206static struct genl_multicast_group nl80211_scan_mcgrp = {
7207 .name = "scan",
7208};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007209static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7210 .name = "regulatory",
7211};
Johannes Berg55682962007-09-20 13:09:35 -04007212
7213/* notification functions */
7214
7215void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7216{
7217 struct sk_buff *msg;
7218
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007220 if (!msg)
7221 return;
7222
7223 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7224 nlmsg_free(msg);
7225 return;
7226 }
7227
Johannes Berg463d0182009-07-14 00:33:35 +02007228 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7229 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007230}
7231
Johannes Berg362a4152009-05-24 16:43:15 +02007232static int nl80211_add_scan_req(struct sk_buff *msg,
7233 struct cfg80211_registered_device *rdev)
7234{
7235 struct cfg80211_scan_request *req = rdev->scan_req;
7236 struct nlattr *nest;
7237 int i;
7238
Johannes Berg667503dd2009-07-07 03:56:11 +02007239 ASSERT_RDEV_LOCK(rdev);
7240
Johannes Berg362a4152009-05-24 16:43:15 +02007241 if (WARN_ON(!req))
7242 return 0;
7243
7244 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7245 if (!nest)
7246 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007247 for (i = 0; i < req->n_ssids; i++) {
7248 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7249 goto nla_put_failure;
7250 }
Johannes Berg362a4152009-05-24 16:43:15 +02007251 nla_nest_end(msg, nest);
7252
7253 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7254 if (!nest)
7255 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007256 for (i = 0; i < req->n_channels; i++) {
7257 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7258 goto nla_put_failure;
7259 }
Johannes Berg362a4152009-05-24 16:43:15 +02007260 nla_nest_end(msg, nest);
7261
David S. Miller9360ffd2012-03-29 04:41:26 -04007262 if (req->ie &&
7263 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7264 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007265
7266 return 0;
7267 nla_put_failure:
7268 return -ENOBUFS;
7269}
7270
Johannes Berga538e2d2009-06-16 19:56:42 +02007271static int nl80211_send_scan_msg(struct sk_buff *msg,
7272 struct cfg80211_registered_device *rdev,
7273 struct net_device *netdev,
7274 u32 pid, u32 seq, int flags,
7275 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007276{
7277 void *hdr;
7278
7279 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7280 if (!hdr)
7281 return -1;
7282
David S. Miller9360ffd2012-03-29 04:41:26 -04007283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7285 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007286
Johannes Berg362a4152009-05-24 16:43:15 +02007287 /* ignore errors and send incomplete event anyway */
7288 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007289
7290 return genlmsg_end(msg, hdr);
7291
7292 nla_put_failure:
7293 genlmsg_cancel(msg, hdr);
7294 return -EMSGSIZE;
7295}
7296
Luciano Coelho807f8a82011-05-11 17:09:35 +03007297static int
7298nl80211_send_sched_scan_msg(struct sk_buff *msg,
7299 struct cfg80211_registered_device *rdev,
7300 struct net_device *netdev,
7301 u32 pid, u32 seq, int flags, u32 cmd)
7302{
7303 void *hdr;
7304
7305 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7306 if (!hdr)
7307 return -1;
7308
David S. Miller9360ffd2012-03-29 04:41:26 -04007309 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7310 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7311 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007312
7313 return genlmsg_end(msg, hdr);
7314
7315 nla_put_failure:
7316 genlmsg_cancel(msg, hdr);
7317 return -EMSGSIZE;
7318}
7319
Johannes Berga538e2d2009-06-16 19:56:42 +02007320void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7321 struct net_device *netdev)
7322{
7323 struct sk_buff *msg;
7324
7325 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7326 if (!msg)
7327 return;
7328
7329 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7330 NL80211_CMD_TRIGGER_SCAN) < 0) {
7331 nlmsg_free(msg);
7332 return;
7333 }
7334
Johannes Berg463d0182009-07-14 00:33:35 +02007335 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7336 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007337}
7338
Johannes Berg2a519312009-02-10 21:25:55 +01007339void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7340 struct net_device *netdev)
7341{
7342 struct sk_buff *msg;
7343
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007344 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007345 if (!msg)
7346 return;
7347
Johannes Berga538e2d2009-06-16 19:56:42 +02007348 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7349 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007350 nlmsg_free(msg);
7351 return;
7352 }
7353
Johannes Berg463d0182009-07-14 00:33:35 +02007354 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7355 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007356}
7357
7358void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7359 struct net_device *netdev)
7360{
7361 struct sk_buff *msg;
7362
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007363 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007364 if (!msg)
7365 return;
7366
Johannes Berga538e2d2009-06-16 19:56:42 +02007367 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7368 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007369 nlmsg_free(msg);
7370 return;
7371 }
7372
Johannes Berg463d0182009-07-14 00:33:35 +02007373 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7374 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007375}
7376
Luciano Coelho807f8a82011-05-11 17:09:35 +03007377void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7378 struct net_device *netdev)
7379{
7380 struct sk_buff *msg;
7381
7382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7383 if (!msg)
7384 return;
7385
7386 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7387 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7388 nlmsg_free(msg);
7389 return;
7390 }
7391
7392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7393 nl80211_scan_mcgrp.id, GFP_KERNEL);
7394}
7395
7396void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7397 struct net_device *netdev, u32 cmd)
7398{
7399 struct sk_buff *msg;
7400
7401 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7402 if (!msg)
7403 return;
7404
7405 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7406 nlmsg_free(msg);
7407 return;
7408 }
7409
7410 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7411 nl80211_scan_mcgrp.id, GFP_KERNEL);
7412}
7413
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007414/*
7415 * This can happen on global regulatory changes or device specific settings
7416 * based on custom world regulatory domains.
7417 */
7418void nl80211_send_reg_change_event(struct regulatory_request *request)
7419{
7420 struct sk_buff *msg;
7421 void *hdr;
7422
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007424 if (!msg)
7425 return;
7426
7427 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7428 if (!hdr) {
7429 nlmsg_free(msg);
7430 return;
7431 }
7432
7433 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007434 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7435 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007436
David S. Miller9360ffd2012-03-29 04:41:26 -04007437 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7438 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7439 NL80211_REGDOM_TYPE_WORLD))
7440 goto nla_put_failure;
7441 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7442 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7443 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7444 goto nla_put_failure;
7445 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7446 request->intersect) {
7447 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7448 NL80211_REGDOM_TYPE_INTERSECTION))
7449 goto nla_put_failure;
7450 } else {
7451 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7452 NL80211_REGDOM_TYPE_COUNTRY) ||
7453 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7454 request->alpha2))
7455 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007456 }
7457
David S. Miller9360ffd2012-03-29 04:41:26 -04007458 if (wiphy_idx_valid(request->wiphy_idx) &&
7459 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7460 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007461
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007462 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007463
Johannes Bergbc43b282009-07-25 10:54:13 +02007464 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007465 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007466 GFP_ATOMIC);
7467 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007468
7469 return;
7470
7471nla_put_failure:
7472 genlmsg_cancel(msg, hdr);
7473 nlmsg_free(msg);
7474}
7475
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007476static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7477 struct net_device *netdev,
7478 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007479 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007480{
7481 struct sk_buff *msg;
7482 void *hdr;
7483
Johannes Berge6d6e342009-07-01 21:26:47 +02007484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007485 if (!msg)
7486 return;
7487
7488 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7489 if (!hdr) {
7490 nlmsg_free(msg);
7491 return;
7492 }
7493
David S. Miller9360ffd2012-03-29 04:41:26 -04007494 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7496 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7497 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007498
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007499 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007500
Johannes Berg463d0182009-07-14 00:33:35 +02007501 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7502 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007503 return;
7504
7505 nla_put_failure:
7506 genlmsg_cancel(msg, hdr);
7507 nlmsg_free(msg);
7508}
7509
7510void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007511 struct net_device *netdev, const u8 *buf,
7512 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007513{
7514 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007515 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007516}
7517
7518void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7519 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007520 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007521{
Johannes Berge6d6e342009-07-01 21:26:47 +02007522 nl80211_send_mlme_event(rdev, netdev, buf, len,
7523 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007524}
7525
Jouni Malinen53b46b82009-03-27 20:53:56 +02007526void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007527 struct net_device *netdev, const u8 *buf,
7528 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007529{
7530 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007531 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007532}
7533
Jouni Malinen53b46b82009-03-27 20:53:56 +02007534void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7535 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007536 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007537{
7538 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007539 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007540}
7541
Jouni Malinencf4e5942010-12-16 00:52:40 +02007542void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7543 struct net_device *netdev, const u8 *buf,
7544 size_t len, gfp_t gfp)
7545{
7546 nl80211_send_mlme_event(rdev, netdev, buf, len,
7547 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7548}
7549
7550void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7551 struct net_device *netdev, const u8 *buf,
7552 size_t len, gfp_t gfp)
7553{
7554 nl80211_send_mlme_event(rdev, netdev, buf, len,
7555 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7556}
7557
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007558static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7559 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007560 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007561{
7562 struct sk_buff *msg;
7563 void *hdr;
7564
Johannes Berge6d6e342009-07-01 21:26:47 +02007565 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007566 if (!msg)
7567 return;
7568
7569 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7570 if (!hdr) {
7571 nlmsg_free(msg);
7572 return;
7573 }
7574
David S. Miller9360ffd2012-03-29 04:41:26 -04007575 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7576 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7577 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7578 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7579 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007580
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007581 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007582
Johannes Berg463d0182009-07-14 00:33:35 +02007583 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7584 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007585 return;
7586
7587 nla_put_failure:
7588 genlmsg_cancel(msg, hdr);
7589 nlmsg_free(msg);
7590}
7591
7592void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007593 struct net_device *netdev, const u8 *addr,
7594 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007595{
7596 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007597 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007598}
7599
7600void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007601 struct net_device *netdev, const u8 *addr,
7602 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007603{
Johannes Berge6d6e342009-07-01 21:26:47 +02007604 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7605 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007606}
7607
Samuel Ortizb23aa672009-07-01 21:26:54 +02007608void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7609 struct net_device *netdev, const u8 *bssid,
7610 const u8 *req_ie, size_t req_ie_len,
7611 const u8 *resp_ie, size_t resp_ie_len,
7612 u16 status, gfp_t gfp)
7613{
7614 struct sk_buff *msg;
7615 void *hdr;
7616
7617 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7618 if (!msg)
7619 return;
7620
7621 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7622 if (!hdr) {
7623 nlmsg_free(msg);
7624 return;
7625 }
7626
David S. Miller9360ffd2012-03-29 04:41:26 -04007627 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7628 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7629 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7630 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7631 (req_ie &&
7632 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7633 (resp_ie &&
7634 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7635 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007636
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007637 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007638
Johannes Berg463d0182009-07-14 00:33:35 +02007639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7640 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007641 return;
7642
7643 nla_put_failure:
7644 genlmsg_cancel(msg, hdr);
7645 nlmsg_free(msg);
7646
7647}
7648
7649void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7650 struct net_device *netdev, const u8 *bssid,
7651 const u8 *req_ie, size_t req_ie_len,
7652 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7653{
7654 struct sk_buff *msg;
7655 void *hdr;
7656
7657 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7658 if (!msg)
7659 return;
7660
7661 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7662 if (!hdr) {
7663 nlmsg_free(msg);
7664 return;
7665 }
7666
David S. Miller9360ffd2012-03-29 04:41:26 -04007667 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7668 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7669 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7670 (req_ie &&
7671 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7672 (resp_ie &&
7673 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7674 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007675
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007676 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007677
Johannes Berg463d0182009-07-14 00:33:35 +02007678 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7679 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007680 return;
7681
7682 nla_put_failure:
7683 genlmsg_cancel(msg, hdr);
7684 nlmsg_free(msg);
7685
7686}
7687
7688void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7689 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007690 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007691{
7692 struct sk_buff *msg;
7693 void *hdr;
7694
Johannes Berg667503dd2009-07-07 03:56:11 +02007695 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007696 if (!msg)
7697 return;
7698
7699 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7700 if (!hdr) {
7701 nlmsg_free(msg);
7702 return;
7703 }
7704
David S. Miller9360ffd2012-03-29 04:41:26 -04007705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7707 (from_ap && reason &&
7708 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7709 (from_ap &&
7710 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7711 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7712 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007713
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007714 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007715
Johannes Berg463d0182009-07-14 00:33:35 +02007716 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7717 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007718 return;
7719
7720 nla_put_failure:
7721 genlmsg_cancel(msg, hdr);
7722 nlmsg_free(msg);
7723
7724}
7725
Johannes Berg04a773a2009-04-19 21:24:32 +02007726void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7727 struct net_device *netdev, const u8 *bssid,
7728 gfp_t gfp)
7729{
7730 struct sk_buff *msg;
7731 void *hdr;
7732
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007734 if (!msg)
7735 return;
7736
7737 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7738 if (!hdr) {
7739 nlmsg_free(msg);
7740 return;
7741 }
7742
David S. Miller9360ffd2012-03-29 04:41:26 -04007743 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7744 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7745 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7746 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007747
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007748 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007749
Johannes Berg463d0182009-07-14 00:33:35 +02007750 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7751 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007752 return;
7753
7754 nla_put_failure:
7755 genlmsg_cancel(msg, hdr);
7756 nlmsg_free(msg);
7757}
7758
Javier Cardonac93b5e72011-04-07 15:08:34 -07007759void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7760 struct net_device *netdev,
7761 const u8 *macaddr, const u8* ie, u8 ie_len,
7762 gfp_t gfp)
7763{
7764 struct sk_buff *msg;
7765 void *hdr;
7766
7767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7768 if (!msg)
7769 return;
7770
7771 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7772 if (!hdr) {
7773 nlmsg_free(msg);
7774 return;
7775 }
7776
David S. Miller9360ffd2012-03-29 04:41:26 -04007777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7778 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7779 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7780 (ie_len && ie &&
7781 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7782 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007783
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007784 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007785
7786 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7787 nl80211_mlme_mcgrp.id, gfp);
7788 return;
7789
7790 nla_put_failure:
7791 genlmsg_cancel(msg, hdr);
7792 nlmsg_free(msg);
7793}
7794
Jouni Malinena3b8b052009-03-27 21:59:49 +02007795void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7796 struct net_device *netdev, const u8 *addr,
7797 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007798 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007799{
7800 struct sk_buff *msg;
7801 void *hdr;
7802
Johannes Berge6d6e342009-07-01 21:26:47 +02007803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007804 if (!msg)
7805 return;
7806
7807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7808 if (!hdr) {
7809 nlmsg_free(msg);
7810 return;
7811 }
7812
David S. Miller9360ffd2012-03-29 04:41:26 -04007813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7815 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7816 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7817 (key_id != -1 &&
7818 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7819 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7820 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007821
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007822 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007823
Johannes Berg463d0182009-07-14 00:33:35 +02007824 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7825 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007826 return;
7827
7828 nla_put_failure:
7829 genlmsg_cancel(msg, hdr);
7830 nlmsg_free(msg);
7831}
7832
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007833void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7834 struct ieee80211_channel *channel_before,
7835 struct ieee80211_channel *channel_after)
7836{
7837 struct sk_buff *msg;
7838 void *hdr;
7839 struct nlattr *nl_freq;
7840
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007841 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007842 if (!msg)
7843 return;
7844
7845 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7846 if (!hdr) {
7847 nlmsg_free(msg);
7848 return;
7849 }
7850
7851 /*
7852 * Since we are applying the beacon hint to a wiphy we know its
7853 * wiphy_idx is valid
7854 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7856 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007857
7858 /* Before */
7859 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7860 if (!nl_freq)
7861 goto nla_put_failure;
7862 if (nl80211_msg_put_channel(msg, channel_before))
7863 goto nla_put_failure;
7864 nla_nest_end(msg, nl_freq);
7865
7866 /* After */
7867 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7868 if (!nl_freq)
7869 goto nla_put_failure;
7870 if (nl80211_msg_put_channel(msg, channel_after))
7871 goto nla_put_failure;
7872 nla_nest_end(msg, nl_freq);
7873
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007874 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007875
Johannes Berg463d0182009-07-14 00:33:35 +02007876 rcu_read_lock();
7877 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7878 GFP_ATOMIC);
7879 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007880
7881 return;
7882
7883nla_put_failure:
7884 genlmsg_cancel(msg, hdr);
7885 nlmsg_free(msg);
7886}
7887
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007888static void nl80211_send_remain_on_chan_event(
7889 int cmd, struct cfg80211_registered_device *rdev,
7890 struct net_device *netdev, u64 cookie,
7891 struct ieee80211_channel *chan,
7892 enum nl80211_channel_type channel_type,
7893 unsigned int duration, gfp_t gfp)
7894{
7895 struct sk_buff *msg;
7896 void *hdr;
7897
7898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7899 if (!msg)
7900 return;
7901
7902 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7903 if (!hdr) {
7904 nlmsg_free(msg);
7905 return;
7906 }
7907
David S. Miller9360ffd2012-03-29 04:41:26 -04007908 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7909 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7910 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7911 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7912 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7913 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007914
David S. Miller9360ffd2012-03-29 04:41:26 -04007915 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7916 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7917 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007918
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007919 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007920
7921 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7922 nl80211_mlme_mcgrp.id, gfp);
7923 return;
7924
7925 nla_put_failure:
7926 genlmsg_cancel(msg, hdr);
7927 nlmsg_free(msg);
7928}
7929
7930void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7931 struct net_device *netdev, u64 cookie,
7932 struct ieee80211_channel *chan,
7933 enum nl80211_channel_type channel_type,
7934 unsigned int duration, gfp_t gfp)
7935{
7936 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7937 rdev, netdev, cookie, chan,
7938 channel_type, duration, gfp);
7939}
7940
7941void nl80211_send_remain_on_channel_cancel(
7942 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7943 u64 cookie, struct ieee80211_channel *chan,
7944 enum nl80211_channel_type channel_type, gfp_t gfp)
7945{
7946 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7947 rdev, netdev, cookie, chan,
7948 channel_type, 0, gfp);
7949}
7950
Johannes Berg98b62182009-12-23 13:15:44 +01007951void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7952 struct net_device *dev, const u8 *mac_addr,
7953 struct station_info *sinfo, gfp_t gfp)
7954{
7955 struct sk_buff *msg;
7956
7957 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7958 if (!msg)
7959 return;
7960
John W. Linville66266b32012-03-15 13:25:41 -04007961 if (nl80211_send_station(msg, 0, 0, 0,
7962 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007963 nlmsg_free(msg);
7964 return;
7965 }
7966
7967 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7968 nl80211_mlme_mcgrp.id, gfp);
7969}
7970
Jouni Malinenec15e682011-03-23 15:29:52 +02007971void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7972 struct net_device *dev, const u8 *mac_addr,
7973 gfp_t gfp)
7974{
7975 struct sk_buff *msg;
7976 void *hdr;
7977
7978 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7979 if (!msg)
7980 return;
7981
7982 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7983 if (!hdr) {
7984 nlmsg_free(msg);
7985 return;
7986 }
7987
David S. Miller9360ffd2012-03-29 04:41:26 -04007988 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7989 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
7990 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02007991
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007992 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007993
7994 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7995 nl80211_mlme_mcgrp.id, gfp);
7996 return;
7997
7998 nla_put_failure:
7999 genlmsg_cancel(msg, hdr);
8000 nlmsg_free(msg);
8001}
8002
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008003static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8004 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008005{
8006 struct wireless_dev *wdev = dev->ieee80211_ptr;
8007 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8008 struct sk_buff *msg;
8009 void *hdr;
8010 int err;
8011 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8012
8013 if (!nlpid)
8014 return false;
8015
8016 msg = nlmsg_new(100, gfp);
8017 if (!msg)
8018 return true;
8019
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008020 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008021 if (!hdr) {
8022 nlmsg_free(msg);
8023 return true;
8024 }
8025
David S. Miller9360ffd2012-03-29 04:41:26 -04008026 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8027 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8028 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8029 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008030
8031 err = genlmsg_end(msg, hdr);
8032 if (err < 0) {
8033 nlmsg_free(msg);
8034 return true;
8035 }
8036
8037 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8038 return true;
8039
8040 nla_put_failure:
8041 genlmsg_cancel(msg, hdr);
8042 nlmsg_free(msg);
8043 return true;
8044}
8045
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008046bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8047{
8048 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8049 addr, gfp);
8050}
8051
8052bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8053 const u8 *addr, gfp_t gfp)
8054{
8055 return __nl80211_unexpected_frame(dev,
8056 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8057 addr, gfp);
8058}
8059
Johannes Berg2e161f72010-08-12 15:38:38 +02008060int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8061 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008062 int freq, int sig_dbm,
8063 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008064{
8065 struct sk_buff *msg;
8066 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008067
8068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8069 if (!msg)
8070 return -ENOMEM;
8071
Johannes Berg2e161f72010-08-12 15:38:38 +02008072 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008073 if (!hdr) {
8074 nlmsg_free(msg);
8075 return -ENOMEM;
8076 }
8077
David S. Miller9360ffd2012-03-29 04:41:26 -04008078 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8080 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8081 (sig_dbm &&
8082 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8083 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8084 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008085
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008086 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008087
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008088 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008089
8090 nla_put_failure:
8091 genlmsg_cancel(msg, hdr);
8092 nlmsg_free(msg);
8093 return -ENOBUFS;
8094}
8095
Johannes Berg2e161f72010-08-12 15:38:38 +02008096void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8097 struct net_device *netdev, u64 cookie,
8098 const u8 *buf, size_t len, bool ack,
8099 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008100{
8101 struct sk_buff *msg;
8102 void *hdr;
8103
8104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8105 if (!msg)
8106 return;
8107
Johannes Berg2e161f72010-08-12 15:38:38 +02008108 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008109 if (!hdr) {
8110 nlmsg_free(msg);
8111 return;
8112 }
8113
David S. Miller9360ffd2012-03-29 04:41:26 -04008114 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8115 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8116 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8117 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8118 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8119 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008120
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008121 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008122
8123 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8124 return;
8125
8126 nla_put_failure:
8127 genlmsg_cancel(msg, hdr);
8128 nlmsg_free(msg);
8129}
8130
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008131void
8132nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8133 struct net_device *netdev,
8134 enum nl80211_cqm_rssi_threshold_event rssi_event,
8135 gfp_t gfp)
8136{
8137 struct sk_buff *msg;
8138 struct nlattr *pinfoattr;
8139 void *hdr;
8140
8141 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8142 if (!msg)
8143 return;
8144
8145 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8146 if (!hdr) {
8147 nlmsg_free(msg);
8148 return;
8149 }
8150
David S. Miller9360ffd2012-03-29 04:41:26 -04008151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8153 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008154
8155 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8156 if (!pinfoattr)
8157 goto nla_put_failure;
8158
David S. Miller9360ffd2012-03-29 04:41:26 -04008159 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8160 rssi_event))
8161 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008162
8163 nla_nest_end(msg, pinfoattr);
8164
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008165 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008166
8167 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8168 nl80211_mlme_mcgrp.id, gfp);
8169 return;
8170
8171 nla_put_failure:
8172 genlmsg_cancel(msg, hdr);
8173 nlmsg_free(msg);
8174}
8175
Johannes Berge5497d72011-07-05 16:35:40 +02008176void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8177 struct net_device *netdev, const u8 *bssid,
8178 const u8 *replay_ctr, gfp_t gfp)
8179{
8180 struct sk_buff *msg;
8181 struct nlattr *rekey_attr;
8182 void *hdr;
8183
8184 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8185 if (!msg)
8186 return;
8187
8188 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8189 if (!hdr) {
8190 nlmsg_free(msg);
8191 return;
8192 }
8193
David S. Miller9360ffd2012-03-29 04:41:26 -04008194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8196 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8197 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008198
8199 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8200 if (!rekey_attr)
8201 goto nla_put_failure;
8202
David S. Miller9360ffd2012-03-29 04:41:26 -04008203 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8204 NL80211_REPLAY_CTR_LEN, replay_ctr))
8205 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008206
8207 nla_nest_end(msg, rekey_attr);
8208
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008209 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008210
8211 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8212 nl80211_mlme_mcgrp.id, gfp);
8213 return;
8214
8215 nla_put_failure:
8216 genlmsg_cancel(msg, hdr);
8217 nlmsg_free(msg);
8218}
8219
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008220void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8221 struct net_device *netdev, int index,
8222 const u8 *bssid, bool preauth, gfp_t gfp)
8223{
8224 struct sk_buff *msg;
8225 struct nlattr *attr;
8226 void *hdr;
8227
8228 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8229 if (!msg)
8230 return;
8231
8232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8233 if (!hdr) {
8234 nlmsg_free(msg);
8235 return;
8236 }
8237
David S. Miller9360ffd2012-03-29 04:41:26 -04008238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8239 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8240 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008241
8242 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8243 if (!attr)
8244 goto nla_put_failure;
8245
David S. Miller9360ffd2012-03-29 04:41:26 -04008246 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8247 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8248 (preauth &&
8249 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8250 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008251
8252 nla_nest_end(msg, attr);
8253
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008254 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008255
8256 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8257 nl80211_mlme_mcgrp.id, gfp);
8258 return;
8259
8260 nla_put_failure:
8261 genlmsg_cancel(msg, hdr);
8262 nlmsg_free(msg);
8263}
8264
Thomas Pedersen53145262012-04-06 13:35:47 -07008265void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8266 struct net_device *netdev, int freq,
8267 enum nl80211_channel_type type, gfp_t gfp)
8268{
8269 struct sk_buff *msg;
8270 void *hdr;
8271
8272 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8273 if (!msg)
8274 return;
8275
8276 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8277 if (!hdr) {
8278 nlmsg_free(msg);
8279 return;
8280 }
8281
John W. Linville7eab0f62012-04-12 14:25:14 -04008282 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8283 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8284 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8285 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008286
8287 genlmsg_end(msg, hdr);
8288
8289 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8290 nl80211_mlme_mcgrp.id, gfp);
8291 return;
8292
8293 nla_put_failure:
8294 genlmsg_cancel(msg, hdr);
8295 nlmsg_free(msg);
8296}
8297
Johannes Bergc063dbf2010-11-24 08:10:05 +01008298void
8299nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8300 struct net_device *netdev, const u8 *peer,
8301 u32 num_packets, gfp_t gfp)
8302{
8303 struct sk_buff *msg;
8304 struct nlattr *pinfoattr;
8305 void *hdr;
8306
8307 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8308 if (!msg)
8309 return;
8310
8311 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8312 if (!hdr) {
8313 nlmsg_free(msg);
8314 return;
8315 }
8316
David S. Miller9360ffd2012-03-29 04:41:26 -04008317 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8318 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8319 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8320 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008321
8322 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8323 if (!pinfoattr)
8324 goto nla_put_failure;
8325
David S. Miller9360ffd2012-03-29 04:41:26 -04008326 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8327 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008328
8329 nla_nest_end(msg, pinfoattr);
8330
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008331 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008332
8333 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8334 nl80211_mlme_mcgrp.id, gfp);
8335 return;
8336
8337 nla_put_failure:
8338 genlmsg_cancel(msg, hdr);
8339 nlmsg_free(msg);
8340}
8341
Johannes Berg7f6cf312011-11-04 11:18:15 +01008342void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8343 u64 cookie, bool acked, gfp_t gfp)
8344{
8345 struct wireless_dev *wdev = dev->ieee80211_ptr;
8346 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8347 struct sk_buff *msg;
8348 void *hdr;
8349 int err;
8350
8351 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8352 if (!msg)
8353 return;
8354
8355 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8356 if (!hdr) {
8357 nlmsg_free(msg);
8358 return;
8359 }
8360
David S. Miller9360ffd2012-03-29 04:41:26 -04008361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8362 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8363 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8364 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8365 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8366 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008367
8368 err = genlmsg_end(msg, hdr);
8369 if (err < 0) {
8370 nlmsg_free(msg);
8371 return;
8372 }
8373
8374 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8375 nl80211_mlme_mcgrp.id, gfp);
8376 return;
8377
8378 nla_put_failure:
8379 genlmsg_cancel(msg, hdr);
8380 nlmsg_free(msg);
8381}
8382EXPORT_SYMBOL(cfg80211_probe_status);
8383
Johannes Berg5e7602302011-11-04 11:18:17 +01008384void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8385 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008386 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008387{
8388 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8389 struct sk_buff *msg;
8390 void *hdr;
8391 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8392
8393 if (!nlpid)
8394 return;
8395
8396 msg = nlmsg_new(len + 100, gfp);
8397 if (!msg)
8398 return;
8399
8400 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8401 if (!hdr) {
8402 nlmsg_free(msg);
8403 return;
8404 }
8405
David S. Miller9360ffd2012-03-29 04:41:26 -04008406 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8407 (freq &&
8408 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8409 (sig_dbm &&
8410 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8411 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8412 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008413
8414 genlmsg_end(msg, hdr);
8415
8416 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8417 return;
8418
8419 nla_put_failure:
8420 genlmsg_cancel(msg, hdr);
8421 nlmsg_free(msg);
8422}
8423EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8424
Jouni Malinen026331c2010-02-15 12:53:10 +02008425static int nl80211_netlink_notify(struct notifier_block * nb,
8426 unsigned long state,
8427 void *_notify)
8428{
8429 struct netlink_notify *notify = _notify;
8430 struct cfg80211_registered_device *rdev;
8431 struct wireless_dev *wdev;
8432
8433 if (state != NETLINK_URELEASE)
8434 return NOTIFY_DONE;
8435
8436 rcu_read_lock();
8437
Johannes Berg5e7602302011-11-04 11:18:17 +01008438 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008439 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008440 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008441 if (rdev->ap_beacons_nlpid == notify->pid)
8442 rdev->ap_beacons_nlpid = 0;
8443 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008444
8445 rcu_read_unlock();
8446
8447 return NOTIFY_DONE;
8448}
8449
8450static struct notifier_block nl80211_netlink_notifier = {
8451 .notifier_call = nl80211_netlink_notify,
8452};
8453
Johannes Berg55682962007-09-20 13:09:35 -04008454/* initialisation/exit functions */
8455
8456int nl80211_init(void)
8457{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008458 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008459
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008460 err = genl_register_family_with_ops(&nl80211_fam,
8461 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008462 if (err)
8463 return err;
8464
Johannes Berg55682962007-09-20 13:09:35 -04008465 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8466 if (err)
8467 goto err_out;
8468
Johannes Berg2a519312009-02-10 21:25:55 +01008469 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8470 if (err)
8471 goto err_out;
8472
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008473 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8474 if (err)
8475 goto err_out;
8476
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008477 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8478 if (err)
8479 goto err_out;
8480
Johannes Bergaff89a92009-07-01 21:26:51 +02008481#ifdef CONFIG_NL80211_TESTMODE
8482 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8483 if (err)
8484 goto err_out;
8485#endif
8486
Jouni Malinen026331c2010-02-15 12:53:10 +02008487 err = netlink_register_notifier(&nl80211_netlink_notifier);
8488 if (err)
8489 goto err_out;
8490
Johannes Berg55682962007-09-20 13:09:35 -04008491 return 0;
8492 err_out:
8493 genl_unregister_family(&nl80211_fam);
8494 return err;
8495}
8496
8497void nl80211_exit(void)
8498{
Jouni Malinen026331c2010-02-15 12:53:10 +02008499 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008500 genl_unregister_family(&nl80211_fam);
8501}