blob: 7e94d4d960bfda28f32e837f0b42393eb799e78d [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Jouni Malinen5fb628e2011-08-10 23:54:35 +030026static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
30 int cipher_limit);
31
Johannes Berg4c476992010-10-04 21:36:35 +020032static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
38static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020044 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020045 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040047};
48
Johannes Berg79c97e92009-07-07 03:56:12 +020049/* internal helper: get rdev and dev */
Johannes Berg00918d32011-12-13 17:22:05 +010050static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
51 struct cfg80211_registered_device **rdev,
52 struct net_device **dev)
Johannes Berg55682962007-09-20 13:09:35 -040053{
54 int ifindex;
55
Johannes Bergbba95fe2008-07-29 13:22:51 +020056 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040057 return -EINVAL;
58
Johannes Bergbba95fe2008-07-29 13:22:51 +020059 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg00918d32011-12-13 17:22:05 +010060 *dev = dev_get_by_index(netns, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040061 if (!*dev)
62 return -ENODEV;
63
Johannes Berg00918d32011-12-13 17:22:05 +010064 *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020065 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040066 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020067 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040068 }
69
70 return 0;
71}
72
Johannes Berga9455402012-06-15 13:32:49 +020073static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +020074__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +020075{
Johannes Berg7fee4772012-06-15 14:09:58 +020076 struct cfg80211_registered_device *rdev = NULL, *tmp;
77 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +020078
79 assert_cfg80211_lock();
80
Johannes Berg878d9ec2012-06-15 14:18:32 +020081 if (!attrs[NL80211_ATTR_WIPHY] &&
82 !attrs[NL80211_ATTR_IFINDEX])
Johannes Berg7fee4772012-06-15 14:09:58 +020083 return ERR_PTR(-EINVAL);
84
Johannes Berg878d9ec2012-06-15 14:18:32 +020085 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +020086 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +020087 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +020088
Johannes Berg878d9ec2012-06-15 14:18:32 +020089 if (attrs[NL80211_ATTR_IFINDEX]) {
90 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +020091 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +020092 if (netdev) {
93 if (netdev->ieee80211_ptr)
94 tmp = wiphy_to_dev(
95 netdev->ieee80211_ptr->wiphy);
96 else
97 tmp = NULL;
98
99 dev_put(netdev);
100
101 /* not wireless device -- return error */
102 if (!tmp)
103 return ERR_PTR(-EINVAL);
104
105 /* mismatch -- return error */
106 if (rdev && tmp != rdev)
107 return ERR_PTR(-EINVAL);
108
109 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200110 }
Johannes Berga9455402012-06-15 13:32:49 +0200111 }
112
Johannes Berg4f7eff12012-06-15 14:14:22 +0200113 if (!rdev)
114 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200115
Johannes Berg4f7eff12012-06-15 14:14:22 +0200116 if (netns != wiphy_net(&rdev->wiphy))
117 return ERR_PTR(-ENODEV);
118
119 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120}
121
122/*
123 * This function returns a pointer to the driver
124 * that the genl_info item that is passed refers to.
125 * If successful, it returns non-NULL and also locks
126 * the driver's mutex!
127 *
128 * This means that you need to call cfg80211_unlock_rdev()
129 * before being allowed to acquire &cfg80211_mutex!
130 *
131 * This is necessary because we need to lock the global
132 * mutex to get an item off the list safely, and then
133 * we lock the rdev mutex so it doesn't go away under us.
134 *
135 * We don't want to keep cfg80211_mutex locked
136 * for all the time in order to allow requests on
137 * other interfaces to go through at the same time.
138 *
139 * The result of this can be a PTR_ERR and hence must
140 * be checked with IS_ERR() for errors.
141 */
142static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200143cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200144{
145 struct cfg80211_registered_device *rdev;
146
147 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200148 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200149
150 /* if it is not an error we grab the lock on
151 * it to assure it won't be going away while
152 * we operate on it */
153 if (!IS_ERR(rdev))
154 mutex_lock(&rdev->mtx);
155
156 mutex_unlock(&cfg80211_mutex);
157
158 return rdev;
159}
160
Johannes Berg55682962007-09-20 13:09:35 -0400161/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000162static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400163 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
164 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700165 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200166 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200167 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530168 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200169 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
170 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
171 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
172 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100173 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400174
175 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
176 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
177 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100178
Eliad Pellere007b852011-11-24 18:13:56 +0200179 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
180 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100181
Johannes Bergb9454e82009-07-08 13:29:08 +0200182 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100183 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
184 .len = WLAN_MAX_KEY_LEN },
185 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
186 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
187 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200188 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200189 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100190
191 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
192 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
193 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
194 .len = IEEE80211_MAX_DATA_LEN },
195 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
196 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100197 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
198 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
199 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
200 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
201 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100202 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100203 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200204 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100205 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800206 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100207 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300208
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700209 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
210 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
211
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300212 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
213 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
214 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200215 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
216 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100217 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300218
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800219 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700220 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700221
Johannes Berg6c739412011-11-03 09:27:01 +0100222 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200223
224 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
225 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
226 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100227 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
228 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200229
230 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_SSID_LEN },
232 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200234 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300235 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300236 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300237 [NL80211_ATTR_STA_FLAGS2] = {
238 .len = sizeof(struct nl80211_sta_flag_update),
239 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300240 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300241 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
242 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200243 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
244 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
245 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200246 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100247 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100248 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
249 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100250 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
251 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200252 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200253 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
255 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200256 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200257 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300258 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200259 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300260 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
261 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200262 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900263 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
264 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100265 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100266 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100267 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200268 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700269 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300270 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200271 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200272 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300273 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300274 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
275 .len = IEEE80211_MAX_DATA_LEN },
276 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530278 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300279 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530280 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300281 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
282 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
283 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
284 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
285 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100286 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200287 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700289 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800290 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
291 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
292 .len = NL80211_HT_CAPABILITY_LEN
293 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100294 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530295 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530296 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400297};
298
Johannes Berge31b8212010-10-05 19:39:30 +0200299/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000300static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200301 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200302 [NL80211_KEY_IDX] = { .type = NLA_U8 },
303 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200304 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200305 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
306 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200307 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100308 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
309};
310
311/* policy for the key default flags */
312static const struct nla_policy
313nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
314 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
315 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200316};
317
Johannes Bergff1b6e62011-05-04 15:37:28 +0200318/* policy for WoWLAN attributes */
319static const struct nla_policy
320nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
321 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
322 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
323 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
324 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200325 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
326 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
327 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
328 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200329};
330
Johannes Berge5497d72011-07-05 16:35:40 +0200331/* policy for GTK rekey offload attributes */
332static const struct nla_policy
333nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
334 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
335 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
336 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
337};
338
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339static const struct nla_policy
340nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200341 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300342 .len = IEEE80211_MAX_SSID_LEN },
343};
344
Holger Schuriga0438972009-11-11 11:30:02 +0100345/* ifidx get helper */
346static int nl80211_get_ifidx(struct netlink_callback *cb)
347{
348 int res;
349
350 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
351 nl80211_fam.attrbuf, nl80211_fam.maxattr,
352 nl80211_policy);
353 if (res)
354 return res;
355
356 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
357 return -EINVAL;
358
359 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
360 if (!res)
361 return -EINVAL;
362 return res;
363}
364
Johannes Berg67748892010-10-04 21:14:06 +0200365static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
366 struct netlink_callback *cb,
367 struct cfg80211_registered_device **rdev,
368 struct net_device **dev)
369{
370 int ifidx = cb->args[0];
371 int err;
372
373 if (!ifidx)
374 ifidx = nl80211_get_ifidx(cb);
375 if (ifidx < 0)
376 return ifidx;
377
378 cb->args[0] = ifidx;
379
380 rtnl_lock();
381
382 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
383 if (!*dev) {
384 err = -ENODEV;
385 goto out_rtnl;
386 }
387
388 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100389 if (IS_ERR(*rdev)) {
390 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200391 goto out_rtnl;
392 }
393
394 return 0;
395 out_rtnl:
396 rtnl_unlock();
397 return err;
398}
399
400static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
401{
402 cfg80211_unlock_rdev(rdev);
403 rtnl_unlock();
404}
405
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100406/* IE validation */
407static bool is_valid_ie_attr(const struct nlattr *attr)
408{
409 const u8 *pos;
410 int len;
411
412 if (!attr)
413 return true;
414
415 pos = nla_data(attr);
416 len = nla_len(attr);
417
418 while (len) {
419 u8 elemlen;
420
421 if (len < 2)
422 return false;
423 len -= 2;
424
425 elemlen = pos[1];
426 if (elemlen > len)
427 return false;
428
429 len -= elemlen;
430 pos += 2 + elemlen;
431 }
432
433 return true;
434}
435
Johannes Berg55682962007-09-20 13:09:35 -0400436/* message building helper */
437static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
438 int flags, u8 cmd)
439{
440 /* since there is no private header just add the generic one */
441 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
442}
443
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400444static int nl80211_msg_put_channel(struct sk_buff *msg,
445 struct ieee80211_channel *chan)
446{
David S. Miller9360ffd2012-03-29 04:41:26 -0400447 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
448 chan->center_freq))
449 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400450
David S. Miller9360ffd2012-03-29 04:41:26 -0400451 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
452 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
453 goto nla_put_failure;
454 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
455 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
456 goto nla_put_failure;
457 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
458 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
459 goto nla_put_failure;
460 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
461 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
462 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400463
David S. Miller9360ffd2012-03-29 04:41:26 -0400464 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
465 DBM_TO_MBM(chan->max_power)))
466 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400467
468 return 0;
469
470 nla_put_failure:
471 return -ENOBUFS;
472}
473
Johannes Berg55682962007-09-20 13:09:35 -0400474/* netlink command implementations */
475
Johannes Bergb9454e82009-07-08 13:29:08 +0200476struct key_parse {
477 struct key_params p;
478 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200479 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200480 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100481 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200482};
483
484static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
485{
486 struct nlattr *tb[NL80211_KEY_MAX + 1];
487 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
488 nl80211_key_policy);
489 if (err)
490 return err;
491
492 k->def = !!tb[NL80211_KEY_DEFAULT];
493 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
494
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100495 if (k->def) {
496 k->def_uni = true;
497 k->def_multi = true;
498 }
499 if (k->defmgmt)
500 k->def_multi = true;
501
Johannes Bergb9454e82009-07-08 13:29:08 +0200502 if (tb[NL80211_KEY_IDX])
503 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
504
505 if (tb[NL80211_KEY_DATA]) {
506 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
507 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
508 }
509
510 if (tb[NL80211_KEY_SEQ]) {
511 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
512 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
513 }
514
515 if (tb[NL80211_KEY_CIPHER])
516 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
517
Johannes Berge31b8212010-10-05 19:39:30 +0200518 if (tb[NL80211_KEY_TYPE]) {
519 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
520 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
521 return -EINVAL;
522 }
523
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100524 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
525 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100526 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
527 tb[NL80211_KEY_DEFAULT_TYPES],
528 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100529 if (err)
530 return err;
531
532 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
533 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
534 }
535
Johannes Bergb9454e82009-07-08 13:29:08 +0200536 return 0;
537}
538
539static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
540{
541 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
542 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
543 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
544 }
545
546 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
547 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
548 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 }
550
551 if (info->attrs[NL80211_ATTR_KEY_IDX])
552 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
553
554 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
555 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
556
557 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
558 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
559
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100560 if (k->def) {
561 k->def_uni = true;
562 k->def_multi = true;
563 }
564 if (k->defmgmt)
565 k->def_multi = true;
566
Johannes Berge31b8212010-10-05 19:39:30 +0200567 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
568 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
569 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
570 return -EINVAL;
571 }
572
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100573 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
574 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
575 int err = nla_parse_nested(
576 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
577 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
578 nl80211_key_default_policy);
579 if (err)
580 return err;
581
582 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
583 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
584 }
585
Johannes Bergb9454e82009-07-08 13:29:08 +0200586 return 0;
587}
588
589static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
590{
591 int err;
592
593 memset(k, 0, sizeof(*k));
594 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200595 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200596
597 if (info->attrs[NL80211_ATTR_KEY])
598 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
599 else
600 err = nl80211_parse_key_old(info, k);
601
602 if (err)
603 return err;
604
605 if (k->def && k->defmgmt)
606 return -EINVAL;
607
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100608 if (k->defmgmt) {
609 if (k->def_uni || !k->def_multi)
610 return -EINVAL;
611 }
612
Johannes Bergb9454e82009-07-08 13:29:08 +0200613 if (k->idx != -1) {
614 if (k->defmgmt) {
615 if (k->idx < 4 || k->idx > 5)
616 return -EINVAL;
617 } else if (k->def) {
618 if (k->idx < 0 || k->idx > 3)
619 return -EINVAL;
620 } else {
621 if (k->idx < 0 || k->idx > 5)
622 return -EINVAL;
623 }
624 }
625
626 return 0;
627}
628
Johannes Bergfffd0932009-07-08 14:22:54 +0200629static struct cfg80211_cached_keys *
630nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
631 struct nlattr *keys)
632{
633 struct key_parse parse;
634 struct nlattr *key;
635 struct cfg80211_cached_keys *result;
636 int rem, err, def = 0;
637
638 result = kzalloc(sizeof(*result), GFP_KERNEL);
639 if (!result)
640 return ERR_PTR(-ENOMEM);
641
642 result->def = -1;
643 result->defmgmt = -1;
644
645 nla_for_each_nested(key, keys, rem) {
646 memset(&parse, 0, sizeof(parse));
647 parse.idx = -1;
648
649 err = nl80211_parse_key_new(key, &parse);
650 if (err)
651 goto error;
652 err = -EINVAL;
653 if (!parse.p.key)
654 goto error;
655 if (parse.idx < 0 || parse.idx > 4)
656 goto error;
657 if (parse.def) {
658 if (def)
659 goto error;
660 def = 1;
661 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100662 if (!parse.def_uni || !parse.def_multi)
663 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200664 } else if (parse.defmgmt)
665 goto error;
666 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200667 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200668 if (err)
669 goto error;
670 result->params[parse.idx].cipher = parse.p.cipher;
671 result->params[parse.idx].key_len = parse.p.key_len;
672 result->params[parse.idx].key = result->data[parse.idx];
673 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
674 }
675
676 return result;
677 error:
678 kfree(result);
679 return ERR_PTR(err);
680}
681
682static int nl80211_key_allowed(struct wireless_dev *wdev)
683{
684 ASSERT_WDEV_LOCK(wdev);
685
Johannes Bergfffd0932009-07-08 14:22:54 +0200686 switch (wdev->iftype) {
687 case NL80211_IFTYPE_AP:
688 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200689 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700690 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200691 break;
692 case NL80211_IFTYPE_ADHOC:
693 if (!wdev->current_bss)
694 return -ENOLINK;
695 break;
696 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200697 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200698 if (wdev->sme_state != CFG80211_SME_CONNECTED)
699 return -ENOLINK;
700 break;
701 default:
702 return -EINVAL;
703 }
704
705 return 0;
706}
707
Johannes Berg7527a782011-05-13 10:58:57 +0200708static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
709{
710 struct nlattr *nl_modes = nla_nest_start(msg, attr);
711 int i;
712
713 if (!nl_modes)
714 goto nla_put_failure;
715
716 i = 0;
717 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400718 if ((ifmodes & 1) && nla_put_flag(msg, i))
719 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200720 ifmodes >>= 1;
721 i++;
722 }
723
724 nla_nest_end(msg, nl_modes);
725 return 0;
726
727nla_put_failure:
728 return -ENOBUFS;
729}
730
731static int nl80211_put_iface_combinations(struct wiphy *wiphy,
732 struct sk_buff *msg)
733{
734 struct nlattr *nl_combis;
735 int i, j;
736
737 nl_combis = nla_nest_start(msg,
738 NL80211_ATTR_INTERFACE_COMBINATIONS);
739 if (!nl_combis)
740 goto nla_put_failure;
741
742 for (i = 0; i < wiphy->n_iface_combinations; i++) {
743 const struct ieee80211_iface_combination *c;
744 struct nlattr *nl_combi, *nl_limits;
745
746 c = &wiphy->iface_combinations[i];
747
748 nl_combi = nla_nest_start(msg, i + 1);
749 if (!nl_combi)
750 goto nla_put_failure;
751
752 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
753 if (!nl_limits)
754 goto nla_put_failure;
755
756 for (j = 0; j < c->n_limits; j++) {
757 struct nlattr *nl_limit;
758
759 nl_limit = nla_nest_start(msg, j + 1);
760 if (!nl_limit)
761 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400762 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
763 c->limits[j].max))
764 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200765 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
766 c->limits[j].types))
767 goto nla_put_failure;
768 nla_nest_end(msg, nl_limit);
769 }
770
771 nla_nest_end(msg, nl_limits);
772
David S. Miller9360ffd2012-03-29 04:41:26 -0400773 if (c->beacon_int_infra_match &&
774 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
775 goto nla_put_failure;
776 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
777 c->num_different_channels) ||
778 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
779 c->max_interfaces))
780 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200781
782 nla_nest_end(msg, nl_combi);
783 }
784
785 nla_nest_end(msg, nl_combis);
786
787 return 0;
788nla_put_failure:
789 return -ENOBUFS;
790}
791
Johannes Berg55682962007-09-20 13:09:35 -0400792static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
793 struct cfg80211_registered_device *dev)
794{
795 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100796 struct nlattr *nl_bands, *nl_band;
797 struct nlattr *nl_freqs, *nl_freq;
798 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100799 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100800 enum ieee80211_band band;
801 struct ieee80211_channel *chan;
802 struct ieee80211_rate *rate;
803 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200804 const struct ieee80211_txrx_stypes *mgmt_stypes =
805 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400806
807 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
808 if (!hdr)
809 return -1;
810
David S. Miller9360ffd2012-03-29 04:41:26 -0400811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
812 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
813 nla_put_u32(msg, NL80211_ATTR_GENERATION,
814 cfg80211_rdev_list_generation) ||
815 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
816 dev->wiphy.retry_short) ||
817 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
818 dev->wiphy.retry_long) ||
819 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
820 dev->wiphy.frag_threshold) ||
821 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
822 dev->wiphy.rts_threshold) ||
823 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
824 dev->wiphy.coverage_class) ||
825 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
826 dev->wiphy.max_scan_ssids) ||
827 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
828 dev->wiphy.max_sched_scan_ssids) ||
829 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
830 dev->wiphy.max_scan_ie_len) ||
831 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
832 dev->wiphy.max_sched_scan_ie_len) ||
833 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
834 dev->wiphy.max_match_sets))
835 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200836
David S. Miller9360ffd2012-03-29 04:41:26 -0400837 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
838 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
839 goto nla_put_failure;
840 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
841 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
842 goto nla_put_failure;
843 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
844 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
845 goto nla_put_failure;
846 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
847 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
848 goto nla_put_failure;
849 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
850 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
851 goto nla_put_failure;
852 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
853 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
854 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200855
David S. Miller9360ffd2012-03-29 04:41:26 -0400856 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
857 sizeof(u32) * dev->wiphy.n_cipher_suites,
858 dev->wiphy.cipher_suites))
859 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100860
David S. Miller9360ffd2012-03-29 04:41:26 -0400861 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
862 dev->wiphy.max_num_pmkids))
863 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530864
David S. Miller9360ffd2012-03-29 04:41:26 -0400865 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
866 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
867 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200868
David S. Miller9360ffd2012-03-29 04:41:26 -0400869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
870 dev->wiphy.available_antennas_tx) ||
871 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
872 dev->wiphy.available_antennas_rx))
873 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100874
David S. Miller9360ffd2012-03-29 04:41:26 -0400875 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
876 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
877 dev->wiphy.probe_resp_offload))
878 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200879
Bruno Randolf7f531e02010-12-16 11:30:22 +0900880 if ((dev->wiphy.available_antennas_tx ||
881 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900882 u32 tx_ant = 0, rx_ant = 0;
883 int res;
884 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
885 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
887 tx_ant) ||
888 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
889 rx_ant))
890 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900891 }
892 }
893
Johannes Berg7527a782011-05-13 10:58:57 +0200894 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
895 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700896 goto nla_put_failure;
897
Johannes Bergee688b002008-01-24 19:38:39 +0100898 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
899 if (!nl_bands)
900 goto nla_put_failure;
901
902 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
903 if (!dev->wiphy.bands[band])
904 continue;
905
906 nl_band = nla_nest_start(msg, band);
907 if (!nl_band)
908 goto nla_put_failure;
909
Johannes Bergd51626d2008-10-09 12:20:13 +0200910 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
912 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
913 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
914 &dev->wiphy.bands[band]->ht_cap.mcs) ||
915 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
916 dev->wiphy.bands[band]->ht_cap.cap) ||
917 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
918 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
919 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
920 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
921 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200922
Johannes Bergee688b002008-01-24 19:38:39 +0100923 /* add frequencies */
924 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
925 if (!nl_freqs)
926 goto nla_put_failure;
927
928 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
929 nl_freq = nla_nest_start(msg, i);
930 if (!nl_freq)
931 goto nla_put_failure;
932
933 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100934
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400935 if (nl80211_msg_put_channel(msg, chan))
936 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200937
Johannes Bergee688b002008-01-24 19:38:39 +0100938 nla_nest_end(msg, nl_freq);
939 }
940
941 nla_nest_end(msg, nl_freqs);
942
943 /* add bitrates */
944 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
945 if (!nl_rates)
946 goto nla_put_failure;
947
948 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
949 nl_rate = nla_nest_start(msg, i);
950 if (!nl_rate)
951 goto nla_put_failure;
952
953 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400954 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
955 rate->bitrate))
956 goto nla_put_failure;
957 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
958 nla_put_flag(msg,
959 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
960 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100961
962 nla_nest_end(msg, nl_rate);
963 }
964
965 nla_nest_end(msg, nl_rates);
966
967 nla_nest_end(msg, nl_band);
968 }
969 nla_nest_end(msg, nl_bands);
970
Johannes Berg8fdc6212009-03-14 09:34:01 +0100971 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
972 if (!nl_cmds)
973 goto nla_put_failure;
974
975 i = 0;
976#define CMD(op, n) \
977 do { \
978 if (dev->ops->op) { \
979 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
981 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100982 } \
983 } while (0)
984
985 CMD(add_virtual_intf, NEW_INTERFACE);
986 CMD(change_virtual_intf, SET_INTERFACE);
987 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100988 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100989 CMD(add_station, NEW_STATION);
990 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800991 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200993 CMD(auth, AUTHENTICATE);
994 CMD(assoc, ASSOCIATE);
995 CMD(deauth, DEAUTHENTICATE);
996 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200997 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100998 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100999 CMD(set_pmksa, SET_PMKSA);
1000 CMD(del_pmksa, DEL_PMKSA);
1001 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001002 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1003 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001004 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001005 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001006 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001007 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001008 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1010 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001011 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001012 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001013 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001014 i++;
1015 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1016 goto nla_put_failure;
1017 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001018 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001019 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1020 CMD(tdls_mgmt, TDLS_MGMT);
1021 CMD(tdls_oper, TDLS_OPER);
1022 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001023 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1024 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001025 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001026 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e7602302011-11-04 11:18:17 +01001027 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1028 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001029 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1030 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01001031 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001032
Kalle Valo4745fc02011-11-17 19:06:10 +02001033#ifdef CONFIG_NL80211_TESTMODE
1034 CMD(testmode_cmd, TESTMODE);
1035#endif
1036
Johannes Berg8fdc6212009-03-14 09:34:01 +01001037#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001038
Johannes Berg6829c872009-07-02 09:13:27 +02001039 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001041 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1042 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001043 }
1044
Johannes Berg6829c872009-07-02 09:13:27 +02001045 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001046 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001047 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1048 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001049 }
1050
Johannes Berg8fdc6212009-03-14 09:34:01 +01001051 nla_nest_end(msg, nl_cmds);
1052
Johannes Berg7c4ef712011-11-18 15:33:48 +01001053 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001054 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1055 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1056 dev->wiphy.max_remain_on_channel_duration))
1057 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001058
David S. Miller9360ffd2012-03-29 04:41:26 -04001059 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1060 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1061 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001062
Johannes Berg2e161f72010-08-12 15:38:38 +02001063 if (mgmt_stypes) {
1064 u16 stypes;
1065 struct nlattr *nl_ftypes, *nl_ifs;
1066 enum nl80211_iftype ift;
1067
1068 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1069 if (!nl_ifs)
1070 goto nla_put_failure;
1071
1072 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1073 nl_ftypes = nla_nest_start(msg, ift);
1074 if (!nl_ftypes)
1075 goto nla_put_failure;
1076 i = 0;
1077 stypes = mgmt_stypes[ift].tx;
1078 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001079 if ((stypes & 1) &&
1080 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1081 (i << 4) | IEEE80211_FTYPE_MGMT))
1082 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001083 stypes >>= 1;
1084 i++;
1085 }
1086 nla_nest_end(msg, nl_ftypes);
1087 }
1088
Johannes Berg74b70a42010-08-24 12:15:53 +02001089 nla_nest_end(msg, nl_ifs);
1090
Johannes Berg2e161f72010-08-12 15:38:38 +02001091 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1092 if (!nl_ifs)
1093 goto nla_put_failure;
1094
1095 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1096 nl_ftypes = nla_nest_start(msg, ift);
1097 if (!nl_ftypes)
1098 goto nla_put_failure;
1099 i = 0;
1100 stypes = mgmt_stypes[ift].rx;
1101 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001102 if ((stypes & 1) &&
1103 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1104 (i << 4) | IEEE80211_FTYPE_MGMT))
1105 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001106 stypes >>= 1;
1107 i++;
1108 }
1109 nla_nest_end(msg, nl_ftypes);
1110 }
1111 nla_nest_end(msg, nl_ifs);
1112 }
1113
Johannes Bergff1b6e62011-05-04 15:37:28 +02001114 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1115 struct nlattr *nl_wowlan;
1116
1117 nl_wowlan = nla_nest_start(msg,
1118 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1119 if (!nl_wowlan)
1120 goto nla_put_failure;
1121
David S. Miller9360ffd2012-03-29 04:41:26 -04001122 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1123 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1124 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1125 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1126 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1127 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1128 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1129 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1130 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1131 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1132 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1134 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1136 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1138 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001139 if (dev->wiphy.wowlan.n_patterns) {
1140 struct nl80211_wowlan_pattern_support pat = {
1141 .max_patterns = dev->wiphy.wowlan.n_patterns,
1142 .min_pattern_len =
1143 dev->wiphy.wowlan.pattern_min_len,
1144 .max_pattern_len =
1145 dev->wiphy.wowlan.pattern_max_len,
1146 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1148 sizeof(pat), &pat))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 }
1151
1152 nla_nest_end(msg, nl_wowlan);
1153 }
1154
Johannes Berg7527a782011-05-13 10:58:57 +02001155 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1156 dev->wiphy.software_iftypes))
1157 goto nla_put_failure;
1158
1159 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1160 goto nla_put_failure;
1161
David S. Miller9360ffd2012-03-29 04:41:26 -04001162 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1163 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1164 dev->wiphy.ap_sme_capa))
1165 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001166
David S. Miller9360ffd2012-03-29 04:41:26 -04001167 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1168 dev->wiphy.features))
1169 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001170
David S. Miller9360ffd2012-03-29 04:41:26 -04001171 if (dev->wiphy.ht_capa_mod_mask &&
1172 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1173 sizeof(*dev->wiphy.ht_capa_mod_mask),
1174 dev->wiphy.ht_capa_mod_mask))
1175 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001176
Johannes Berg55682962007-09-20 13:09:35 -04001177 return genlmsg_end(msg, hdr);
1178
1179 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001180 genlmsg_cancel(msg, hdr);
1181 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001182}
1183
1184static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1185{
1186 int idx = 0;
1187 int start = cb->args[0];
1188 struct cfg80211_registered_device *dev;
1189
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001190 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001191 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001192 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1193 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001194 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001195 continue;
1196 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1197 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001198 dev) < 0) {
1199 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001200 break;
Julius Volzb4637272008-07-08 14:02:19 +02001201 }
Johannes Berg55682962007-09-20 13:09:35 -04001202 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001203 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001204
1205 cb->args[0] = idx;
1206
1207 return skb->len;
1208}
1209
1210static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1211{
1212 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001213 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001214
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001215 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001216 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001217 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001218
Johannes Berg4c476992010-10-04 21:36:35 +02001219 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1220 nlmsg_free(msg);
1221 return -ENOBUFS;
1222 }
Johannes Berg55682962007-09-20 13:09:35 -04001223
Johannes Berg134e6372009-07-10 09:51:34 +00001224 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001225}
1226
Jouni Malinen31888482008-10-30 16:59:24 +02001227static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1228 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1229 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1230 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1231 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1232 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1233};
1234
1235static int parse_txq_params(struct nlattr *tb[],
1236 struct ieee80211_txq_params *txq_params)
1237{
Johannes Berga3304b02012-03-28 11:04:24 +02001238 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001239 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1240 !tb[NL80211_TXQ_ATTR_AIFS])
1241 return -EINVAL;
1242
Johannes Berga3304b02012-03-28 11:04:24 +02001243 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001244 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1245 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1246 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1247 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1248
Johannes Berga3304b02012-03-28 11:04:24 +02001249 if (txq_params->ac >= NL80211_NUM_ACS)
1250 return -EINVAL;
1251
Jouni Malinen31888482008-10-30 16:59:24 +02001252 return 0;
1253}
1254
Johannes Bergf444de02010-05-05 15:25:02 +02001255static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1256{
1257 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001258 * You can only set the channel explicitly for WDS interfaces,
1259 * all others have their channel managed via their respective
1260 * "establish a connection" command (connect, join, ...)
1261 *
1262 * For AP/GO and mesh mode, the channel can be set with the
1263 * channel userspace API, but is only stored and passed to the
1264 * low-level driver when the AP starts or the mesh is joined.
1265 * This is for backward compatibility, userspace can also give
1266 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001267 *
1268 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001269 * whatever else is going on, so they have their own special
1270 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001271 */
1272 return !wdev ||
1273 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001274 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001275 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1276 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001277}
1278
Johannes Bergcd6c6592012-05-10 21:27:18 +02001279static bool nl80211_valid_channel_type(struct genl_info *info,
1280 enum nl80211_channel_type *channel_type)
1281{
1282 enum nl80211_channel_type tmp;
1283
1284 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1285 return false;
1286
1287 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1288 if (tmp != NL80211_CHAN_NO_HT &&
1289 tmp != NL80211_CHAN_HT20 &&
1290 tmp != NL80211_CHAN_HT40PLUS &&
1291 tmp != NL80211_CHAN_HT40MINUS)
1292 return false;
1293
1294 if (channel_type)
1295 *channel_type = tmp;
1296
1297 return true;
1298}
1299
Johannes Bergf444de02010-05-05 15:25:02 +02001300static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1301 struct wireless_dev *wdev,
1302 struct genl_info *info)
1303{
Johannes Bergaa430da2012-05-16 23:50:18 +02001304 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001305 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1306 u32 freq;
1307 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001308 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1309
1310 if (wdev)
1311 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001312
1313 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1314 return -EINVAL;
1315
1316 if (!nl80211_can_set_dev_channel(wdev))
1317 return -EOPNOTSUPP;
1318
Johannes Bergcd6c6592012-05-10 21:27:18 +02001319 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1320 !nl80211_valid_channel_type(info, &channel_type))
1321 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001322
1323 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1324
1325 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001326 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001327 case NL80211_IFTYPE_AP:
1328 case NL80211_IFTYPE_P2P_GO:
1329 if (wdev->beacon_interval) {
1330 result = -EBUSY;
1331 break;
1332 }
1333 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1334 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1335 channel,
1336 channel_type)) {
1337 result = -EINVAL;
1338 break;
1339 }
1340 wdev->preset_chan = channel;
1341 wdev->preset_chantype = channel_type;
1342 result = 0;
1343 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001344 case NL80211_IFTYPE_MESH_POINT:
1345 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1346 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001347 case NL80211_IFTYPE_MONITOR:
1348 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1349 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001350 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001351 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001352 }
1353 mutex_unlock(&rdev->devlist_mtx);
1354
1355 return result;
1356}
1357
1358static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1359{
Johannes Berg4c476992010-10-04 21:36:35 +02001360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1361 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001362
Johannes Berg4c476992010-10-04 21:36:35 +02001363 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001364}
1365
Bill Jordane8347eb2010-10-01 13:54:28 -04001366static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1367{
Johannes Berg43b19952010-10-07 13:10:30 +02001368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1369 struct net_device *dev = info->user_ptr[1];
1370 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001371 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001372
1373 if (!info->attrs[NL80211_ATTR_MAC])
1374 return -EINVAL;
1375
Johannes Berg43b19952010-10-07 13:10:30 +02001376 if (netif_running(dev))
1377 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001378
Johannes Berg43b19952010-10-07 13:10:30 +02001379 if (!rdev->ops->set_wds_peer)
1380 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001381
Johannes Berg43b19952010-10-07 13:10:30 +02001382 if (wdev->iftype != NL80211_IFTYPE_WDS)
1383 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001386 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001387}
1388
1389
Johannes Berg55682962007-09-20 13:09:35 -04001390static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1391{
1392 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001393 struct net_device *netdev = NULL;
1394 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001395 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001396 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001397 u32 changed;
1398 u8 retry_short = 0, retry_long = 0;
1399 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001400 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001401
Johannes Bergf444de02010-05-05 15:25:02 +02001402 /*
1403 * Try to find the wiphy and netdev. Normally this
1404 * function shouldn't need the netdev, but this is
1405 * done for backward compatibility -- previously
1406 * setting the channel was done per wiphy, but now
1407 * it is per netdev. Previous userland like hostapd
1408 * also passed a netdev to set_wiphy, so that it is
1409 * possible to let that go to the right netdev!
1410 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001411 mutex_lock(&cfg80211_mutex);
1412
Johannes Bergf444de02010-05-05 15:25:02 +02001413 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1414 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1415
1416 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1417 if (netdev && netdev->ieee80211_ptr) {
1418 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1419 mutex_lock(&rdev->mtx);
1420 } else
1421 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001422 }
1423
Johannes Bergf444de02010-05-05 15:25:02 +02001424 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001425 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1426 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001427 if (IS_ERR(rdev)) {
1428 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001429 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001430 }
1431 wdev = NULL;
1432 netdev = NULL;
1433 result = 0;
1434
1435 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001436 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001437 wdev = netdev->ieee80211_ptr;
1438 else
1439 wdev = NULL;
1440
1441 /*
1442 * end workaround code, by now the rdev is available
1443 * and locked, and wdev may or may not be NULL.
1444 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001445
1446 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001447 result = cfg80211_dev_rename(
1448 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001449
1450 mutex_unlock(&cfg80211_mutex);
1451
1452 if (result)
1453 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001454
Jouni Malinen31888482008-10-30 16:59:24 +02001455 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1456 struct ieee80211_txq_params txq_params;
1457 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1458
1459 if (!rdev->ops->set_txq_params) {
1460 result = -EOPNOTSUPP;
1461 goto bad_res;
1462 }
1463
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001464 if (!netdev) {
1465 result = -EINVAL;
1466 goto bad_res;
1467 }
1468
Johannes Berg133a3ff2011-11-03 14:50:13 +01001469 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1470 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1471 result = -EINVAL;
1472 goto bad_res;
1473 }
1474
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001475 if (!netif_running(netdev)) {
1476 result = -ENETDOWN;
1477 goto bad_res;
1478 }
1479
Jouni Malinen31888482008-10-30 16:59:24 +02001480 nla_for_each_nested(nl_txq_params,
1481 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1482 rem_txq_params) {
1483 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1484 nla_data(nl_txq_params),
1485 nla_len(nl_txq_params),
1486 txq_params_policy);
1487 result = parse_txq_params(tb, &txq_params);
1488 if (result)
1489 goto bad_res;
1490
1491 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001492 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001493 &txq_params);
1494 if (result)
1495 goto bad_res;
1496 }
1497 }
1498
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001499 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001500 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001501 if (result)
1502 goto bad_res;
1503 }
1504
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001505 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1506 enum nl80211_tx_power_setting type;
1507 int idx, mbm = 0;
1508
1509 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001510 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001511 goto bad_res;
1512 }
1513
1514 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1515 type = nla_get_u32(info->attrs[idx]);
1516
1517 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1518 (type != NL80211_TX_POWER_AUTOMATIC)) {
1519 result = -EINVAL;
1520 goto bad_res;
1521 }
1522
1523 if (type != NL80211_TX_POWER_AUTOMATIC) {
1524 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1525 mbm = nla_get_u32(info->attrs[idx]);
1526 }
1527
1528 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1529 if (result)
1530 goto bad_res;
1531 }
1532
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001533 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1534 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1535 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001536 if ((!rdev->wiphy.available_antennas_tx &&
1537 !rdev->wiphy.available_antennas_rx) ||
1538 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001539 result = -EOPNOTSUPP;
1540 goto bad_res;
1541 }
1542
1543 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1544 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1545
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001546 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001547 * available antenna masks, except for the "all" mask */
1548 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1549 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001550 result = -EINVAL;
1551 goto bad_res;
1552 }
1553
Bruno Randolf7f531e02010-12-16 11:30:22 +09001554 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1555 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001556
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001557 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1558 if (result)
1559 goto bad_res;
1560 }
1561
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001562 changed = 0;
1563
1564 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1565 retry_short = nla_get_u8(
1566 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1567 if (retry_short == 0) {
1568 result = -EINVAL;
1569 goto bad_res;
1570 }
1571 changed |= WIPHY_PARAM_RETRY_SHORT;
1572 }
1573
1574 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1575 retry_long = nla_get_u8(
1576 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1577 if (retry_long == 0) {
1578 result = -EINVAL;
1579 goto bad_res;
1580 }
1581 changed |= WIPHY_PARAM_RETRY_LONG;
1582 }
1583
1584 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1585 frag_threshold = nla_get_u32(
1586 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1587 if (frag_threshold < 256) {
1588 result = -EINVAL;
1589 goto bad_res;
1590 }
1591 if (frag_threshold != (u32) -1) {
1592 /*
1593 * Fragments (apart from the last one) are required to
1594 * have even length. Make the fragmentation code
1595 * simpler by stripping LSB should someone try to use
1596 * odd threshold value.
1597 */
1598 frag_threshold &= ~0x1;
1599 }
1600 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1601 }
1602
1603 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1604 rts_threshold = nla_get_u32(
1605 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1606 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1607 }
1608
Lukáš Turek81077e82009-12-21 22:50:47 +01001609 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1610 coverage_class = nla_get_u8(
1611 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1612 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1613 }
1614
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001615 if (changed) {
1616 u8 old_retry_short, old_retry_long;
1617 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001618 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001619
1620 if (!rdev->ops->set_wiphy_params) {
1621 result = -EOPNOTSUPP;
1622 goto bad_res;
1623 }
1624
1625 old_retry_short = rdev->wiphy.retry_short;
1626 old_retry_long = rdev->wiphy.retry_long;
1627 old_frag_threshold = rdev->wiphy.frag_threshold;
1628 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001629 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001630
1631 if (changed & WIPHY_PARAM_RETRY_SHORT)
1632 rdev->wiphy.retry_short = retry_short;
1633 if (changed & WIPHY_PARAM_RETRY_LONG)
1634 rdev->wiphy.retry_long = retry_long;
1635 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1636 rdev->wiphy.frag_threshold = frag_threshold;
1637 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1638 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001639 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1640 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001641
1642 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1643 if (result) {
1644 rdev->wiphy.retry_short = old_retry_short;
1645 rdev->wiphy.retry_long = old_retry_long;
1646 rdev->wiphy.frag_threshold = old_frag_threshold;
1647 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001648 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001649 }
1650 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001651
Johannes Berg306d6112008-12-08 12:39:04 +01001652 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001653 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001654 if (netdev)
1655 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001656 return result;
1657}
1658
1659
1660static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001661 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001662 struct net_device *dev)
1663{
1664 void *hdr;
1665
1666 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1667 if (!hdr)
1668 return -1;
1669
David S. Miller9360ffd2012-03-29 04:41:26 -04001670 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1671 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1672 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1673 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1674 dev->ieee80211_ptr->iftype) ||
1675 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1676 rdev->devlist_generation ^
1677 (cfg80211_rdev_list_generation << 2)))
1678 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001679
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001680 if (rdev->ops->get_channel) {
1681 struct ieee80211_channel *chan;
1682 enum nl80211_channel_type channel_type;
1683
1684 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001685 if (chan &&
1686 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1687 chan->center_freq) ||
1688 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1689 channel_type)))
1690 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001691 }
1692
Johannes Berg55682962007-09-20 13:09:35 -04001693 return genlmsg_end(msg, hdr);
1694
1695 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001696 genlmsg_cancel(msg, hdr);
1697 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001698}
1699
1700static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1701{
1702 int wp_idx = 0;
1703 int if_idx = 0;
1704 int wp_start = cb->args[0];
1705 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001706 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001707 struct wireless_dev *wdev;
1708
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001709 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001710 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1711 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001712 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001713 if (wp_idx < wp_start) {
1714 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001715 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001716 }
Johannes Berg55682962007-09-20 13:09:35 -04001717 if_idx = 0;
1718
Johannes Bergf5ea9122009-08-07 16:17:38 +02001719 mutex_lock(&rdev->devlist_mtx);
1720 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001721 if (if_idx < if_start) {
1722 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001723 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001724 }
Johannes Berg55682962007-09-20 13:09:35 -04001725 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001727 rdev, wdev->netdev) < 0) {
1728 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001729 goto out;
1730 }
1731 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001732 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001733 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001734
1735 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001736 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001737 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001738 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001739
1740 cb->args[0] = wp_idx;
1741 cb->args[1] = if_idx;
1742
1743 return skb->len;
1744}
1745
1746static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1747{
1748 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001749 struct cfg80211_registered_device *dev = info->user_ptr[0];
1750 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001751
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001753 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001754 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001755
Johannes Bergd7264052009-04-19 16:23:20 +02001756 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001757 dev, netdev) < 0) {
1758 nlmsg_free(msg);
1759 return -ENOBUFS;
1760 }
Johannes Berg55682962007-09-20 13:09:35 -04001761
Johannes Berg134e6372009-07-10 09:51:34 +00001762 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001763}
1764
Michael Wu66f7ac52008-01-31 19:48:22 +01001765static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1766 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1767 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1768 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1769 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1770 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1771};
1772
1773static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1774{
1775 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1776 int flag;
1777
1778 *mntrflags = 0;
1779
1780 if (!nla)
1781 return -EINVAL;
1782
1783 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1784 nla, mntr_flags_policy))
1785 return -EINVAL;
1786
1787 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1788 if (flags[flag])
1789 *mntrflags |= (1<<flag);
1790
1791 return 0;
1792}
1793
Johannes Berg9bc383d2009-11-19 11:55:19 +01001794static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001795 struct net_device *netdev, u8 use_4addr,
1796 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001797{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001798 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001799 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001800 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001801 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001802 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001803
1804 switch (iftype) {
1805 case NL80211_IFTYPE_AP_VLAN:
1806 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1807 return 0;
1808 break;
1809 case NL80211_IFTYPE_STATION:
1810 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1811 return 0;
1812 break;
1813 default:
1814 break;
1815 }
1816
1817 return -EOPNOTSUPP;
1818}
1819
Johannes Berg55682962007-09-20 13:09:35 -04001820static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1821{
Johannes Berg4c476992010-10-04 21:36:35 +02001822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001823 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001824 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001825 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001826 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001827 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001828 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001829
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001830 memset(&params, 0, sizeof(params));
1831
Johannes Berg04a773a2009-04-19 21:24:32 +02001832 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001833
Johannes Berg723b0382008-09-16 20:22:09 +02001834 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001835 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001836 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001837 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001838 if (ntype > NL80211_IFTYPE_MAX)
1839 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001840 }
1841
Johannes Berg92ffe052008-09-16 20:39:36 +02001842 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001843 struct wireless_dev *wdev = dev->ieee80211_ptr;
1844
Johannes Berg4c476992010-10-04 21:36:35 +02001845 if (ntype != NL80211_IFTYPE_MESH_POINT)
1846 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001847 if (netif_running(dev))
1848 return -EBUSY;
1849
1850 wdev_lock(wdev);
1851 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1852 IEEE80211_MAX_MESH_ID_LEN);
1853 wdev->mesh_id_up_len =
1854 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1855 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1856 wdev->mesh_id_up_len);
1857 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001858 }
1859
Felix Fietkau8b787642009-11-10 18:53:10 +01001860 if (info->attrs[NL80211_ATTR_4ADDR]) {
1861 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1862 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001863 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001864 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001865 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001866 } else {
1867 params.use_4addr = -1;
1868 }
1869
Johannes Berg92ffe052008-09-16 20:39:36 +02001870 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001871 if (ntype != NL80211_IFTYPE_MONITOR)
1872 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001873 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1874 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001875 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001876 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001877
1878 flags = &_flags;
1879 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001880 }
Johannes Berg3b858752009-03-12 09:55:09 +01001881
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001882 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001883 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001884 else
1885 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001886
Johannes Berg9bc383d2009-11-19 11:55:19 +01001887 if (!err && params.use_4addr != -1)
1888 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1889
Johannes Berg55682962007-09-20 13:09:35 -04001890 return err;
1891}
1892
1893static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1894{
Johannes Berg4c476992010-10-04 21:36:35 +02001895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001896 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001897 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001898 int err;
1899 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001900 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001901
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001902 memset(&params, 0, sizeof(params));
1903
Johannes Berg55682962007-09-20 13:09:35 -04001904 if (!info->attrs[NL80211_ATTR_IFNAME])
1905 return -EINVAL;
1906
1907 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1908 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1909 if (type > NL80211_IFTYPE_MAX)
1910 return -EINVAL;
1911 }
1912
Johannes Berg79c97e92009-07-07 03:56:12 +02001913 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001914 !(rdev->wiphy.interface_modes & (1 << type)))
1915 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001916
Johannes Berg9bc383d2009-11-19 11:55:19 +01001917 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001918 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001919 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001920 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001921 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001922 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001923
Michael Wu66f7ac52008-01-31 19:48:22 +01001924 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1925 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1926 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001927 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001928 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001929 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001930 if (IS_ERR(dev))
1931 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001932
Johannes Berg29cbe682010-12-03 09:20:44 +01001933 if (type == NL80211_IFTYPE_MESH_POINT &&
1934 info->attrs[NL80211_ATTR_MESH_ID]) {
1935 struct wireless_dev *wdev = dev->ieee80211_ptr;
1936
1937 wdev_lock(wdev);
1938 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1939 IEEE80211_MAX_MESH_ID_LEN);
1940 wdev->mesh_id_up_len =
1941 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1942 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1943 wdev->mesh_id_up_len);
1944 wdev_unlock(wdev);
1945 }
1946
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001947 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001948}
1949
1950static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1951{
Johannes Berg4c476992010-10-04 21:36:35 +02001952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1953 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001954
Johannes Berg4c476992010-10-04 21:36:35 +02001955 if (!rdev->ops->del_virtual_intf)
1956 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001957
Johannes Berg4c476992010-10-04 21:36:35 +02001958 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001959}
1960
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001961static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1962{
1963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1964 struct net_device *dev = info->user_ptr[1];
1965 u16 noack_map;
1966
1967 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1968 return -EINVAL;
1969
1970 if (!rdev->ops->set_noack_map)
1971 return -EOPNOTSUPP;
1972
1973 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1974
1975 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1976}
1977
Johannes Berg41ade002007-12-19 02:03:29 +01001978struct get_key_cookie {
1979 struct sk_buff *msg;
1980 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001981 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001982};
1983
1984static void get_key_callback(void *c, struct key_params *params)
1985{
Johannes Bergb9454e82009-07-08 13:29:08 +02001986 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001987 struct get_key_cookie *cookie = c;
1988
David S. Miller9360ffd2012-03-29 04:41:26 -04001989 if ((params->key &&
1990 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1991 params->key_len, params->key)) ||
1992 (params->seq &&
1993 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
1994 params->seq_len, params->seq)) ||
1995 (params->cipher &&
1996 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1997 params->cipher)))
1998 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01001999
Johannes Bergb9454e82009-07-08 13:29:08 +02002000 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2001 if (!key)
2002 goto nla_put_failure;
2003
David S. Miller9360ffd2012-03-29 04:41:26 -04002004 if ((params->key &&
2005 nla_put(cookie->msg, NL80211_KEY_DATA,
2006 params->key_len, params->key)) ||
2007 (params->seq &&
2008 nla_put(cookie->msg, NL80211_KEY_SEQ,
2009 params->seq_len, params->seq)) ||
2010 (params->cipher &&
2011 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2012 params->cipher)))
2013 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002014
David S. Miller9360ffd2012-03-29 04:41:26 -04002015 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2016 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002017
2018 nla_nest_end(cookie->msg, key);
2019
Johannes Berg41ade002007-12-19 02:03:29 +01002020 return;
2021 nla_put_failure:
2022 cookie->error = 1;
2023}
2024
2025static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2026{
Johannes Berg4c476992010-10-04 21:36:35 +02002027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002028 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002029 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002030 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002031 const u8 *mac_addr = NULL;
2032 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002033 struct get_key_cookie cookie = {
2034 .error = 0,
2035 };
2036 void *hdr;
2037 struct sk_buff *msg;
2038
2039 if (info->attrs[NL80211_ATTR_KEY_IDX])
2040 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2041
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002042 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002043 return -EINVAL;
2044
2045 if (info->attrs[NL80211_ATTR_MAC])
2046 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2047
Johannes Berge31b8212010-10-05 19:39:30 +02002048 pairwise = !!mac_addr;
2049 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2050 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2051 if (kt >= NUM_NL80211_KEYTYPES)
2052 return -EINVAL;
2053 if (kt != NL80211_KEYTYPE_GROUP &&
2054 kt != NL80211_KEYTYPE_PAIRWISE)
2055 return -EINVAL;
2056 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2057 }
2058
Johannes Berg4c476992010-10-04 21:36:35 +02002059 if (!rdev->ops->get_key)
2060 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002061
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002062 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002063 if (!msg)
2064 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002065
2066 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2067 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002068 if (IS_ERR(hdr))
2069 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002070
2071 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002072 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002073
David S. Miller9360ffd2012-03-29 04:41:26 -04002074 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2075 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2076 goto nla_put_failure;
2077 if (mac_addr &&
2078 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2079 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002080
Johannes Berge31b8212010-10-05 19:39:30 +02002081 if (pairwise && mac_addr &&
2082 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2083 return -ENOENT;
2084
2085 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2086 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002087
2088 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002089 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002090
2091 if (cookie.error)
2092 goto nla_put_failure;
2093
2094 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002095 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002096
2097 nla_put_failure:
2098 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002099 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002100 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002101 return err;
2102}
2103
2104static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2105{
Johannes Berg4c476992010-10-04 21:36:35 +02002106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002107 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002108 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002109 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002110
Johannes Bergb9454e82009-07-08 13:29:08 +02002111 err = nl80211_parse_key(info, &key);
2112 if (err)
2113 return err;
2114
2115 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002116 return -EINVAL;
2117
Johannes Bergb9454e82009-07-08 13:29:08 +02002118 /* only support setting default key */
2119 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002120 return -EINVAL;
2121
Johannes Bergfffd0932009-07-08 14:22:54 +02002122 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002123
2124 if (key.def) {
2125 if (!rdev->ops->set_default_key) {
2126 err = -EOPNOTSUPP;
2127 goto out;
2128 }
2129
2130 err = nl80211_key_allowed(dev->ieee80211_ptr);
2131 if (err)
2132 goto out;
2133
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002134 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2135 key.def_uni, key.def_multi);
2136
2137 if (err)
2138 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002139
Johannes Berg3d23e342009-09-29 23:27:28 +02002140#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002141 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002142#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002143 } else {
2144 if (key.def_uni || !key.def_multi) {
2145 err = -EINVAL;
2146 goto out;
2147 }
2148
2149 if (!rdev->ops->set_default_mgmt_key) {
2150 err = -EOPNOTSUPP;
2151 goto out;
2152 }
2153
2154 err = nl80211_key_allowed(dev->ieee80211_ptr);
2155 if (err)
2156 goto out;
2157
2158 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2159 dev, key.idx);
2160 if (err)
2161 goto out;
2162
2163#ifdef CONFIG_CFG80211_WEXT
2164 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2165#endif
2166 }
2167
2168 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002169 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002170
Johannes Berg41ade002007-12-19 02:03:29 +01002171 return err;
2172}
2173
2174static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2175{
Johannes Berg4c476992010-10-04 21:36:35 +02002176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002177 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002178 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002179 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002180 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002181
Johannes Bergb9454e82009-07-08 13:29:08 +02002182 err = nl80211_parse_key(info, &key);
2183 if (err)
2184 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002185
Johannes Bergb9454e82009-07-08 13:29:08 +02002186 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002187 return -EINVAL;
2188
Johannes Berg41ade002007-12-19 02:03:29 +01002189 if (info->attrs[NL80211_ATTR_MAC])
2190 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2191
Johannes Berge31b8212010-10-05 19:39:30 +02002192 if (key.type == -1) {
2193 if (mac_addr)
2194 key.type = NL80211_KEYTYPE_PAIRWISE;
2195 else
2196 key.type = NL80211_KEYTYPE_GROUP;
2197 }
2198
2199 /* for now */
2200 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2201 key.type != NL80211_KEYTYPE_GROUP)
2202 return -EINVAL;
2203
Johannes Berg4c476992010-10-04 21:36:35 +02002204 if (!rdev->ops->add_key)
2205 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002206
Johannes Berge31b8212010-10-05 19:39:30 +02002207 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2208 key.type == NL80211_KEYTYPE_PAIRWISE,
2209 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002210 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002211
2212 wdev_lock(dev->ieee80211_ptr);
2213 err = nl80211_key_allowed(dev->ieee80211_ptr);
2214 if (!err)
2215 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002216 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002217 mac_addr, &key.p);
2218 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002219
Johannes Berg41ade002007-12-19 02:03:29 +01002220 return err;
2221}
2222
2223static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2224{
Johannes Berg4c476992010-10-04 21:36:35 +02002225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002226 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002227 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002228 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002229 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002230
Johannes Bergb9454e82009-07-08 13:29:08 +02002231 err = nl80211_parse_key(info, &key);
2232 if (err)
2233 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002234
2235 if (info->attrs[NL80211_ATTR_MAC])
2236 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2237
Johannes Berge31b8212010-10-05 19:39:30 +02002238 if (key.type == -1) {
2239 if (mac_addr)
2240 key.type = NL80211_KEYTYPE_PAIRWISE;
2241 else
2242 key.type = NL80211_KEYTYPE_GROUP;
2243 }
2244
2245 /* for now */
2246 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2247 key.type != NL80211_KEYTYPE_GROUP)
2248 return -EINVAL;
2249
Johannes Berg4c476992010-10-04 21:36:35 +02002250 if (!rdev->ops->del_key)
2251 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002252
Johannes Bergfffd0932009-07-08 14:22:54 +02002253 wdev_lock(dev->ieee80211_ptr);
2254 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002255
2256 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2257 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2258 err = -ENOENT;
2259
Johannes Bergfffd0932009-07-08 14:22:54 +02002260 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002261 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2262 key.type == NL80211_KEYTYPE_PAIRWISE,
2263 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002264
Johannes Berg3d23e342009-09-29 23:27:28 +02002265#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002266 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002267 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002268 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002269 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002270 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2271 }
2272#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002273 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002274
Johannes Berg41ade002007-12-19 02:03:29 +01002275 return err;
2276}
2277
Johannes Berg88600202012-02-13 15:17:18 +01002278static int nl80211_parse_beacon(struct genl_info *info,
2279 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002280{
Johannes Berg88600202012-02-13 15:17:18 +01002281 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002282
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002283 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2284 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2285 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2286 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002287 return -EINVAL;
2288
Johannes Berg88600202012-02-13 15:17:18 +01002289 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002290
Johannes Berged1b6cc2007-12-19 02:03:32 +01002291 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002292 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2293 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2294 if (!bcn->head_len)
2295 return -EINVAL;
2296 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002297 }
2298
2299 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002300 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2301 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002302 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002303 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002304 }
2305
Johannes Berg4c476992010-10-04 21:36:35 +02002306 if (!haveinfo)
2307 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002308
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002309 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002310 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2311 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002312 }
2313
2314 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002315 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002316 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002317 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002318 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2319 }
2320
2321 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002323 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002324 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002325 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2326 }
2327
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002328 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002330 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002331 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002332 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2333 }
2334
Johannes Berg88600202012-02-13 15:17:18 +01002335 return 0;
2336}
2337
2338static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2339{
2340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2341 struct net_device *dev = info->user_ptr[1];
2342 struct wireless_dev *wdev = dev->ieee80211_ptr;
2343 struct cfg80211_ap_settings params;
2344 int err;
2345
2346 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2347 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2348 return -EOPNOTSUPP;
2349
2350 if (!rdev->ops->start_ap)
2351 return -EOPNOTSUPP;
2352
2353 if (wdev->beacon_interval)
2354 return -EALREADY;
2355
2356 memset(&params, 0, sizeof(params));
2357
2358 /* these are required for START_AP */
2359 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2360 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2361 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2362 return -EINVAL;
2363
2364 err = nl80211_parse_beacon(info, &params.beacon);
2365 if (err)
2366 return err;
2367
2368 params.beacon_interval =
2369 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2370 params.dtim_period =
2371 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2372
2373 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2374 if (err)
2375 return err;
2376
2377 /*
2378 * In theory, some of these attributes should be required here
2379 * but since they were not used when the command was originally
2380 * added, keep them optional for old user space programs to let
2381 * them continue to work with drivers that do not need the
2382 * additional information -- drivers must check!
2383 */
2384 if (info->attrs[NL80211_ATTR_SSID]) {
2385 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2386 params.ssid_len =
2387 nla_len(info->attrs[NL80211_ATTR_SSID]);
2388 if (params.ssid_len == 0 ||
2389 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2390 return -EINVAL;
2391 }
2392
2393 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2394 params.hidden_ssid = nla_get_u32(
2395 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2396 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2397 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2398 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2399 return -EINVAL;
2400 }
2401
2402 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2403
2404 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2405 params.auth_type = nla_get_u32(
2406 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2407 if (!nl80211_valid_auth_type(params.auth_type))
2408 return -EINVAL;
2409 } else
2410 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2411
2412 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2413 NL80211_MAX_NR_CIPHER_SUITES);
2414 if (err)
2415 return err;
2416
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302417 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2418 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2419 return -EOPNOTSUPP;
2420 params.inactivity_timeout = nla_get_u16(
2421 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2422 }
2423
Johannes Bergaa430da2012-05-16 23:50:18 +02002424 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2425 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2426
2427 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2428 !nl80211_valid_channel_type(info, &channel_type))
2429 return -EINVAL;
2430
2431 params.channel = rdev_freq_to_chan(rdev,
2432 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2433 channel_type);
2434 if (!params.channel)
2435 return -EINVAL;
2436 params.channel_type = channel_type;
2437 } else if (wdev->preset_chan) {
2438 params.channel = wdev->preset_chan;
2439 params.channel_type = wdev->preset_chantype;
2440 } else
2441 return -EINVAL;
2442
2443 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2444 params.channel_type))
2445 return -EINVAL;
2446
Johannes Berg88600202012-02-13 15:17:18 +01002447 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2448 if (!err)
2449 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002450 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002451}
2452
Johannes Berg88600202012-02-13 15:17:18 +01002453static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2454{
2455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2456 struct net_device *dev = info->user_ptr[1];
2457 struct wireless_dev *wdev = dev->ieee80211_ptr;
2458 struct cfg80211_beacon_data params;
2459 int err;
2460
2461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2462 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2463 return -EOPNOTSUPP;
2464
2465 if (!rdev->ops->change_beacon)
2466 return -EOPNOTSUPP;
2467
2468 if (!wdev->beacon_interval)
2469 return -EINVAL;
2470
2471 err = nl80211_parse_beacon(info, &params);
2472 if (err)
2473 return err;
2474
2475 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2476}
2477
2478static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002479{
Johannes Berg4c476992010-10-04 21:36:35 +02002480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2481 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002482 struct wireless_dev *wdev = dev->ieee80211_ptr;
2483 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002484
Johannes Berg88600202012-02-13 15:17:18 +01002485 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002486 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002487
Johannes Berg074ac8d2010-09-16 14:58:22 +02002488 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002489 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2490 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002491
Johannes Berg88600202012-02-13 15:17:18 +01002492 if (!wdev->beacon_interval)
2493 return -ENOENT;
2494
2495 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002496 if (!err)
2497 wdev->beacon_interval = 0;
2498 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002499}
2500
Johannes Berg5727ef12007-12-19 02:03:34 +01002501static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2502 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2503 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2504 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002505 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002506 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002507 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002508};
2509
Johannes Bergeccb8e82009-05-11 21:57:56 +03002510static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002511 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002512 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002513{
2514 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002515 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002516 int flag;
2517
Johannes Bergeccb8e82009-05-11 21:57:56 +03002518 /*
2519 * Try parsing the new attribute first so userspace
2520 * can specify both for older kernels.
2521 */
2522 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2523 if (nla) {
2524 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002525
Johannes Bergeccb8e82009-05-11 21:57:56 +03002526 sta_flags = nla_data(nla);
2527 params->sta_flags_mask = sta_flags->mask;
2528 params->sta_flags_set = sta_flags->set;
2529 if ((params->sta_flags_mask |
2530 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2531 return -EINVAL;
2532 return 0;
2533 }
2534
2535 /* if present, parse the old attribute */
2536
2537 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002538 if (!nla)
2539 return 0;
2540
2541 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2542 nla, sta_flags_policy))
2543 return -EINVAL;
2544
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002545 /*
2546 * Only allow certain flags for interface types so that
2547 * other attributes are silently ignored. Remember that
2548 * this is backward compatibility code with old userspace
2549 * and shouldn't be hit in other cases anyway.
2550 */
2551 switch (iftype) {
2552 case NL80211_IFTYPE_AP:
2553 case NL80211_IFTYPE_AP_VLAN:
2554 case NL80211_IFTYPE_P2P_GO:
2555 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2556 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2557 BIT(NL80211_STA_FLAG_WME) |
2558 BIT(NL80211_STA_FLAG_MFP);
2559 break;
2560 case NL80211_IFTYPE_P2P_CLIENT:
2561 case NL80211_IFTYPE_STATION:
2562 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2563 BIT(NL80211_STA_FLAG_TDLS_PEER);
2564 break;
2565 case NL80211_IFTYPE_MESH_POINT:
2566 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2567 BIT(NL80211_STA_FLAG_MFP) |
2568 BIT(NL80211_STA_FLAG_AUTHORIZED);
2569 default:
2570 return -EINVAL;
2571 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002572
Johannes Berg3383b5a2012-05-10 20:14:43 +02002573 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2574 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002575 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002576
Johannes Berg3383b5a2012-05-10 20:14:43 +02002577 /* no longer support new API additions in old API */
2578 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2579 return -EINVAL;
2580 }
2581 }
2582
Johannes Berg5727ef12007-12-19 02:03:34 +01002583 return 0;
2584}
2585
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002586static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2587 int attr)
2588{
2589 struct nlattr *rate;
2590 u16 bitrate;
2591
2592 rate = nla_nest_start(msg, attr);
2593 if (!rate)
2594 goto nla_put_failure;
2595
2596 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2597 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002598 if ((bitrate > 0 &&
2599 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2600 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2601 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2602 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2603 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2604 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2605 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2606 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002607
2608 nla_nest_end(msg, rate);
2609 return true;
2610
2611nla_put_failure:
2612 return false;
2613}
2614
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002615static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002616 int flags,
2617 struct cfg80211_registered_device *rdev,
2618 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002619 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002620{
2621 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002622 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002623
2624 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2625 if (!hdr)
2626 return -1;
2627
David S. Miller9360ffd2012-03-29 04:41:26 -04002628 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2629 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2630 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2631 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002632
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002633 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2634 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002635 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002636 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2637 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2638 sinfo->connected_time))
2639 goto nla_put_failure;
2640 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2641 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2642 sinfo->inactive_time))
2643 goto nla_put_failure;
2644 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2645 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2646 sinfo->rx_bytes))
2647 goto nla_put_failure;
2648 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2649 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2650 sinfo->tx_bytes))
2651 goto nla_put_failure;
2652 if ((sinfo->filled & STATION_INFO_LLID) &&
2653 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2654 goto nla_put_failure;
2655 if ((sinfo->filled & STATION_INFO_PLID) &&
2656 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2657 goto nla_put_failure;
2658 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2659 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2660 sinfo->plink_state))
2661 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002662 switch (rdev->wiphy.signal_type) {
2663 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2665 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2666 sinfo->signal))
2667 goto nla_put_failure;
2668 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2669 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2670 sinfo->signal_avg))
2671 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002672 break;
2673 default:
2674 break;
2675 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002676 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002677 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2678 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002679 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002680 }
2681 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2682 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2683 NL80211_STA_INFO_RX_BITRATE))
2684 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002685 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002686 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2687 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2688 sinfo->rx_packets))
2689 goto nla_put_failure;
2690 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2691 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2692 sinfo->tx_packets))
2693 goto nla_put_failure;
2694 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2695 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2696 sinfo->tx_retries))
2697 goto nla_put_failure;
2698 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2699 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2700 sinfo->tx_failed))
2701 goto nla_put_failure;
2702 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2703 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2704 sinfo->beacon_loss_count))
2705 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002706 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2707 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2708 if (!bss_param)
2709 goto nla_put_failure;
2710
David S. Miller9360ffd2012-03-29 04:41:26 -04002711 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2712 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2713 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2714 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2715 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2716 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2717 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2718 sinfo->bss_param.dtim_period) ||
2719 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2720 sinfo->bss_param.beacon_interval))
2721 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002722
2723 nla_nest_end(msg, bss_param);
2724 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002725 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2726 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2727 sizeof(struct nl80211_sta_flag_update),
2728 &sinfo->sta_flags))
2729 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002730 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2731 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2732 sinfo->t_offset))
2733 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002734 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002735
David S. Miller9360ffd2012-03-29 04:41:26 -04002736 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2737 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2738 sinfo->assoc_req_ies))
2739 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002740
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002741 return genlmsg_end(msg, hdr);
2742
2743 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002744 genlmsg_cancel(msg, hdr);
2745 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002746}
2747
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002748static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002749 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002750{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002751 struct station_info sinfo;
2752 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002753 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002754 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002755 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002756 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002757
Johannes Berg67748892010-10-04 21:14:06 +02002758 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2759 if (err)
2760 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002761
2762 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002763 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002764 goto out_err;
2765 }
2766
Johannes Bergbba95fe2008-07-29 13:22:51 +02002767 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002768 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002769 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2770 mac_addr, &sinfo);
2771 if (err == -ENOENT)
2772 break;
2773 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002774 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002775
2776 if (nl80211_send_station(skb,
2777 NETLINK_CB(cb->skb).pid,
2778 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002779 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002780 &sinfo) < 0)
2781 goto out;
2782
2783 sta_idx++;
2784 }
2785
2786
2787 out:
2788 cb->args[1] = sta_idx;
2789 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002790 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002791 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002792
2793 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002794}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002795
Johannes Berg5727ef12007-12-19 02:03:34 +01002796static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2797{
Johannes Berg4c476992010-10-04 21:36:35 +02002798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2799 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002800 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002801 struct sk_buff *msg;
2802 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002803 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002804
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002805 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002806
2807 if (!info->attrs[NL80211_ATTR_MAC])
2808 return -EINVAL;
2809
2810 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2811
Johannes Berg4c476992010-10-04 21:36:35 +02002812 if (!rdev->ops->get_station)
2813 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002814
Johannes Berg79c97e92009-07-07 03:56:12 +02002815 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002817 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002818
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002820 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002821 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002822
2823 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002824 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002825 nlmsg_free(msg);
2826 return -ENOBUFS;
2827 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002828
Johannes Berg4c476992010-10-04 21:36:35 +02002829 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002830}
2831
2832/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002833 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002834 */
Johannes Berg80b99892011-11-18 16:23:01 +01002835static struct net_device *get_vlan(struct genl_info *info,
2836 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002837{
Johannes Berg463d0182009-07-14 00:33:35 +02002838 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002839 struct net_device *v;
2840 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002841
Johannes Berg80b99892011-11-18 16:23:01 +01002842 if (!vlanattr)
2843 return NULL;
2844
2845 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2846 if (!v)
2847 return ERR_PTR(-ENODEV);
2848
2849 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2850 ret = -EINVAL;
2851 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002852 }
Johannes Berg80b99892011-11-18 16:23:01 +01002853
2854 if (!netif_running(v)) {
2855 ret = -ENETDOWN;
2856 goto error;
2857 }
2858
2859 return v;
2860 error:
2861 dev_put(v);
2862 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002863}
2864
2865static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2866{
Johannes Berg4c476992010-10-04 21:36:35 +02002867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002868 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002869 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002870 struct station_parameters params;
2871 u8 *mac_addr = NULL;
2872
2873 memset(&params, 0, sizeof(params));
2874
2875 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002876 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002877
2878 if (info->attrs[NL80211_ATTR_STA_AID])
2879 return -EINVAL;
2880
2881 if (!info->attrs[NL80211_ATTR_MAC])
2882 return -EINVAL;
2883
2884 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2885
2886 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2887 params.supported_rates =
2888 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2889 params.supported_rates_len =
2890 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2891 }
2892
2893 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2894 params.listen_interval =
2895 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2896
Jouni Malinen36aedc902008-08-25 11:58:58 +03002897 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2898 params.ht_capa =
2899 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2900
Johannes Bergbdd90d52011-12-14 12:20:27 +01002901 if (!rdev->ops->change_station)
2902 return -EOPNOTSUPP;
2903
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002904 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002905 return -EINVAL;
2906
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002907 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2908 params.plink_action =
2909 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2910
Javier Cardona9c3990a2011-05-03 16:57:11 -07002911 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2912 params.plink_state =
2913 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2914
Johannes Berga97f4422009-06-18 17:23:43 +02002915 switch (dev->ieee80211_ptr->iftype) {
2916 case NL80211_IFTYPE_AP:
2917 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002918 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002919 /* disallow mesh-specific things */
2920 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002921 return -EINVAL;
2922
2923 /* TDLS can't be set, ... */
2924 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2925 return -EINVAL;
2926 /*
2927 * ... but don't bother the driver with it. This works around
2928 * a hostapd/wpa_supplicant issue -- it always includes the
2929 * TLDS_PEER flag in the mask even for AP mode.
2930 */
2931 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2932
2933 /* accept only the listed bits */
2934 if (params.sta_flags_mask &
2935 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2936 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2937 BIT(NL80211_STA_FLAG_WME) |
2938 BIT(NL80211_STA_FLAG_MFP)))
2939 return -EINVAL;
2940
2941 /* must be last in here for error handling */
2942 params.vlan = get_vlan(info, rdev);
2943 if (IS_ERR(params.vlan))
2944 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002945 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002946 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002947 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002948 /*
2949 * Don't allow userspace to change the TDLS_PEER flag,
2950 * but silently ignore attempts to change it since we
2951 * don't have state here to verify that it doesn't try
2952 * to change the flag.
2953 */
2954 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002955 /* fall through */
2956 case NL80211_IFTYPE_ADHOC:
2957 /* disallow things sta doesn't support */
2958 if (params.plink_action)
2959 return -EINVAL;
2960 if (params.ht_capa)
2961 return -EINVAL;
2962 if (params.listen_interval >= 0)
2963 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002964 /* reject any changes other than AUTHORIZED */
2965 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2966 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002967 break;
2968 case NL80211_IFTYPE_MESH_POINT:
2969 /* disallow things mesh doesn't support */
2970 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002971 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002972 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002973 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002974 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002975 return -EINVAL;
2976 /*
2977 * No special handling for TDLS here -- the userspace
2978 * mesh code doesn't have this bug.
2979 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002980 if (params.sta_flags_mask &
2981 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002982 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002983 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002984 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002985 break;
2986 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002987 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002988 }
2989
Johannes Bergbdd90d52011-12-14 12:20:27 +01002990 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002991
Johannes Berg79c97e92009-07-07 03:56:12 +02002992 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002993
Johannes Berg5727ef12007-12-19 02:03:34 +01002994 if (params.vlan)
2995 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002996
Johannes Berg5727ef12007-12-19 02:03:34 +01002997 return err;
2998}
2999
Eliad Pellerc75786c2011-08-23 14:37:46 +03003000static struct nla_policy
3001nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3002 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3003 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3004};
3005
Johannes Berg5727ef12007-12-19 02:03:34 +01003006static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3007{
Johannes Berg4c476992010-10-04 21:36:35 +02003008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003009 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003010 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003011 struct station_parameters params;
3012 u8 *mac_addr = NULL;
3013
3014 memset(&params, 0, sizeof(params));
3015
3016 if (!info->attrs[NL80211_ATTR_MAC])
3017 return -EINVAL;
3018
Johannes Berg5727ef12007-12-19 02:03:34 +01003019 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3020 return -EINVAL;
3021
3022 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3023 return -EINVAL;
3024
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003025 if (!info->attrs[NL80211_ATTR_STA_AID])
3026 return -EINVAL;
3027
Johannes Berg5727ef12007-12-19 02:03:34 +01003028 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3029 params.supported_rates =
3030 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3031 params.supported_rates_len =
3032 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3033 params.listen_interval =
3034 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003035
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003036 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3037 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3038 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003039
Jouni Malinen36aedc902008-08-25 11:58:58 +03003040 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3041 params.ht_capa =
3042 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003043
Javier Cardona96b78df2011-04-07 15:08:33 -07003044 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3045 params.plink_action =
3046 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3047
Johannes Bergbdd90d52011-12-14 12:20:27 +01003048 if (!rdev->ops->add_station)
3049 return -EOPNOTSUPP;
3050
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003051 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003052 return -EINVAL;
3053
Johannes Bergbdd90d52011-12-14 12:20:27 +01003054 switch (dev->ieee80211_ptr->iftype) {
3055 case NL80211_IFTYPE_AP:
3056 case NL80211_IFTYPE_AP_VLAN:
3057 case NL80211_IFTYPE_P2P_GO:
3058 /* parse WME attributes if sta is WME capable */
3059 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3060 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3061 info->attrs[NL80211_ATTR_STA_WME]) {
3062 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3063 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003064
Johannes Bergbdd90d52011-12-14 12:20:27 +01003065 nla = info->attrs[NL80211_ATTR_STA_WME];
3066 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3067 nl80211_sta_wme_policy);
3068 if (err)
3069 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003070
Johannes Bergbdd90d52011-12-14 12:20:27 +01003071 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3072 params.uapsd_queues =
3073 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3074 if (params.uapsd_queues &
3075 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3076 return -EINVAL;
3077
3078 if (tb[NL80211_STA_WME_MAX_SP])
3079 params.max_sp =
3080 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3081
3082 if (params.max_sp &
3083 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3084 return -EINVAL;
3085
3086 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3087 }
3088 /* TDLS peers cannot be added */
3089 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003090 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003091 /* but don't bother the driver with it */
3092 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003093
Johannes Bergbdd90d52011-12-14 12:20:27 +01003094 /* must be last in here for error handling */
3095 params.vlan = get_vlan(info, rdev);
3096 if (IS_ERR(params.vlan))
3097 return PTR_ERR(params.vlan);
3098 break;
3099 case NL80211_IFTYPE_MESH_POINT:
3100 /* TDLS peers cannot be added */
3101 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003102 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003103 break;
3104 case NL80211_IFTYPE_STATION:
3105 /* Only TDLS peers can be added */
3106 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3107 return -EINVAL;
3108 /* Can only add if TDLS ... */
3109 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3110 return -EOPNOTSUPP;
3111 /* ... with external setup is supported */
3112 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3113 return -EOPNOTSUPP;
3114 break;
3115 default:
3116 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003117 }
3118
Johannes Bergbdd90d52011-12-14 12:20:27 +01003119 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003120
Johannes Berg79c97e92009-07-07 03:56:12 +02003121 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003122
Johannes Berg5727ef12007-12-19 02:03:34 +01003123 if (params.vlan)
3124 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003125 return err;
3126}
3127
3128static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3129{
Johannes Berg4c476992010-10-04 21:36:35 +02003130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3131 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003132 u8 *mac_addr = NULL;
3133
3134 if (info->attrs[NL80211_ATTR_MAC])
3135 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3136
Johannes Berge80cf852009-05-11 14:43:13 +02003137 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003138 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003139 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003140 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3141 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003142
Johannes Berg4c476992010-10-04 21:36:35 +02003143 if (!rdev->ops->del_station)
3144 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003145
Johannes Berg4c476992010-10-04 21:36:35 +02003146 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003147}
3148
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003149static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3150 int flags, struct net_device *dev,
3151 u8 *dst, u8 *next_hop,
3152 struct mpath_info *pinfo)
3153{
3154 void *hdr;
3155 struct nlattr *pinfoattr;
3156
3157 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3158 if (!hdr)
3159 return -1;
3160
David S. Miller9360ffd2012-03-29 04:41:26 -04003161 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3162 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3163 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3164 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3165 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003166
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003167 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3168 if (!pinfoattr)
3169 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003170 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3171 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3172 pinfo->frame_qlen))
3173 goto nla_put_failure;
3174 if (((pinfo->filled & MPATH_INFO_SN) &&
3175 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3176 ((pinfo->filled & MPATH_INFO_METRIC) &&
3177 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3178 pinfo->metric)) ||
3179 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3180 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3181 pinfo->exptime)) ||
3182 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3183 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3184 pinfo->flags)) ||
3185 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3186 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3187 pinfo->discovery_timeout)) ||
3188 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3189 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3190 pinfo->discovery_retries)))
3191 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003192
3193 nla_nest_end(msg, pinfoattr);
3194
3195 return genlmsg_end(msg, hdr);
3196
3197 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003198 genlmsg_cancel(msg, hdr);
3199 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003200}
3201
3202static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003203 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003204{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003205 struct mpath_info pinfo;
3206 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003207 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003208 u8 dst[ETH_ALEN];
3209 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003210 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003211 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003212
Johannes Berg67748892010-10-04 21:14:06 +02003213 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3214 if (err)
3215 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003216
3217 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003218 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003219 goto out_err;
3220 }
3221
Jouni Malineneec60b02009-03-20 21:21:19 +02003222 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3223 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003224 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003225 }
3226
Johannes Bergbba95fe2008-07-29 13:22:51 +02003227 while (1) {
3228 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3229 dst, next_hop, &pinfo);
3230 if (err == -ENOENT)
3231 break;
3232 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003233 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003234
3235 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3236 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3237 netdev, dst, next_hop,
3238 &pinfo) < 0)
3239 goto out;
3240
3241 path_idx++;
3242 }
3243
3244
3245 out:
3246 cb->args[1] = path_idx;
3247 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003248 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003249 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003250 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003251}
3252
3253static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3254{
Johannes Berg4c476992010-10-04 21:36:35 +02003255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003256 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003257 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003258 struct mpath_info pinfo;
3259 struct sk_buff *msg;
3260 u8 *dst = NULL;
3261 u8 next_hop[ETH_ALEN];
3262
3263 memset(&pinfo, 0, sizeof(pinfo));
3264
3265 if (!info->attrs[NL80211_ATTR_MAC])
3266 return -EINVAL;
3267
3268 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3269
Johannes Berg4c476992010-10-04 21:36:35 +02003270 if (!rdev->ops->get_mpath)
3271 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003272
Johannes Berg4c476992010-10-04 21:36:35 +02003273 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3274 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003275
Johannes Berg79c97e92009-07-07 03:56:12 +02003276 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003277 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003278 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003279
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003281 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003282 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003283
3284 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003285 dev, dst, next_hop, &pinfo) < 0) {
3286 nlmsg_free(msg);
3287 return -ENOBUFS;
3288 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003289
Johannes Berg4c476992010-10-04 21:36:35 +02003290 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003291}
3292
3293static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3294{
Johannes Berg4c476992010-10-04 21:36:35 +02003295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3296 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003297 u8 *dst = NULL;
3298 u8 *next_hop = NULL;
3299
3300 if (!info->attrs[NL80211_ATTR_MAC])
3301 return -EINVAL;
3302
3303 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3304 return -EINVAL;
3305
3306 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3307 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3308
Johannes Berg4c476992010-10-04 21:36:35 +02003309 if (!rdev->ops->change_mpath)
3310 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003311
Johannes Berg4c476992010-10-04 21:36:35 +02003312 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3313 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003314
Johannes Berg4c476992010-10-04 21:36:35 +02003315 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003316}
Johannes Berg4c476992010-10-04 21:36:35 +02003317
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003318static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3319{
Johannes Berg4c476992010-10-04 21:36:35 +02003320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3321 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003322 u8 *dst = NULL;
3323 u8 *next_hop = NULL;
3324
3325 if (!info->attrs[NL80211_ATTR_MAC])
3326 return -EINVAL;
3327
3328 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3329 return -EINVAL;
3330
3331 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3332 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3333
Johannes Berg4c476992010-10-04 21:36:35 +02003334 if (!rdev->ops->add_mpath)
3335 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003336
Johannes Berg4c476992010-10-04 21:36:35 +02003337 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3338 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003339
Johannes Berg4c476992010-10-04 21:36:35 +02003340 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003341}
3342
3343static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3344{
Johannes Berg4c476992010-10-04 21:36:35 +02003345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3346 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003347 u8 *dst = NULL;
3348
3349 if (info->attrs[NL80211_ATTR_MAC])
3350 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3351
Johannes Berg4c476992010-10-04 21:36:35 +02003352 if (!rdev->ops->del_mpath)
3353 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003354
Johannes Berg4c476992010-10-04 21:36:35 +02003355 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003356}
3357
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003358static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3359{
Johannes Berg4c476992010-10-04 21:36:35 +02003360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3361 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003362 struct bss_parameters params;
3363
3364 memset(&params, 0, sizeof(params));
3365 /* default to not changing parameters */
3366 params.use_cts_prot = -1;
3367 params.use_short_preamble = -1;
3368 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003369 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003370 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003371
3372 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3373 params.use_cts_prot =
3374 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3375 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3376 params.use_short_preamble =
3377 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3378 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3379 params.use_short_slot_time =
3380 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003381 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3382 params.basic_rates =
3383 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3384 params.basic_rates_len =
3385 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3386 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003387 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3388 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003389 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3390 params.ht_opmode =
3391 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003392
Johannes Berg4c476992010-10-04 21:36:35 +02003393 if (!rdev->ops->change_bss)
3394 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003395
Johannes Berg074ac8d2010-09-16 14:58:22 +02003396 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003397 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3398 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003399
Johannes Berg4c476992010-10-04 21:36:35 +02003400 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003401}
3402
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003403static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003404 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3405 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3406 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3407 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3408 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3409 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3410};
3411
3412static int parse_reg_rule(struct nlattr *tb[],
3413 struct ieee80211_reg_rule *reg_rule)
3414{
3415 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3416 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3417
3418 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3419 return -EINVAL;
3420 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3421 return -EINVAL;
3422 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3423 return -EINVAL;
3424 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3425 return -EINVAL;
3426 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3427 return -EINVAL;
3428
3429 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3430
3431 freq_range->start_freq_khz =
3432 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3433 freq_range->end_freq_khz =
3434 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3435 freq_range->max_bandwidth_khz =
3436 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3437
3438 power_rule->max_eirp =
3439 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3440
3441 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3442 power_rule->max_antenna_gain =
3443 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3444
3445 return 0;
3446}
3447
3448static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3449{
3450 int r;
3451 char *data = NULL;
3452
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003453 /*
3454 * You should only get this when cfg80211 hasn't yet initialized
3455 * completely when built-in to the kernel right between the time
3456 * window between nl80211_init() and regulatory_init(), if that is
3457 * even possible.
3458 */
3459 mutex_lock(&cfg80211_mutex);
3460 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003461 mutex_unlock(&cfg80211_mutex);
3462 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003463 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003464 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003465
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003466 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3467 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003468
3469 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3470
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003471 r = regulatory_hint_user(data);
3472
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003473 return r;
3474}
3475
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003476static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003477 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003478{
Johannes Berg4c476992010-10-04 21:36:35 +02003479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003480 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003481 struct wireless_dev *wdev = dev->ieee80211_ptr;
3482 struct mesh_config cur_params;
3483 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003484 void *hdr;
3485 struct nlattr *pinfoattr;
3486 struct sk_buff *msg;
3487
Johannes Berg29cbe682010-12-03 09:20:44 +01003488 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3489 return -EOPNOTSUPP;
3490
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003491 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003492 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003493
Johannes Berg29cbe682010-12-03 09:20:44 +01003494 wdev_lock(wdev);
3495 /* If not connected, get default parameters */
3496 if (!wdev->mesh_id_len)
3497 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3498 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003499 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003500 &cur_params);
3501 wdev_unlock(wdev);
3502
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003504 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003505
3506 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003508 if (!msg)
3509 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003510 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003511 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003512 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003513 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003514 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003515 if (!pinfoattr)
3516 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3518 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3519 cur_params.dot11MeshRetryTimeout) ||
3520 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3521 cur_params.dot11MeshConfirmTimeout) ||
3522 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3523 cur_params.dot11MeshHoldingTimeout) ||
3524 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3525 cur_params.dot11MeshMaxPeerLinks) ||
3526 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3527 cur_params.dot11MeshMaxRetries) ||
3528 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3529 cur_params.dot11MeshTTL) ||
3530 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3531 cur_params.element_ttl) ||
3532 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3533 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003534 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3535 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003536 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3537 cur_params.dot11MeshHWMPmaxPREQretries) ||
3538 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3539 cur_params.path_refresh_time) ||
3540 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3541 cur_params.min_discovery_timeout) ||
3542 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3543 cur_params.dot11MeshHWMPactivePathTimeout) ||
3544 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3545 cur_params.dot11MeshHWMPpreqMinInterval) ||
3546 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3547 cur_params.dot11MeshHWMPperrMinInterval) ||
3548 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3549 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3550 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3551 cur_params.dot11MeshHWMPRootMode) ||
3552 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3553 cur_params.dot11MeshHWMPRannInterval) ||
3554 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3555 cur_params.dot11MeshGateAnnouncementProtocol) ||
3556 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3557 cur_params.dot11MeshForwarding) ||
3558 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003559 cur_params.rssi_threshold) ||
3560 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003561 cur_params.ht_opmode) ||
3562 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3563 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3564 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003565 cur_params.dot11MeshHWMProotInterval) ||
3566 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3567 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003568 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003569 nla_nest_end(msg, pinfoattr);
3570 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003571 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003572
Johannes Berg3b858752009-03-12 09:55:09 +01003573 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003574 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003575 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003576 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003577 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003578}
3579
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003580static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003581 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3582 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3583 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3584 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3585 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3586 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003587 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003588 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003589 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003590 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3591 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3592 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3593 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3594 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003595 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003596 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003597 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003598 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003599 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003600 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003601 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3602 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003603 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3604 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003605 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003606};
3607
Javier Cardonac80d5452010-12-16 17:37:49 -08003608static const struct nla_policy
3609 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003610 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003611 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3612 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003613 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003614 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003615 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003616 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003617};
3618
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003619static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003620 struct mesh_config *cfg,
3621 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003622{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003623 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003624 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003625
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003626#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3627do {\
3628 if (table[attr_num]) {\
3629 cfg->param = nla_fn(table[attr_num]); \
3630 mask |= (1 << (attr_num - 1)); \
3631 } \
3632} while (0);\
3633
3634
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003635 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003636 return -EINVAL;
3637 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003638 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003639 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003640 return -EINVAL;
3641
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003642 /* This makes sure that there aren't more than 32 mesh config
3643 * parameters (otherwise our bitfield scheme would not work.) */
3644 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3645
3646 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003647 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003648 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3649 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003650 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003651 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3652 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003653 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003654 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3655 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003656 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003657 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3658 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003660 mask, NL80211_MESHCONF_MAX_RETRIES,
3661 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003662 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003663 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003664 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003665 mask, NL80211_MESHCONF_ELEMENT_TTL,
3666 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003668 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3669 nla_get_u8);
3670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3671 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3672 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003674 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3675 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003677 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3678 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003680 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3681 nla_get_u16);
3682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3683 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3684 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003686 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3687 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003688 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003689 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3690 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003692 dot11MeshHWMPnetDiameterTraversalTime, mask,
3693 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3694 nla_get_u16);
3695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3696 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3698 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3699 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003701 dot11MeshGateAnnouncementProtocol, mask,
3702 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3703 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003705 mask, NL80211_MESHCONF_FORWARDING,
3706 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003708 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3709 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003711 mask, NL80211_MESHCONF_HT_OPMODE,
3712 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3714 mask,
3715 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3716 nla_get_u32);
3717 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3718 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3719 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3721 dot11MeshHWMPconfirmationInterval, mask,
3722 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3723 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003724 if (mask_out)
3725 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003726
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003727 return 0;
3728
3729#undef FILL_IN_MESH_PARAM_IF_SET
3730}
3731
Javier Cardonac80d5452010-12-16 17:37:49 -08003732static int nl80211_parse_mesh_setup(struct genl_info *info,
3733 struct mesh_setup *setup)
3734{
3735 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3736
3737 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3738 return -EINVAL;
3739 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3740 info->attrs[NL80211_ATTR_MESH_SETUP],
3741 nl80211_mesh_setup_params_policy))
3742 return -EINVAL;
3743
Javier Cardonad299a1f2012-03-31 11:31:33 -07003744 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3745 setup->sync_method =
3746 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3747 IEEE80211_SYNC_METHOD_VENDOR :
3748 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3749
Javier Cardonac80d5452010-12-16 17:37:49 -08003750 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3751 setup->path_sel_proto =
3752 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3753 IEEE80211_PATH_PROTOCOL_VENDOR :
3754 IEEE80211_PATH_PROTOCOL_HWMP;
3755
3756 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3757 setup->path_metric =
3758 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3759 IEEE80211_PATH_METRIC_VENDOR :
3760 IEEE80211_PATH_METRIC_AIRTIME;
3761
Javier Cardona581a8b02011-04-07 15:08:27 -07003762
3763 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003764 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003765 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003766 if (!is_valid_ie_attr(ieattr))
3767 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003768 setup->ie = nla_data(ieattr);
3769 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003770 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003771 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3772 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003773
3774 return 0;
3775}
3776
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003777static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003778 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003779{
3780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3781 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003782 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003783 struct mesh_config cfg;
3784 u32 mask;
3785 int err;
3786
Johannes Berg29cbe682010-12-03 09:20:44 +01003787 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3788 return -EOPNOTSUPP;
3789
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003790 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003791 return -EOPNOTSUPP;
3792
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003793 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003794 if (err)
3795 return err;
3796
Johannes Berg29cbe682010-12-03 09:20:44 +01003797 wdev_lock(wdev);
3798 if (!wdev->mesh_id_len)
3799 err = -ENOLINK;
3800
3801 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003802 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003803 mask, &cfg);
3804
3805 wdev_unlock(wdev);
3806
3807 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003808}
3809
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003810static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3811{
3812 struct sk_buff *msg;
3813 void *hdr = NULL;
3814 struct nlattr *nl_reg_rules;
3815 unsigned int i;
3816 int err = -EINVAL;
3817
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003818 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003819
3820 if (!cfg80211_regdomain)
3821 goto out;
3822
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003823 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003824 if (!msg) {
3825 err = -ENOBUFS;
3826 goto out;
3827 }
3828
3829 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3830 NL80211_CMD_GET_REG);
3831 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003832 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003833
David S. Miller9360ffd2012-03-29 04:41:26 -04003834 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3835 cfg80211_regdomain->alpha2) ||
3836 (cfg80211_regdomain->dfs_region &&
3837 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3838 cfg80211_regdomain->dfs_region)))
3839 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003840
3841 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3842 if (!nl_reg_rules)
3843 goto nla_put_failure;
3844
3845 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3846 struct nlattr *nl_reg_rule;
3847 const struct ieee80211_reg_rule *reg_rule;
3848 const struct ieee80211_freq_range *freq_range;
3849 const struct ieee80211_power_rule *power_rule;
3850
3851 reg_rule = &cfg80211_regdomain->reg_rules[i];
3852 freq_range = &reg_rule->freq_range;
3853 power_rule = &reg_rule->power_rule;
3854
3855 nl_reg_rule = nla_nest_start(msg, i);
3856 if (!nl_reg_rule)
3857 goto nla_put_failure;
3858
David S. Miller9360ffd2012-03-29 04:41:26 -04003859 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3860 reg_rule->flags) ||
3861 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3862 freq_range->start_freq_khz) ||
3863 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3864 freq_range->end_freq_khz) ||
3865 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3866 freq_range->max_bandwidth_khz) ||
3867 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3868 power_rule->max_antenna_gain) ||
3869 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3870 power_rule->max_eirp))
3871 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003872
3873 nla_nest_end(msg, nl_reg_rule);
3874 }
3875
3876 nla_nest_end(msg, nl_reg_rules);
3877
3878 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003879 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003880 goto out;
3881
3882nla_put_failure:
3883 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003884put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003885 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003886 err = -EMSGSIZE;
3887out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003888 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003889 return err;
3890}
3891
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003892static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3893{
3894 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3895 struct nlattr *nl_reg_rule;
3896 char *alpha2 = NULL;
3897 int rem_reg_rules = 0, r = 0;
3898 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003899 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003900 struct ieee80211_regdomain *rd = NULL;
3901
3902 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3903 return -EINVAL;
3904
3905 if (!info->attrs[NL80211_ATTR_REG_RULES])
3906 return -EINVAL;
3907
3908 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3909
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003910 if (info->attrs[NL80211_ATTR_DFS_REGION])
3911 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3912
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003913 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3914 rem_reg_rules) {
3915 num_rules++;
3916 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003917 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003918 }
3919
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003920 mutex_lock(&cfg80211_mutex);
3921
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003922 if (!reg_is_valid_request(alpha2)) {
3923 r = -EINVAL;
3924 goto bad_reg;
3925 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003926
3927 size_of_regd = sizeof(struct ieee80211_regdomain) +
3928 (num_rules * sizeof(struct ieee80211_reg_rule));
3929
3930 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003931 if (!rd) {
3932 r = -ENOMEM;
3933 goto bad_reg;
3934 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003935
3936 rd->n_reg_rules = num_rules;
3937 rd->alpha2[0] = alpha2[0];
3938 rd->alpha2[1] = alpha2[1];
3939
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003940 /*
3941 * Disable DFS master mode if the DFS region was
3942 * not supported or known on this kernel.
3943 */
3944 if (reg_supported_dfs_region(dfs_region))
3945 rd->dfs_region = dfs_region;
3946
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003947 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3948 rem_reg_rules) {
3949 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3950 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3951 reg_rule_policy);
3952 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3953 if (r)
3954 goto bad_reg;
3955
3956 rule_idx++;
3957
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003958 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3959 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003960 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003961 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003962 }
3963
3964 BUG_ON(rule_idx != num_rules);
3965
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003966 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003967
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003968 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003969
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003970 return r;
3971
Johannes Bergd2372b32008-10-24 20:32:20 +02003972 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003973 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003974 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003975 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003976}
3977
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003978static int validate_scan_freqs(struct nlattr *freqs)
3979{
3980 struct nlattr *attr1, *attr2;
3981 int n_channels = 0, tmp1, tmp2;
3982
3983 nla_for_each_nested(attr1, freqs, tmp1) {
3984 n_channels++;
3985 /*
3986 * Some hardware has a limited channel list for
3987 * scanning, and it is pretty much nonsensical
3988 * to scan for a channel twice, so disallow that
3989 * and don't require drivers to check that the
3990 * channel list they get isn't longer than what
3991 * they can scan, as long as they can scan all
3992 * the channels they registered at once.
3993 */
3994 nla_for_each_nested(attr2, freqs, tmp2)
3995 if (attr1 != attr2 &&
3996 nla_get_u32(attr1) == nla_get_u32(attr2))
3997 return 0;
3998 }
3999
4000 return n_channels;
4001}
4002
Johannes Berg2a519312009-02-10 21:25:55 +01004003static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4004{
Johannes Berg4c476992010-10-04 21:36:35 +02004005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4006 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004007 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004008 struct nlattr *attr;
4009 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004010 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004011 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004012
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004013 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4014 return -EINVAL;
4015
Johannes Berg79c97e92009-07-07 03:56:12 +02004016 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004017
Johannes Berg4c476992010-10-04 21:36:35 +02004018 if (!rdev->ops->scan)
4019 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004020
Johannes Berg4c476992010-10-04 21:36:35 +02004021 if (rdev->scan_req)
4022 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004023
4024 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004025 n_channels = validate_scan_freqs(
4026 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004027 if (!n_channels)
4028 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004029 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004030 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004031 n_channels = 0;
4032
Johannes Berg2a519312009-02-10 21:25:55 +01004033 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4034 if (wiphy->bands[band])
4035 n_channels += wiphy->bands[band]->n_channels;
4036 }
4037
4038 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4039 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4040 n_ssids++;
4041
Johannes Berg4c476992010-10-04 21:36:35 +02004042 if (n_ssids > wiphy->max_scan_ssids)
4043 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004044
Jouni Malinen70692ad2009-02-16 19:39:13 +02004045 if (info->attrs[NL80211_ATTR_IE])
4046 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4047 else
4048 ie_len = 0;
4049
Johannes Berg4c476992010-10-04 21:36:35 +02004050 if (ie_len > wiphy->max_scan_ie_len)
4051 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004052
Johannes Berg2a519312009-02-10 21:25:55 +01004053 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004054 + sizeof(*request->ssids) * n_ssids
4055 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004056 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004057 if (!request)
4058 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004059
Johannes Berg2a519312009-02-10 21:25:55 +01004060 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004061 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004062 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004063 if (ie_len) {
4064 if (request->ssids)
4065 request->ie = (void *)(request->ssids + n_ssids);
4066 else
4067 request->ie = (void *)(request->channels + n_channels);
4068 }
Johannes Berg2a519312009-02-10 21:25:55 +01004069
Johannes Berg584991d2009-11-02 13:32:03 +01004070 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004071 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4072 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004073 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004074 struct ieee80211_channel *chan;
4075
4076 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4077
4078 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004079 err = -EINVAL;
4080 goto out_free;
4081 }
Johannes Berg584991d2009-11-02 13:32:03 +01004082
4083 /* ignore disabled channels */
4084 if (chan->flags & IEEE80211_CHAN_DISABLED)
4085 continue;
4086
4087 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004088 i++;
4089 }
4090 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004091 enum ieee80211_band band;
4092
Johannes Berg2a519312009-02-10 21:25:55 +01004093 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004094 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4095 int j;
4096 if (!wiphy->bands[band])
4097 continue;
4098 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004099 struct ieee80211_channel *chan;
4100
4101 chan = &wiphy->bands[band]->channels[j];
4102
4103 if (chan->flags & IEEE80211_CHAN_DISABLED)
4104 continue;
4105
4106 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004107 i++;
4108 }
4109 }
4110 }
4111
Johannes Berg584991d2009-11-02 13:32:03 +01004112 if (!i) {
4113 err = -EINVAL;
4114 goto out_free;
4115 }
4116
4117 request->n_channels = i;
4118
Johannes Berg2a519312009-02-10 21:25:55 +01004119 i = 0;
4120 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4121 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004122 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004123 err = -EINVAL;
4124 goto out_free;
4125 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004126 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004127 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004128 i++;
4129 }
4130 }
4131
Jouni Malinen70692ad2009-02-16 19:39:13 +02004132 if (info->attrs[NL80211_ATTR_IE]) {
4133 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004134 memcpy((void *)request->ie,
4135 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004136 request->ie_len);
4137 }
4138
Johannes Berg34850ab2011-07-18 18:08:35 +02004139 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004140 if (wiphy->bands[i])
4141 request->rates[i] =
4142 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004143
4144 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4145 nla_for_each_nested(attr,
4146 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4147 tmp) {
4148 enum ieee80211_band band = nla_type(attr);
4149
Dan Carpenter84404622011-07-29 11:52:18 +03004150 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004151 err = -EINVAL;
4152 goto out_free;
4153 }
4154 err = ieee80211_get_ratemask(wiphy->bands[band],
4155 nla_data(attr),
4156 nla_len(attr),
4157 &request->rates[band]);
4158 if (err)
4159 goto out_free;
4160 }
4161 }
4162
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304163 request->no_cck =
4164 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4165
Johannes Berg463d0182009-07-14 00:33:35 +02004166 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004167 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004168
Johannes Berg79c97e92009-07-07 03:56:12 +02004169 rdev->scan_req = request;
4170 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004171
Johannes Berg463d0182009-07-14 00:33:35 +02004172 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004173 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004174 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004175 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004176 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004177 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004178 kfree(request);
4179 }
Johannes Berg3b858752009-03-12 09:55:09 +01004180
Johannes Berg2a519312009-02-10 21:25:55 +01004181 return err;
4182}
4183
Luciano Coelho807f8a82011-05-11 17:09:35 +03004184static int nl80211_start_sched_scan(struct sk_buff *skb,
4185 struct genl_info *info)
4186{
4187 struct cfg80211_sched_scan_request *request;
4188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4189 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004190 struct nlattr *attr;
4191 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004192 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004193 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004194 enum ieee80211_band band;
4195 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004196 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004197
4198 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4199 !rdev->ops->sched_scan_start)
4200 return -EOPNOTSUPP;
4201
4202 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4203 return -EINVAL;
4204
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004205 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4206 return -EINVAL;
4207
4208 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4209 if (interval == 0)
4210 return -EINVAL;
4211
Luciano Coelho807f8a82011-05-11 17:09:35 +03004212 wiphy = &rdev->wiphy;
4213
4214 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4215 n_channels = validate_scan_freqs(
4216 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4217 if (!n_channels)
4218 return -EINVAL;
4219 } else {
4220 n_channels = 0;
4221
4222 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4223 if (wiphy->bands[band])
4224 n_channels += wiphy->bands[band]->n_channels;
4225 }
4226
4227 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4228 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4229 tmp)
4230 n_ssids++;
4231
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004232 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004233 return -EINVAL;
4234
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004235 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4236 nla_for_each_nested(attr,
4237 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4238 tmp)
4239 n_match_sets++;
4240
4241 if (n_match_sets > wiphy->max_match_sets)
4242 return -EINVAL;
4243
Luciano Coelho807f8a82011-05-11 17:09:35 +03004244 if (info->attrs[NL80211_ATTR_IE])
4245 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4246 else
4247 ie_len = 0;
4248
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004249 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004250 return -EINVAL;
4251
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004252 mutex_lock(&rdev->sched_scan_mtx);
4253
4254 if (rdev->sched_scan_req) {
4255 err = -EINPROGRESS;
4256 goto out;
4257 }
4258
Luciano Coelho807f8a82011-05-11 17:09:35 +03004259 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004260 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004261 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004262 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004263 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004264 if (!request) {
4265 err = -ENOMEM;
4266 goto out;
4267 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004268
4269 if (n_ssids)
4270 request->ssids = (void *)&request->channels[n_channels];
4271 request->n_ssids = n_ssids;
4272 if (ie_len) {
4273 if (request->ssids)
4274 request->ie = (void *)(request->ssids + n_ssids);
4275 else
4276 request->ie = (void *)(request->channels + n_channels);
4277 }
4278
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004279 if (n_match_sets) {
4280 if (request->ie)
4281 request->match_sets = (void *)(request->ie + ie_len);
4282 else if (request->ssids)
4283 request->match_sets =
4284 (void *)(request->ssids + n_ssids);
4285 else
4286 request->match_sets =
4287 (void *)(request->channels + n_channels);
4288 }
4289 request->n_match_sets = n_match_sets;
4290
Luciano Coelho807f8a82011-05-11 17:09:35 +03004291 i = 0;
4292 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4293 /* user specified, bail out if channel not found */
4294 nla_for_each_nested(attr,
4295 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4296 tmp) {
4297 struct ieee80211_channel *chan;
4298
4299 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4300
4301 if (!chan) {
4302 err = -EINVAL;
4303 goto out_free;
4304 }
4305
4306 /* ignore disabled channels */
4307 if (chan->flags & IEEE80211_CHAN_DISABLED)
4308 continue;
4309
4310 request->channels[i] = chan;
4311 i++;
4312 }
4313 } else {
4314 /* all channels */
4315 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4316 int j;
4317 if (!wiphy->bands[band])
4318 continue;
4319 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4320 struct ieee80211_channel *chan;
4321
4322 chan = &wiphy->bands[band]->channels[j];
4323
4324 if (chan->flags & IEEE80211_CHAN_DISABLED)
4325 continue;
4326
4327 request->channels[i] = chan;
4328 i++;
4329 }
4330 }
4331 }
4332
4333 if (!i) {
4334 err = -EINVAL;
4335 goto out_free;
4336 }
4337
4338 request->n_channels = i;
4339
4340 i = 0;
4341 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4342 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4343 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004344 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004345 err = -EINVAL;
4346 goto out_free;
4347 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004348 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004349 memcpy(request->ssids[i].ssid, nla_data(attr),
4350 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004351 i++;
4352 }
4353 }
4354
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004355 i = 0;
4356 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4357 nla_for_each_nested(attr,
4358 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4359 tmp) {
4360 struct nlattr *ssid;
4361
4362 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4363 nla_data(attr), nla_len(attr),
4364 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004365 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004366 if (ssid) {
4367 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4368 err = -EINVAL;
4369 goto out_free;
4370 }
4371 memcpy(request->match_sets[i].ssid.ssid,
4372 nla_data(ssid), nla_len(ssid));
4373 request->match_sets[i].ssid.ssid_len =
4374 nla_len(ssid);
4375 }
4376 i++;
4377 }
4378 }
4379
Luciano Coelho807f8a82011-05-11 17:09:35 +03004380 if (info->attrs[NL80211_ATTR_IE]) {
4381 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4382 memcpy((void *)request->ie,
4383 nla_data(info->attrs[NL80211_ATTR_IE]),
4384 request->ie_len);
4385 }
4386
4387 request->dev = dev;
4388 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004389 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004390
4391 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4392 if (!err) {
4393 rdev->sched_scan_req = request;
4394 nl80211_send_sched_scan(rdev, dev,
4395 NL80211_CMD_START_SCHED_SCAN);
4396 goto out;
4397 }
4398
4399out_free:
4400 kfree(request);
4401out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004402 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004403 return err;
4404}
4405
4406static int nl80211_stop_sched_scan(struct sk_buff *skb,
4407 struct genl_info *info)
4408{
4409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004410 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004411
4412 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4413 !rdev->ops->sched_scan_stop)
4414 return -EOPNOTSUPP;
4415
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004416 mutex_lock(&rdev->sched_scan_mtx);
4417 err = __cfg80211_stop_sched_scan(rdev, false);
4418 mutex_unlock(&rdev->sched_scan_mtx);
4419
4420 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004421}
4422
Johannes Berg9720bb32011-06-21 09:45:33 +02004423static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4424 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004425 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004426 struct wireless_dev *wdev,
4427 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004428{
Johannes Berg48ab9052009-07-10 18:42:31 +02004429 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004430 void *hdr;
4431 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004432
4433 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004434
Johannes Berg9720bb32011-06-21 09:45:33 +02004435 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004436 NL80211_CMD_NEW_SCAN_RESULTS);
4437 if (!hdr)
4438 return -1;
4439
Johannes Berg9720bb32011-06-21 09:45:33 +02004440 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4441
David S. Miller9360ffd2012-03-29 04:41:26 -04004442 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4443 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4444 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004445
4446 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4447 if (!bss)
4448 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004449 if ((!is_zero_ether_addr(res->bssid) &&
4450 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4451 (res->information_elements && res->len_information_elements &&
4452 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4453 res->len_information_elements,
4454 res->information_elements)) ||
4455 (res->beacon_ies && res->len_beacon_ies &&
4456 res->beacon_ies != res->information_elements &&
4457 nla_put(msg, NL80211_BSS_BEACON_IES,
4458 res->len_beacon_ies, res->beacon_ies)))
4459 goto nla_put_failure;
4460 if (res->tsf &&
4461 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4462 goto nla_put_failure;
4463 if (res->beacon_interval &&
4464 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4465 goto nla_put_failure;
4466 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4467 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4468 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4469 jiffies_to_msecs(jiffies - intbss->ts)))
4470 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004471
Johannes Berg77965c92009-02-18 18:45:06 +01004472 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004473 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004474 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4475 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004476 break;
4477 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004478 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4479 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004480 break;
4481 default:
4482 break;
4483 }
4484
Johannes Berg48ab9052009-07-10 18:42:31 +02004485 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004486 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004487 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004488 if (intbss == wdev->current_bss &&
4489 nla_put_u32(msg, NL80211_BSS_STATUS,
4490 NL80211_BSS_STATUS_ASSOCIATED))
4491 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004492 break;
4493 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004494 if (intbss == wdev->current_bss &&
4495 nla_put_u32(msg, NL80211_BSS_STATUS,
4496 NL80211_BSS_STATUS_IBSS_JOINED))
4497 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004498 break;
4499 default:
4500 break;
4501 }
4502
Johannes Berg2a519312009-02-10 21:25:55 +01004503 nla_nest_end(msg, bss);
4504
4505 return genlmsg_end(msg, hdr);
4506
4507 nla_put_failure:
4508 genlmsg_cancel(msg, hdr);
4509 return -EMSGSIZE;
4510}
4511
4512static int nl80211_dump_scan(struct sk_buff *skb,
4513 struct netlink_callback *cb)
4514{
Johannes Berg48ab9052009-07-10 18:42:31 +02004515 struct cfg80211_registered_device *rdev;
4516 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004517 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004518 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004519 int start = cb->args[1], idx = 0;
4520 int err;
4521
Johannes Berg67748892010-10-04 21:14:06 +02004522 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4523 if (err)
4524 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004525
Johannes Berg48ab9052009-07-10 18:42:31 +02004526 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004527
Johannes Berg48ab9052009-07-10 18:42:31 +02004528 wdev_lock(wdev);
4529 spin_lock_bh(&rdev->bss_lock);
4530 cfg80211_bss_expire(rdev);
4531
Johannes Berg9720bb32011-06-21 09:45:33 +02004532 cb->seq = rdev->bss_generation;
4533
Johannes Berg48ab9052009-07-10 18:42:31 +02004534 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004535 if (++idx <= start)
4536 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004537 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004538 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004539 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004540 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004541 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004542 }
4543 }
4544
Johannes Berg48ab9052009-07-10 18:42:31 +02004545 spin_unlock_bh(&rdev->bss_lock);
4546 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004547
4548 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004549 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004550
Johannes Berg67748892010-10-04 21:14:06 +02004551 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004552}
4553
Holger Schurig61fa7132009-11-11 12:25:40 +01004554static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4555 int flags, struct net_device *dev,
4556 struct survey_info *survey)
4557{
4558 void *hdr;
4559 struct nlattr *infoattr;
4560
Holger Schurig61fa7132009-11-11 12:25:40 +01004561 hdr = nl80211hdr_put(msg, pid, seq, flags,
4562 NL80211_CMD_NEW_SURVEY_RESULTS);
4563 if (!hdr)
4564 return -ENOMEM;
4565
David S. Miller9360ffd2012-03-29 04:41:26 -04004566 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4567 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004568
4569 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4570 if (!infoattr)
4571 goto nla_put_failure;
4572
David S. Miller9360ffd2012-03-29 04:41:26 -04004573 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4574 survey->channel->center_freq))
4575 goto nla_put_failure;
4576
4577 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4578 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4579 goto nla_put_failure;
4580 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4581 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4582 goto nla_put_failure;
4583 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4584 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4585 survey->channel_time))
4586 goto nla_put_failure;
4587 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4588 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4589 survey->channel_time_busy))
4590 goto nla_put_failure;
4591 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4592 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4593 survey->channel_time_ext_busy))
4594 goto nla_put_failure;
4595 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4596 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4597 survey->channel_time_rx))
4598 goto nla_put_failure;
4599 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4600 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4601 survey->channel_time_tx))
4602 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004603
4604 nla_nest_end(msg, infoattr);
4605
4606 return genlmsg_end(msg, hdr);
4607
4608 nla_put_failure:
4609 genlmsg_cancel(msg, hdr);
4610 return -EMSGSIZE;
4611}
4612
4613static int nl80211_dump_survey(struct sk_buff *skb,
4614 struct netlink_callback *cb)
4615{
4616 struct survey_info survey;
4617 struct cfg80211_registered_device *dev;
4618 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004619 int survey_idx = cb->args[1];
4620 int res;
4621
Johannes Berg67748892010-10-04 21:14:06 +02004622 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4623 if (res)
4624 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004625
4626 if (!dev->ops->dump_survey) {
4627 res = -EOPNOTSUPP;
4628 goto out_err;
4629 }
4630
4631 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004632 struct ieee80211_channel *chan;
4633
Holger Schurig61fa7132009-11-11 12:25:40 +01004634 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4635 &survey);
4636 if (res == -ENOENT)
4637 break;
4638 if (res)
4639 goto out_err;
4640
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004641 /* Survey without a channel doesn't make sense */
4642 if (!survey.channel) {
4643 res = -EINVAL;
4644 goto out;
4645 }
4646
4647 chan = ieee80211_get_channel(&dev->wiphy,
4648 survey.channel->center_freq);
4649 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4650 survey_idx++;
4651 continue;
4652 }
4653
Holger Schurig61fa7132009-11-11 12:25:40 +01004654 if (nl80211_send_survey(skb,
4655 NETLINK_CB(cb->skb).pid,
4656 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4657 netdev,
4658 &survey) < 0)
4659 goto out;
4660 survey_idx++;
4661 }
4662
4663 out:
4664 cb->args[1] = survey_idx;
4665 res = skb->len;
4666 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004667 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004668 return res;
4669}
4670
Jouni Malinen255e7372009-03-20 21:21:17 +02004671static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4672{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004673 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004674}
4675
Samuel Ortizb23aa672009-07-01 21:26:54 +02004676static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4677{
4678 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4679 NL80211_WPA_VERSION_2));
4680}
4681
Jouni Malinen636a5d32009-03-19 13:39:22 +02004682static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4683{
Johannes Berg4c476992010-10-04 21:36:35 +02004684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4685 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004686 struct ieee80211_channel *chan;
4687 const u8 *bssid, *ssid, *ie = NULL;
4688 int err, ssid_len, ie_len = 0;
4689 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004690 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004691 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004692
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004693 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4694 return -EINVAL;
4695
4696 if (!info->attrs[NL80211_ATTR_MAC])
4697 return -EINVAL;
4698
Jouni Malinen17780922009-03-27 20:52:47 +02004699 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4700 return -EINVAL;
4701
Johannes Berg19957bb2009-07-02 17:20:43 +02004702 if (!info->attrs[NL80211_ATTR_SSID])
4703 return -EINVAL;
4704
4705 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4706 return -EINVAL;
4707
Johannes Bergfffd0932009-07-08 14:22:54 +02004708 err = nl80211_parse_key(info, &key);
4709 if (err)
4710 return err;
4711
4712 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004713 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4714 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004715 if (!key.p.key || !key.p.key_len)
4716 return -EINVAL;
4717 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4718 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4719 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4720 key.p.key_len != WLAN_KEY_LEN_WEP104))
4721 return -EINVAL;
4722 if (key.idx > 4)
4723 return -EINVAL;
4724 } else {
4725 key.p.key_len = 0;
4726 key.p.key = NULL;
4727 }
4728
Johannes Bergafea0b72010-08-10 09:46:42 +02004729 if (key.idx >= 0) {
4730 int i;
4731 bool ok = false;
4732 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4733 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4734 ok = true;
4735 break;
4736 }
4737 }
Johannes Berg4c476992010-10-04 21:36:35 +02004738 if (!ok)
4739 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004740 }
4741
Johannes Berg4c476992010-10-04 21:36:35 +02004742 if (!rdev->ops->auth)
4743 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004744
Johannes Berg074ac8d2010-09-16 14:58:22 +02004745 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004746 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4747 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004748
Johannes Berg19957bb2009-07-02 17:20:43 +02004749 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004750 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004751 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004752 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4753 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004754
Johannes Berg19957bb2009-07-02 17:20:43 +02004755 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4756 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4757
4758 if (info->attrs[NL80211_ATTR_IE]) {
4759 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4760 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4761 }
4762
4763 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004764 if (!nl80211_valid_auth_type(auth_type))
4765 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004766
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004767 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4768
Johannes Berg95de8172012-01-20 13:55:25 +01004769 /*
4770 * Since we no longer track auth state, ignore
4771 * requests to only change local state.
4772 */
4773 if (local_state_change)
4774 return 0;
4775
Johannes Berg4c476992010-10-04 21:36:35 +02004776 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4777 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004778 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004779}
4780
Johannes Bergc0692b82010-08-27 14:26:53 +03004781static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4782 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004783 struct cfg80211_crypto_settings *settings,
4784 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004785{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004786 memset(settings, 0, sizeof(*settings));
4787
Samuel Ortizb23aa672009-07-01 21:26:54 +02004788 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4789
Johannes Bergc0692b82010-08-27 14:26:53 +03004790 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4791 u16 proto;
4792 proto = nla_get_u16(
4793 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4794 settings->control_port_ethertype = cpu_to_be16(proto);
4795 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4796 proto != ETH_P_PAE)
4797 return -EINVAL;
4798 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4799 settings->control_port_no_encrypt = true;
4800 } else
4801 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4802
Samuel Ortizb23aa672009-07-01 21:26:54 +02004803 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4804 void *data;
4805 int len, i;
4806
4807 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4808 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4809 settings->n_ciphers_pairwise = len / sizeof(u32);
4810
4811 if (len % sizeof(u32))
4812 return -EINVAL;
4813
Johannes Berg3dc27d22009-07-02 21:36:37 +02004814 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004815 return -EINVAL;
4816
4817 memcpy(settings->ciphers_pairwise, data, len);
4818
4819 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004820 if (!cfg80211_supported_cipher_suite(
4821 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004822 settings->ciphers_pairwise[i]))
4823 return -EINVAL;
4824 }
4825
4826 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4827 settings->cipher_group =
4828 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004829 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4830 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004831 return -EINVAL;
4832 }
4833
4834 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4835 settings->wpa_versions =
4836 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4837 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4838 return -EINVAL;
4839 }
4840
4841 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4842 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004843 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004844
4845 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4846 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4847 settings->n_akm_suites = len / sizeof(u32);
4848
4849 if (len % sizeof(u32))
4850 return -EINVAL;
4851
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004852 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4853 return -EINVAL;
4854
Samuel Ortizb23aa672009-07-01 21:26:54 +02004855 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004856 }
4857
4858 return 0;
4859}
4860
Jouni Malinen636a5d32009-03-19 13:39:22 +02004861static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4862{
Johannes Berg4c476992010-10-04 21:36:35 +02004863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4864 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004865 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004866 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004867 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004868 int err, ssid_len, ie_len = 0;
4869 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004870 u32 flags = 0;
4871 struct ieee80211_ht_cap *ht_capa = NULL;
4872 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004873
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004874 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4875 return -EINVAL;
4876
4877 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004878 !info->attrs[NL80211_ATTR_SSID] ||
4879 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004880 return -EINVAL;
4881
Johannes Berg4c476992010-10-04 21:36:35 +02004882 if (!rdev->ops->assoc)
4883 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004884
Johannes Berg074ac8d2010-09-16 14:58:22 +02004885 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004886 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4887 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004888
Johannes Berg19957bb2009-07-02 17:20:43 +02004889 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004890
Johannes Berg19957bb2009-07-02 17:20:43 +02004891 chan = ieee80211_get_channel(&rdev->wiphy,
4892 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004893 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4894 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004895
Johannes Berg19957bb2009-07-02 17:20:43 +02004896 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4897 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004898
4899 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004900 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4901 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004902 }
4903
Jouni Malinendc6382c2009-05-06 22:09:37 +03004904 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004905 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004906 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004907 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004908 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004909 else if (mfp != NL80211_MFP_NO)
4910 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004911 }
4912
Johannes Berg3e5d7642009-07-07 14:37:26 +02004913 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4914 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4915
Ben Greear7e7c8922011-11-18 11:31:59 -08004916 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4917 flags |= ASSOC_REQ_DISABLE_HT;
4918
4919 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4920 ht_capa_mask =
4921 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4922
4923 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4924 if (!ht_capa_mask)
4925 return -EINVAL;
4926 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4927 }
4928
Johannes Bergc0692b82010-08-27 14:26:53 +03004929 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004930 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004931 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4932 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004933 &crypto, flags, ht_capa,
4934 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004935
Jouni Malinen636a5d32009-03-19 13:39:22 +02004936 return err;
4937}
4938
4939static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4940{
Johannes Berg4c476992010-10-04 21:36:35 +02004941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4942 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004943 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004944 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004945 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004946 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004947
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004948 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4949 return -EINVAL;
4950
4951 if (!info->attrs[NL80211_ATTR_MAC])
4952 return -EINVAL;
4953
4954 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4955 return -EINVAL;
4956
Johannes Berg4c476992010-10-04 21:36:35 +02004957 if (!rdev->ops->deauth)
4958 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004959
Johannes Berg074ac8d2010-09-16 14:58:22 +02004960 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004961 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4962 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004963
Johannes Berg19957bb2009-07-02 17:20:43 +02004964 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004965
Johannes Berg19957bb2009-07-02 17:20:43 +02004966 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4967 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004968 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004969 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004970 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004971
4972 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004973 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4974 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004975 }
4976
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004977 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4978
Johannes Berg4c476992010-10-04 21:36:35 +02004979 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4980 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004981}
4982
4983static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4984{
Johannes Berg4c476992010-10-04 21:36:35 +02004985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4986 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004987 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004988 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004989 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004990 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004991
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004992 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4993 return -EINVAL;
4994
4995 if (!info->attrs[NL80211_ATTR_MAC])
4996 return -EINVAL;
4997
4998 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4999 return -EINVAL;
5000
Johannes Berg4c476992010-10-04 21:36:35 +02005001 if (!rdev->ops->disassoc)
5002 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005003
Johannes Berg074ac8d2010-09-16 14:58:22 +02005004 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005005 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5006 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005007
Johannes Berg19957bb2009-07-02 17:20:43 +02005008 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005009
Johannes Berg19957bb2009-07-02 17:20:43 +02005010 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5011 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005012 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005013 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005014 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005015
5016 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005017 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5018 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005019 }
5020
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005021 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5022
Johannes Berg4c476992010-10-04 21:36:35 +02005023 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5024 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005025}
5026
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005027static bool
5028nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5029 int mcast_rate[IEEE80211_NUM_BANDS],
5030 int rateval)
5031{
5032 struct wiphy *wiphy = &rdev->wiphy;
5033 bool found = false;
5034 int band, i;
5035
5036 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5037 struct ieee80211_supported_band *sband;
5038
5039 sband = wiphy->bands[band];
5040 if (!sband)
5041 continue;
5042
5043 for (i = 0; i < sband->n_bitrates; i++) {
5044 if (sband->bitrates[i].bitrate == rateval) {
5045 mcast_rate[band] = i + 1;
5046 found = true;
5047 break;
5048 }
5049 }
5050 }
5051
5052 return found;
5053}
5054
Johannes Berg04a773a2009-04-19 21:24:32 +02005055static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5056{
Johannes Berg4c476992010-10-04 21:36:35 +02005057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5058 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005059 struct cfg80211_ibss_params ibss;
5060 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005061 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005062 int err;
5063
Johannes Berg8e30bc52009-04-22 17:45:38 +02005064 memset(&ibss, 0, sizeof(ibss));
5065
Johannes Berg04a773a2009-04-19 21:24:32 +02005066 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5067 return -EINVAL;
5068
5069 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5070 !info->attrs[NL80211_ATTR_SSID] ||
5071 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5072 return -EINVAL;
5073
Johannes Berg8e30bc52009-04-22 17:45:38 +02005074 ibss.beacon_interval = 100;
5075
5076 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5077 ibss.beacon_interval =
5078 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5079 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5080 return -EINVAL;
5081 }
5082
Johannes Berg4c476992010-10-04 21:36:35 +02005083 if (!rdev->ops->join_ibss)
5084 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005085
Johannes Berg4c476992010-10-04 21:36:35 +02005086 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5087 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005088
Johannes Berg79c97e92009-07-07 03:56:12 +02005089 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005090
Johannes Berg39193492011-09-16 13:45:25 +02005091 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005092 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005093
5094 if (!is_valid_ether_addr(ibss.bssid))
5095 return -EINVAL;
5096 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005097 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5098 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5099
5100 if (info->attrs[NL80211_ATTR_IE]) {
5101 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5102 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5103 }
5104
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005105 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5106 enum nl80211_channel_type channel_type;
5107
Johannes Bergcd6c6592012-05-10 21:27:18 +02005108 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005109 return -EINVAL;
5110
5111 if (channel_type != NL80211_CHAN_NO_HT &&
5112 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5113 return -EINVAL;
5114
5115 ibss.channel_type = channel_type;
5116 } else {
5117 ibss.channel_type = NL80211_CHAN_NO_HT;
5118 }
5119
5120 ibss.channel = rdev_freq_to_chan(rdev,
5121 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5122 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005123 if (!ibss.channel ||
5124 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005125 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5126 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005127
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005128 /* Both channels should be able to initiate communication */
5129 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5130 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5131 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5132 ibss.channel_type))
5133 return -EINVAL;
5134
Johannes Berg04a773a2009-04-19 21:24:32 +02005135 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005136 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005137
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005138 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5139 u8 *rates =
5140 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5141 int n_rates =
5142 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5143 struct ieee80211_supported_band *sband =
5144 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005145
Johannes Berg34850ab2011-07-18 18:08:35 +02005146 err = ieee80211_get_ratemask(sband, rates, n_rates,
5147 &ibss.basic_rates);
5148 if (err)
5149 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005150 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005151
5152 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5153 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5154 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5155 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005156
Johannes Berg4c476992010-10-04 21:36:35 +02005157 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5158 connkeys = nl80211_parse_connkeys(rdev,
5159 info->attrs[NL80211_ATTR_KEYS]);
5160 if (IS_ERR(connkeys))
5161 return PTR_ERR(connkeys);
5162 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005163
Antonio Quartulli267335d2012-01-31 20:25:47 +01005164 ibss.control_port =
5165 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5166
Johannes Berg4c476992010-10-04 21:36:35 +02005167 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005168 if (err)
5169 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005170 return err;
5171}
5172
5173static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5174{
Johannes Berg4c476992010-10-04 21:36:35 +02005175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5176 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005177
Johannes Berg4c476992010-10-04 21:36:35 +02005178 if (!rdev->ops->leave_ibss)
5179 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005180
Johannes Berg4c476992010-10-04 21:36:35 +02005181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5182 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005183
Johannes Berg4c476992010-10-04 21:36:35 +02005184 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005185}
5186
Johannes Bergaff89a92009-07-01 21:26:51 +02005187#ifdef CONFIG_NL80211_TESTMODE
5188static struct genl_multicast_group nl80211_testmode_mcgrp = {
5189 .name = "testmode",
5190};
5191
5192static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5193{
Johannes Berg4c476992010-10-04 21:36:35 +02005194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005195 int err;
5196
5197 if (!info->attrs[NL80211_ATTR_TESTDATA])
5198 return -EINVAL;
5199
Johannes Bergaff89a92009-07-01 21:26:51 +02005200 err = -EOPNOTSUPP;
5201 if (rdev->ops->testmode_cmd) {
5202 rdev->testmode_info = info;
5203 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5204 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5205 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5206 rdev->testmode_info = NULL;
5207 }
5208
Johannes Bergaff89a92009-07-01 21:26:51 +02005209 return err;
5210}
5211
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005212static int nl80211_testmode_dump(struct sk_buff *skb,
5213 struct netlink_callback *cb)
5214{
Johannes Berg00918d32011-12-13 17:22:05 +01005215 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005216 int err;
5217 long phy_idx;
5218 void *data = NULL;
5219 int data_len = 0;
5220
5221 if (cb->args[0]) {
5222 /*
5223 * 0 is a valid index, but not valid for args[0],
5224 * so we need to offset by 1.
5225 */
5226 phy_idx = cb->args[0] - 1;
5227 } else {
5228 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5229 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5230 nl80211_policy);
5231 if (err)
5232 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005233 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
5234 phy_idx = nla_get_u32(
5235 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
5236 } else {
5237 struct net_device *netdev;
5238
5239 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
5240 nl80211_fam.attrbuf,
5241 &rdev, &netdev);
5242 if (err)
5243 return err;
5244 dev_put(netdev);
5245 phy_idx = rdev->wiphy_idx;
5246 cfg80211_unlock_rdev(rdev);
5247 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005248 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5249 cb->args[1] =
5250 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5251 }
5252
5253 if (cb->args[1]) {
5254 data = nla_data((void *)cb->args[1]);
5255 data_len = nla_len((void *)cb->args[1]);
5256 }
5257
5258 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005259 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5260 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005261 mutex_unlock(&cfg80211_mutex);
5262 return -ENOENT;
5263 }
Johannes Berg00918d32011-12-13 17:22:05 +01005264 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005265 mutex_unlock(&cfg80211_mutex);
5266
Johannes Berg00918d32011-12-13 17:22:05 +01005267 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005268 err = -EOPNOTSUPP;
5269 goto out_err;
5270 }
5271
5272 while (1) {
5273 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5274 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5275 NL80211_CMD_TESTMODE);
5276 struct nlattr *tmdata;
5277
David S. Miller9360ffd2012-03-29 04:41:26 -04005278 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005279 genlmsg_cancel(skb, hdr);
5280 break;
5281 }
5282
5283 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5284 if (!tmdata) {
5285 genlmsg_cancel(skb, hdr);
5286 break;
5287 }
Johannes Berg00918d32011-12-13 17:22:05 +01005288 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5289 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005290 nla_nest_end(skb, tmdata);
5291
5292 if (err == -ENOBUFS || err == -ENOENT) {
5293 genlmsg_cancel(skb, hdr);
5294 break;
5295 } else if (err) {
5296 genlmsg_cancel(skb, hdr);
5297 goto out_err;
5298 }
5299
5300 genlmsg_end(skb, hdr);
5301 }
5302
5303 err = skb->len;
5304 /* see above */
5305 cb->args[0] = phy_idx + 1;
5306 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005307 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005308 return err;
5309}
5310
Johannes Bergaff89a92009-07-01 21:26:51 +02005311static struct sk_buff *
5312__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5313 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5314{
5315 struct sk_buff *skb;
5316 void *hdr;
5317 struct nlattr *data;
5318
5319 skb = nlmsg_new(approxlen + 100, gfp);
5320 if (!skb)
5321 return NULL;
5322
5323 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5324 if (!hdr) {
5325 kfree_skb(skb);
5326 return NULL;
5327 }
5328
David S. Miller9360ffd2012-03-29 04:41:26 -04005329 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5330 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005331 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5332
5333 ((void **)skb->cb)[0] = rdev;
5334 ((void **)skb->cb)[1] = hdr;
5335 ((void **)skb->cb)[2] = data;
5336
5337 return skb;
5338
5339 nla_put_failure:
5340 kfree_skb(skb);
5341 return NULL;
5342}
5343
5344struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5345 int approxlen)
5346{
5347 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5348
5349 if (WARN_ON(!rdev->testmode_info))
5350 return NULL;
5351
5352 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5353 rdev->testmode_info->snd_pid,
5354 rdev->testmode_info->snd_seq,
5355 GFP_KERNEL);
5356}
5357EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5358
5359int cfg80211_testmode_reply(struct sk_buff *skb)
5360{
5361 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5362 void *hdr = ((void **)skb->cb)[1];
5363 struct nlattr *data = ((void **)skb->cb)[2];
5364
5365 if (WARN_ON(!rdev->testmode_info)) {
5366 kfree_skb(skb);
5367 return -EINVAL;
5368 }
5369
5370 nla_nest_end(skb, data);
5371 genlmsg_end(skb, hdr);
5372 return genlmsg_reply(skb, rdev->testmode_info);
5373}
5374EXPORT_SYMBOL(cfg80211_testmode_reply);
5375
5376struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5377 int approxlen, gfp_t gfp)
5378{
5379 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5380
5381 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5382}
5383EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5384
5385void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5386{
5387 void *hdr = ((void **)skb->cb)[1];
5388 struct nlattr *data = ((void **)skb->cb)[2];
5389
5390 nla_nest_end(skb, data);
5391 genlmsg_end(skb, hdr);
5392 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5393}
5394EXPORT_SYMBOL(cfg80211_testmode_event);
5395#endif
5396
Samuel Ortizb23aa672009-07-01 21:26:54 +02005397static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5398{
Johannes Berg4c476992010-10-04 21:36:35 +02005399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5400 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005401 struct cfg80211_connect_params connect;
5402 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005403 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005404 int err;
5405
5406 memset(&connect, 0, sizeof(connect));
5407
5408 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5409 return -EINVAL;
5410
5411 if (!info->attrs[NL80211_ATTR_SSID] ||
5412 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5413 return -EINVAL;
5414
5415 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5416 connect.auth_type =
5417 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5418 if (!nl80211_valid_auth_type(connect.auth_type))
5419 return -EINVAL;
5420 } else
5421 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5422
5423 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5424
Johannes Bergc0692b82010-08-27 14:26:53 +03005425 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005426 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005427 if (err)
5428 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005429
Johannes Berg074ac8d2010-09-16 14:58:22 +02005430 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005431 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5432 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005433
Johannes Berg79c97e92009-07-07 03:56:12 +02005434 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005435
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305436 connect.bg_scan_period = -1;
5437 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5438 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5439 connect.bg_scan_period =
5440 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5441 }
5442
Samuel Ortizb23aa672009-07-01 21:26:54 +02005443 if (info->attrs[NL80211_ATTR_MAC])
5444 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5445 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5446 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5447
5448 if (info->attrs[NL80211_ATTR_IE]) {
5449 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5450 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5451 }
5452
5453 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5454 connect.channel =
5455 ieee80211_get_channel(wiphy,
5456 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5457 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005458 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5459 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005460 }
5461
Johannes Bergfffd0932009-07-08 14:22:54 +02005462 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5463 connkeys = nl80211_parse_connkeys(rdev,
5464 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005465 if (IS_ERR(connkeys))
5466 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005467 }
5468
Ben Greear7e7c8922011-11-18 11:31:59 -08005469 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5470 connect.flags |= ASSOC_REQ_DISABLE_HT;
5471
5472 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5473 memcpy(&connect.ht_capa_mask,
5474 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5475 sizeof(connect.ht_capa_mask));
5476
5477 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5478 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5479 return -EINVAL;
5480 memcpy(&connect.ht_capa,
5481 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5482 sizeof(connect.ht_capa));
5483 }
5484
Johannes Bergfffd0932009-07-08 14:22:54 +02005485 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005486 if (err)
5487 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005488 return err;
5489}
5490
5491static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5492{
Johannes Berg4c476992010-10-04 21:36:35 +02005493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5494 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005495 u16 reason;
5496
5497 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5498 reason = WLAN_REASON_DEAUTH_LEAVING;
5499 else
5500 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5501
5502 if (reason == 0)
5503 return -EINVAL;
5504
Johannes Berg074ac8d2010-09-16 14:58:22 +02005505 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005506 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5507 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005508
Johannes Berg4c476992010-10-04 21:36:35 +02005509 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005510}
5511
Johannes Berg463d0182009-07-14 00:33:35 +02005512static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5513{
Johannes Berg4c476992010-10-04 21:36:35 +02005514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005515 struct net *net;
5516 int err;
5517 u32 pid;
5518
5519 if (!info->attrs[NL80211_ATTR_PID])
5520 return -EINVAL;
5521
5522 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5523
Johannes Berg463d0182009-07-14 00:33:35 +02005524 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005525 if (IS_ERR(net))
5526 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005527
5528 err = 0;
5529
5530 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005531 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5532 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005533
Johannes Berg463d0182009-07-14 00:33:35 +02005534 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005535 return err;
5536}
5537
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005538static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5539{
Johannes Berg4c476992010-10-04 21:36:35 +02005540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005541 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5542 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005543 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005544 struct cfg80211_pmksa pmksa;
5545
5546 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5547
5548 if (!info->attrs[NL80211_ATTR_MAC])
5549 return -EINVAL;
5550
5551 if (!info->attrs[NL80211_ATTR_PMKID])
5552 return -EINVAL;
5553
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005554 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5555 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5556
Johannes Berg074ac8d2010-09-16 14:58:22 +02005557 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005558 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5559 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005560
5561 switch (info->genlhdr->cmd) {
5562 case NL80211_CMD_SET_PMKSA:
5563 rdev_ops = rdev->ops->set_pmksa;
5564 break;
5565 case NL80211_CMD_DEL_PMKSA:
5566 rdev_ops = rdev->ops->del_pmksa;
5567 break;
5568 default:
5569 WARN_ON(1);
5570 break;
5571 }
5572
Johannes Berg4c476992010-10-04 21:36:35 +02005573 if (!rdev_ops)
5574 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005575
Johannes Berg4c476992010-10-04 21:36:35 +02005576 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005577}
5578
5579static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5580{
Johannes Berg4c476992010-10-04 21:36:35 +02005581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5582 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005583
Johannes Berg074ac8d2010-09-16 14:58:22 +02005584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005585 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5586 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005587
Johannes Berg4c476992010-10-04 21:36:35 +02005588 if (!rdev->ops->flush_pmksa)
5589 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005590
Johannes Berg4c476992010-10-04 21:36:35 +02005591 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005592}
5593
Arik Nemtsov109086c2011-09-28 14:12:50 +03005594static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5595{
5596 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5597 struct net_device *dev = info->user_ptr[1];
5598 u8 action_code, dialog_token;
5599 u16 status_code;
5600 u8 *peer;
5601
5602 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5603 !rdev->ops->tdls_mgmt)
5604 return -EOPNOTSUPP;
5605
5606 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5607 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5608 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5609 !info->attrs[NL80211_ATTR_IE] ||
5610 !info->attrs[NL80211_ATTR_MAC])
5611 return -EINVAL;
5612
5613 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5614 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5615 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5616 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5617
5618 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5619 dialog_token, status_code,
5620 nla_data(info->attrs[NL80211_ATTR_IE]),
5621 nla_len(info->attrs[NL80211_ATTR_IE]));
5622}
5623
5624static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5625{
5626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5627 struct net_device *dev = info->user_ptr[1];
5628 enum nl80211_tdls_operation operation;
5629 u8 *peer;
5630
5631 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5632 !rdev->ops->tdls_oper)
5633 return -EOPNOTSUPP;
5634
5635 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5636 !info->attrs[NL80211_ATTR_MAC])
5637 return -EINVAL;
5638
5639 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5640 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5641
5642 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5643}
5644
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005645static int nl80211_remain_on_channel(struct sk_buff *skb,
5646 struct genl_info *info)
5647{
Johannes Berg4c476992010-10-04 21:36:35 +02005648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5649 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005650 struct ieee80211_channel *chan;
5651 struct sk_buff *msg;
5652 void *hdr;
5653 u64 cookie;
5654 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5655 u32 freq, duration;
5656 int err;
5657
5658 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5659 !info->attrs[NL80211_ATTR_DURATION])
5660 return -EINVAL;
5661
5662 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5663
Johannes Berg7c4ef712011-11-18 15:33:48 +01005664 if (!rdev->ops->remain_on_channel ||
5665 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005666 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005667
Johannes Bergebf348f2012-06-01 12:50:54 +02005668 /*
5669 * We should be on that channel for at least a minimum amount of
5670 * time (10ms) but no longer than the driver supports.
5671 */
5672 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5673 duration > rdev->wiphy.max_remain_on_channel_duration)
5674 return -EINVAL;
5675
Johannes Bergcd6c6592012-05-10 21:27:18 +02005676 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5677 !nl80211_valid_channel_type(info, &channel_type))
5678 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005679
5680 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5681 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005682 if (chan == NULL)
5683 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005684
5685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005686 if (!msg)
5687 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005688
5689 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5690 NL80211_CMD_REMAIN_ON_CHANNEL);
5691
5692 if (IS_ERR(hdr)) {
5693 err = PTR_ERR(hdr);
5694 goto free_msg;
5695 }
5696
5697 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5698 channel_type, duration, &cookie);
5699
5700 if (err)
5701 goto free_msg;
5702
David S. Miller9360ffd2012-03-29 04:41:26 -04005703 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5704 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005705
5706 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005707
5708 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005709
5710 nla_put_failure:
5711 err = -ENOBUFS;
5712 free_msg:
5713 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005714 return err;
5715}
5716
5717static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5718 struct genl_info *info)
5719{
Johannes Berg4c476992010-10-04 21:36:35 +02005720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5721 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005722 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005723
5724 if (!info->attrs[NL80211_ATTR_COOKIE])
5725 return -EINVAL;
5726
Johannes Berg4c476992010-10-04 21:36:35 +02005727 if (!rdev->ops->cancel_remain_on_channel)
5728 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005729
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005730 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5731
Johannes Berg4c476992010-10-04 21:36:35 +02005732 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005733}
5734
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005735static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5736 u8 *rates, u8 rates_len)
5737{
5738 u8 i;
5739 u32 mask = 0;
5740
5741 for (i = 0; i < rates_len; i++) {
5742 int rate = (rates[i] & 0x7f) * 5;
5743 int ridx;
5744 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5745 struct ieee80211_rate *srate =
5746 &sband->bitrates[ridx];
5747 if (rate == srate->bitrate) {
5748 mask |= 1 << ridx;
5749 break;
5750 }
5751 }
5752 if (ridx == sband->n_bitrates)
5753 return 0; /* rate not found */
5754 }
5755
5756 return mask;
5757}
5758
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005759static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5760 u8 *rates, u8 rates_len,
5761 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5762{
5763 u8 i;
5764
5765 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5766
5767 for (i = 0; i < rates_len; i++) {
5768 int ridx, rbit;
5769
5770 ridx = rates[i] / 8;
5771 rbit = BIT(rates[i] % 8);
5772
5773 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005774 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005775 return false;
5776
5777 /* check availability */
5778 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5779 mcs[ridx] |= rbit;
5780 else
5781 return false;
5782 }
5783
5784 return true;
5785}
5786
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005787static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005788 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5789 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005790 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5791 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005792};
5793
5794static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5795 struct genl_info *info)
5796{
5797 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005799 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005800 int rem, i;
5801 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005802 struct nlattr *tx_rates;
5803 struct ieee80211_supported_band *sband;
5804
5805 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5806 return -EINVAL;
5807
Johannes Berg4c476992010-10-04 21:36:35 +02005808 if (!rdev->ops->set_bitrate_mask)
5809 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005810
5811 memset(&mask, 0, sizeof(mask));
5812 /* Default to all rates enabled */
5813 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5814 sband = rdev->wiphy.bands[i];
5815 mask.control[i].legacy =
5816 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005817 if (sband)
5818 memcpy(mask.control[i].mcs,
5819 sband->ht_cap.mcs.rx_mask,
5820 sizeof(mask.control[i].mcs));
5821 else
5822 memset(mask.control[i].mcs, 0,
5823 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005824 }
5825
5826 /*
5827 * The nested attribute uses enum nl80211_band as the index. This maps
5828 * directly to the enum ieee80211_band values used in cfg80211.
5829 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005830 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005831 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5832 {
5833 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005834 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5835 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005836 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005837 if (sband == NULL)
5838 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005839 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5840 nla_len(tx_rates), nl80211_txattr_policy);
5841 if (tb[NL80211_TXRATE_LEGACY]) {
5842 mask.control[band].legacy = rateset_to_mask(
5843 sband,
5844 nla_data(tb[NL80211_TXRATE_LEGACY]),
5845 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305846 if ((mask.control[band].legacy == 0) &&
5847 nla_len(tb[NL80211_TXRATE_LEGACY]))
5848 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005849 }
5850 if (tb[NL80211_TXRATE_MCS]) {
5851 if (!ht_rateset_to_mask(
5852 sband,
5853 nla_data(tb[NL80211_TXRATE_MCS]),
5854 nla_len(tb[NL80211_TXRATE_MCS]),
5855 mask.control[band].mcs))
5856 return -EINVAL;
5857 }
5858
5859 if (mask.control[band].legacy == 0) {
5860 /* don't allow empty legacy rates if HT
5861 * is not even supported. */
5862 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5863 return -EINVAL;
5864
5865 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5866 if (mask.control[band].mcs[i])
5867 break;
5868
5869 /* legacy and mcs rates may not be both empty */
5870 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005871 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005872 }
5873 }
5874
Johannes Berg4c476992010-10-04 21:36:35 +02005875 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005876}
5877
Johannes Berg2e161f72010-08-12 15:38:38 +02005878static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005879{
Johannes Berg4c476992010-10-04 21:36:35 +02005880 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5881 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005882 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005883
5884 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5885 return -EINVAL;
5886
Johannes Berg2e161f72010-08-12 15:38:38 +02005887 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5888 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005889
Johannes Berg9d38d852010-06-09 17:20:33 +02005890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5894 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005895 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005896 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5897 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005898
5899 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005900 if (!rdev->ops->mgmt_tx)
5901 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005902
Johannes Berg4c476992010-10-04 21:36:35 +02005903 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005904 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005905 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5906 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005907}
5908
Johannes Berg2e161f72010-08-12 15:38:38 +02005909static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005910{
Johannes Berg4c476992010-10-04 21:36:35 +02005911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5912 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005913 struct ieee80211_channel *chan;
5914 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005915 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005916 u32 freq;
5917 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005918 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005919 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005920 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005921 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005922 bool offchan, no_cck, dont_wait_for_ack;
5923
5924 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005925
5926 if (!info->attrs[NL80211_ATTR_FRAME] ||
5927 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5928 return -EINVAL;
5929
Johannes Berg4c476992010-10-04 21:36:35 +02005930 if (!rdev->ops->mgmt_tx)
5931 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005932
Johannes Berg9d38d852010-06-09 17:20:33 +02005933 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005935 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5936 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005938 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005939 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5940 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005941
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005942 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005943 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005944 return -EINVAL;
5945 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005946
5947 /*
5948 * We should wait on the channel for at least a minimum amount
5949 * of time (10ms) but no longer than the driver supports.
5950 */
5951 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5952 wait > rdev->wiphy.max_remain_on_channel_duration)
5953 return -EINVAL;
5954
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005955 }
5956
Jouni Malinen026331c2010-02-15 12:53:10 +02005957 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005958 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005959 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005960 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005961 }
5962
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005963 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5964
Johannes Berg7c4ef712011-11-18 15:33:48 +01005965 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5966 return -EINVAL;
5967
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305968 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5969
Jouni Malinen026331c2010-02-15 12:53:10 +02005970 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5971 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005972 if (chan == NULL)
5973 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005974
Johannes Berge247bd902011-11-04 11:18:21 +01005975 if (!dont_wait_for_ack) {
5976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5977 if (!msg)
5978 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005979
Johannes Berge247bd902011-11-04 11:18:21 +01005980 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5981 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005982
Johannes Berge247bd902011-11-04 11:18:21 +01005983 if (IS_ERR(hdr)) {
5984 err = PTR_ERR(hdr);
5985 goto free_msg;
5986 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005987 }
Johannes Berge247bd902011-11-04 11:18:21 +01005988
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005989 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5990 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005991 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5992 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005993 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005994 if (err)
5995 goto free_msg;
5996
Johannes Berge247bd902011-11-04 11:18:21 +01005997 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04005998 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5999 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006000
Johannes Berge247bd902011-11-04 11:18:21 +01006001 genlmsg_end(msg, hdr);
6002 return genlmsg_reply(msg, info);
6003 }
6004
6005 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006006
6007 nla_put_failure:
6008 err = -ENOBUFS;
6009 free_msg:
6010 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006011 return err;
6012}
6013
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006014static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6015{
6016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6017 struct net_device *dev = info->user_ptr[1];
6018 u64 cookie;
6019
6020 if (!info->attrs[NL80211_ATTR_COOKIE])
6021 return -EINVAL;
6022
6023 if (!rdev->ops->mgmt_tx_cancel_wait)
6024 return -EOPNOTSUPP;
6025
6026 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6028 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6031 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6032 return -EOPNOTSUPP;
6033
6034 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6035
6036 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6037}
6038
Kalle Valoffb9eb32010-02-17 17:58:10 +02006039static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6040{
Johannes Berg4c476992010-10-04 21:36:35 +02006041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006042 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006043 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006044 u8 ps_state;
6045 bool state;
6046 int err;
6047
Johannes Berg4c476992010-10-04 21:36:35 +02006048 if (!info->attrs[NL80211_ATTR_PS_STATE])
6049 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006050
6051 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6052
Johannes Berg4c476992010-10-04 21:36:35 +02006053 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6054 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006055
6056 wdev = dev->ieee80211_ptr;
6057
Johannes Berg4c476992010-10-04 21:36:35 +02006058 if (!rdev->ops->set_power_mgmt)
6059 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006060
6061 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6062
6063 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006064 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006065
Johannes Berg4c476992010-10-04 21:36:35 +02006066 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6067 wdev->ps_timeout);
6068 if (!err)
6069 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006070 return err;
6071}
6072
6073static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6074{
Johannes Berg4c476992010-10-04 21:36:35 +02006075 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006076 enum nl80211_ps_state ps_state;
6077 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006078 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006079 struct sk_buff *msg;
6080 void *hdr;
6081 int err;
6082
Kalle Valoffb9eb32010-02-17 17:58:10 +02006083 wdev = dev->ieee80211_ptr;
6084
Johannes Berg4c476992010-10-04 21:36:35 +02006085 if (!rdev->ops->set_power_mgmt)
6086 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006087
6088 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006089 if (!msg)
6090 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006091
6092 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6093 NL80211_CMD_GET_POWER_SAVE);
6094 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006095 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006096 goto free_msg;
6097 }
6098
6099 if (wdev->ps)
6100 ps_state = NL80211_PS_ENABLED;
6101 else
6102 ps_state = NL80211_PS_DISABLED;
6103
David S. Miller9360ffd2012-03-29 04:41:26 -04006104 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6105 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006106
6107 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006108 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006109
Johannes Berg4c476992010-10-04 21:36:35 +02006110 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006111 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006112 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006113 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006114 return err;
6115}
6116
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006117static struct nla_policy
6118nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6119 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6120 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6121 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6122};
6123
6124static int nl80211_set_cqm_rssi(struct genl_info *info,
6125 s32 threshold, u32 hysteresis)
6126{
Johannes Berg4c476992010-10-04 21:36:35 +02006127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006128 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006129 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006130
6131 if (threshold > 0)
6132 return -EINVAL;
6133
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006134 wdev = dev->ieee80211_ptr;
6135
Johannes Berg4c476992010-10-04 21:36:35 +02006136 if (!rdev->ops->set_cqm_rssi_config)
6137 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006138
Johannes Berg074ac8d2010-09-16 14:58:22 +02006139 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006140 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6141 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006142
Johannes Berg4c476992010-10-04 21:36:35 +02006143 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6144 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006145}
6146
6147static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6148{
6149 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6150 struct nlattr *cqm;
6151 int err;
6152
6153 cqm = info->attrs[NL80211_ATTR_CQM];
6154 if (!cqm) {
6155 err = -EINVAL;
6156 goto out;
6157 }
6158
6159 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6160 nl80211_attr_cqm_policy);
6161 if (err)
6162 goto out;
6163
6164 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6165 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6166 s32 threshold;
6167 u32 hysteresis;
6168 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6169 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6170 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6171 } else
6172 err = -EINVAL;
6173
6174out:
6175 return err;
6176}
6177
Johannes Berg29cbe682010-12-03 09:20:44 +01006178static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6179{
6180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6181 struct net_device *dev = info->user_ptr[1];
6182 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006183 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006184 int err;
6185
6186 /* start with default */
6187 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006188 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006189
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006190 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006191 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006192 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006193 if (err)
6194 return err;
6195 }
6196
6197 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6198 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6199 return -EINVAL;
6200
Javier Cardonac80d5452010-12-16 17:37:49 -08006201 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6202 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6203
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006204 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6205 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6206 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6207 return -EINVAL;
6208
Javier Cardonac80d5452010-12-16 17:37:49 -08006209 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6210 /* parse additional setup parameters if given */
6211 err = nl80211_parse_mesh_setup(info, &setup);
6212 if (err)
6213 return err;
6214 }
6215
Johannes Bergcc1d2802012-05-16 23:50:20 +02006216 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6217 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6218
6219 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6220 !nl80211_valid_channel_type(info, &channel_type))
6221 return -EINVAL;
6222
6223 setup.channel = rdev_freq_to_chan(rdev,
6224 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6225 channel_type);
6226 if (!setup.channel)
6227 return -EINVAL;
6228 setup.channel_type = channel_type;
6229 } else {
6230 /* cfg80211_join_mesh() will sort it out */
6231 setup.channel = NULL;
6232 }
6233
Javier Cardonac80d5452010-12-16 17:37:49 -08006234 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006235}
6236
6237static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6238{
6239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6240 struct net_device *dev = info->user_ptr[1];
6241
6242 return cfg80211_leave_mesh(rdev, dev);
6243}
6244
Johannes Bergff1b6e62011-05-04 15:37:28 +02006245static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6246{
6247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6248 struct sk_buff *msg;
6249 void *hdr;
6250
6251 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6252 return -EOPNOTSUPP;
6253
6254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6255 if (!msg)
6256 return -ENOMEM;
6257
6258 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6259 NL80211_CMD_GET_WOWLAN);
6260 if (!hdr)
6261 goto nla_put_failure;
6262
6263 if (rdev->wowlan) {
6264 struct nlattr *nl_wowlan;
6265
6266 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6267 if (!nl_wowlan)
6268 goto nla_put_failure;
6269
David S. Miller9360ffd2012-03-29 04:41:26 -04006270 if ((rdev->wowlan->any &&
6271 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6272 (rdev->wowlan->disconnect &&
6273 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6274 (rdev->wowlan->magic_pkt &&
6275 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6276 (rdev->wowlan->gtk_rekey_failure &&
6277 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6278 (rdev->wowlan->eap_identity_req &&
6279 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6280 (rdev->wowlan->four_way_handshake &&
6281 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6282 (rdev->wowlan->rfkill_release &&
6283 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6284 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006285 if (rdev->wowlan->n_patterns) {
6286 struct nlattr *nl_pats, *nl_pat;
6287 int i, pat_len;
6288
6289 nl_pats = nla_nest_start(msg,
6290 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6291 if (!nl_pats)
6292 goto nla_put_failure;
6293
6294 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6295 nl_pat = nla_nest_start(msg, i + 1);
6296 if (!nl_pat)
6297 goto nla_put_failure;
6298 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006299 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6300 DIV_ROUND_UP(pat_len, 8),
6301 rdev->wowlan->patterns[i].mask) ||
6302 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6303 pat_len,
6304 rdev->wowlan->patterns[i].pattern))
6305 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006306 nla_nest_end(msg, nl_pat);
6307 }
6308 nla_nest_end(msg, nl_pats);
6309 }
6310
6311 nla_nest_end(msg, nl_wowlan);
6312 }
6313
6314 genlmsg_end(msg, hdr);
6315 return genlmsg_reply(msg, info);
6316
6317nla_put_failure:
6318 nlmsg_free(msg);
6319 return -ENOBUFS;
6320}
6321
6322static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6323{
6324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6325 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6326 struct cfg80211_wowlan no_triggers = {};
6327 struct cfg80211_wowlan new_triggers = {};
6328 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6329 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006330 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006331
6332 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6333 return -EOPNOTSUPP;
6334
6335 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6336 goto no_triggers;
6337
6338 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6339 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6340 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6341 nl80211_wowlan_policy);
6342 if (err)
6343 return err;
6344
6345 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6346 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6347 return -EINVAL;
6348 new_triggers.any = true;
6349 }
6350
6351 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6352 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6353 return -EINVAL;
6354 new_triggers.disconnect = true;
6355 }
6356
6357 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6358 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6359 return -EINVAL;
6360 new_triggers.magic_pkt = true;
6361 }
6362
Johannes Berg77dbbb12011-07-13 10:48:55 +02006363 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6364 return -EINVAL;
6365
6366 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6367 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6368 return -EINVAL;
6369 new_triggers.gtk_rekey_failure = true;
6370 }
6371
6372 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6373 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6374 return -EINVAL;
6375 new_triggers.eap_identity_req = true;
6376 }
6377
6378 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6379 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6380 return -EINVAL;
6381 new_triggers.four_way_handshake = true;
6382 }
6383
6384 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6385 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6386 return -EINVAL;
6387 new_triggers.rfkill_release = true;
6388 }
6389
Johannes Bergff1b6e62011-05-04 15:37:28 +02006390 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6391 struct nlattr *pat;
6392 int n_patterns = 0;
6393 int rem, pat_len, mask_len;
6394 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6395
6396 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6397 rem)
6398 n_patterns++;
6399 if (n_patterns > wowlan->n_patterns)
6400 return -EINVAL;
6401
6402 new_triggers.patterns = kcalloc(n_patterns,
6403 sizeof(new_triggers.patterns[0]),
6404 GFP_KERNEL);
6405 if (!new_triggers.patterns)
6406 return -ENOMEM;
6407
6408 new_triggers.n_patterns = n_patterns;
6409 i = 0;
6410
6411 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6412 rem) {
6413 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6414 nla_data(pat), nla_len(pat), NULL);
6415 err = -EINVAL;
6416 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6417 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6418 goto error;
6419 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6420 mask_len = DIV_ROUND_UP(pat_len, 8);
6421 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6422 mask_len)
6423 goto error;
6424 if (pat_len > wowlan->pattern_max_len ||
6425 pat_len < wowlan->pattern_min_len)
6426 goto error;
6427
6428 new_triggers.patterns[i].mask =
6429 kmalloc(mask_len + pat_len, GFP_KERNEL);
6430 if (!new_triggers.patterns[i].mask) {
6431 err = -ENOMEM;
6432 goto error;
6433 }
6434 new_triggers.patterns[i].pattern =
6435 new_triggers.patterns[i].mask + mask_len;
6436 memcpy(new_triggers.patterns[i].mask,
6437 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6438 mask_len);
6439 new_triggers.patterns[i].pattern_len = pat_len;
6440 memcpy(new_triggers.patterns[i].pattern,
6441 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6442 pat_len);
6443 i++;
6444 }
6445 }
6446
6447 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6448 struct cfg80211_wowlan *ntrig;
6449 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6450 GFP_KERNEL);
6451 if (!ntrig) {
6452 err = -ENOMEM;
6453 goto error;
6454 }
6455 cfg80211_rdev_free_wowlan(rdev);
6456 rdev->wowlan = ntrig;
6457 } else {
6458 no_triggers:
6459 cfg80211_rdev_free_wowlan(rdev);
6460 rdev->wowlan = NULL;
6461 }
6462
Johannes Berg6d525632012-04-04 15:05:25 +02006463 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6464 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6465
Johannes Bergff1b6e62011-05-04 15:37:28 +02006466 return 0;
6467 error:
6468 for (i = 0; i < new_triggers.n_patterns; i++)
6469 kfree(new_triggers.patterns[i].mask);
6470 kfree(new_triggers.patterns);
6471 return err;
6472}
6473
Johannes Berge5497d72011-07-05 16:35:40 +02006474static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6475{
6476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6477 struct net_device *dev = info->user_ptr[1];
6478 struct wireless_dev *wdev = dev->ieee80211_ptr;
6479 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6480 struct cfg80211_gtk_rekey_data rekey_data;
6481 int err;
6482
6483 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6484 return -EINVAL;
6485
6486 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6487 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6488 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6489 nl80211_rekey_policy);
6490 if (err)
6491 return err;
6492
6493 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6494 return -ERANGE;
6495 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6496 return -ERANGE;
6497 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6498 return -ERANGE;
6499
6500 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6501 NL80211_KEK_LEN);
6502 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6503 NL80211_KCK_LEN);
6504 memcpy(rekey_data.replay_ctr,
6505 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6506 NL80211_REPLAY_CTR_LEN);
6507
6508 wdev_lock(wdev);
6509 if (!wdev->current_bss) {
6510 err = -ENOTCONN;
6511 goto out;
6512 }
6513
6514 if (!rdev->ops->set_rekey_data) {
6515 err = -EOPNOTSUPP;
6516 goto out;
6517 }
6518
6519 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6520 out:
6521 wdev_unlock(wdev);
6522 return err;
6523}
6524
Johannes Berg28946da2011-11-04 11:18:12 +01006525static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6526 struct genl_info *info)
6527{
6528 struct net_device *dev = info->user_ptr[1];
6529 struct wireless_dev *wdev = dev->ieee80211_ptr;
6530
6531 if (wdev->iftype != NL80211_IFTYPE_AP &&
6532 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6533 return -EINVAL;
6534
6535 if (wdev->ap_unexpected_nlpid)
6536 return -EBUSY;
6537
6538 wdev->ap_unexpected_nlpid = info->snd_pid;
6539 return 0;
6540}
6541
Johannes Berg7f6cf312011-11-04 11:18:15 +01006542static int nl80211_probe_client(struct sk_buff *skb,
6543 struct genl_info *info)
6544{
6545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6546 struct net_device *dev = info->user_ptr[1];
6547 struct wireless_dev *wdev = dev->ieee80211_ptr;
6548 struct sk_buff *msg;
6549 void *hdr;
6550 const u8 *addr;
6551 u64 cookie;
6552 int err;
6553
6554 if (wdev->iftype != NL80211_IFTYPE_AP &&
6555 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6556 return -EOPNOTSUPP;
6557
6558 if (!info->attrs[NL80211_ATTR_MAC])
6559 return -EINVAL;
6560
6561 if (!rdev->ops->probe_client)
6562 return -EOPNOTSUPP;
6563
6564 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6565 if (!msg)
6566 return -ENOMEM;
6567
6568 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6569 NL80211_CMD_PROBE_CLIENT);
6570
6571 if (IS_ERR(hdr)) {
6572 err = PTR_ERR(hdr);
6573 goto free_msg;
6574 }
6575
6576 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6577
6578 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6579 if (err)
6580 goto free_msg;
6581
David S. Miller9360ffd2012-03-29 04:41:26 -04006582 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6583 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006584
6585 genlmsg_end(msg, hdr);
6586
6587 return genlmsg_reply(msg, info);
6588
6589 nla_put_failure:
6590 err = -ENOBUFS;
6591 free_msg:
6592 nlmsg_free(msg);
6593 return err;
6594}
6595
Johannes Berg5e7602302011-11-04 11:18:17 +01006596static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6597{
6598 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6599
6600 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6601 return -EOPNOTSUPP;
6602
6603 if (rdev->ap_beacons_nlpid)
6604 return -EBUSY;
6605
6606 rdev->ap_beacons_nlpid = info->snd_pid;
6607
6608 return 0;
6609}
6610
Johannes Berg4c476992010-10-04 21:36:35 +02006611#define NL80211_FLAG_NEED_WIPHY 0x01
6612#define NL80211_FLAG_NEED_NETDEV 0x02
6613#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006614#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6615#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6616 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006617
6618static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6619 struct genl_info *info)
6620{
6621 struct cfg80211_registered_device *rdev;
6622 struct net_device *dev;
6623 int err;
6624 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6625
6626 if (rtnl)
6627 rtnl_lock();
6628
6629 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006630 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006631 if (IS_ERR(rdev)) {
6632 if (rtnl)
6633 rtnl_unlock();
6634 return PTR_ERR(rdev);
6635 }
6636 info->user_ptr[0] = rdev;
6637 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006638 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6639 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006640 if (err) {
6641 if (rtnl)
6642 rtnl_unlock();
6643 return err;
6644 }
Johannes Berg41265712010-10-04 21:14:05 +02006645 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6646 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006647 cfg80211_unlock_rdev(rdev);
6648 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006649 if (rtnl)
6650 rtnl_unlock();
6651 return -ENETDOWN;
6652 }
Johannes Berg4c476992010-10-04 21:36:35 +02006653 info->user_ptr[0] = rdev;
6654 info->user_ptr[1] = dev;
6655 }
6656
6657 return 0;
6658}
6659
6660static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6661 struct genl_info *info)
6662{
6663 if (info->user_ptr[0])
6664 cfg80211_unlock_rdev(info->user_ptr[0]);
6665 if (info->user_ptr[1])
6666 dev_put(info->user_ptr[1]);
6667 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6668 rtnl_unlock();
6669}
6670
Johannes Berg55682962007-09-20 13:09:35 -04006671static struct genl_ops nl80211_ops[] = {
6672 {
6673 .cmd = NL80211_CMD_GET_WIPHY,
6674 .doit = nl80211_get_wiphy,
6675 .dumpit = nl80211_dump_wiphy,
6676 .policy = nl80211_policy,
6677 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006678 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006679 },
6680 {
6681 .cmd = NL80211_CMD_SET_WIPHY,
6682 .doit = nl80211_set_wiphy,
6683 .policy = nl80211_policy,
6684 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006685 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006686 },
6687 {
6688 .cmd = NL80211_CMD_GET_INTERFACE,
6689 .doit = nl80211_get_interface,
6690 .dumpit = nl80211_dump_interface,
6691 .policy = nl80211_policy,
6692 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006693 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006694 },
6695 {
6696 .cmd = NL80211_CMD_SET_INTERFACE,
6697 .doit = nl80211_set_interface,
6698 .policy = nl80211_policy,
6699 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006700 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6701 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006702 },
6703 {
6704 .cmd = NL80211_CMD_NEW_INTERFACE,
6705 .doit = nl80211_new_interface,
6706 .policy = nl80211_policy,
6707 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006708 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6709 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006710 },
6711 {
6712 .cmd = NL80211_CMD_DEL_INTERFACE,
6713 .doit = nl80211_del_interface,
6714 .policy = nl80211_policy,
6715 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006716 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6717 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006718 },
Johannes Berg41ade002007-12-19 02:03:29 +01006719 {
6720 .cmd = NL80211_CMD_GET_KEY,
6721 .doit = nl80211_get_key,
6722 .policy = nl80211_policy,
6723 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006724 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006725 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006726 },
6727 {
6728 .cmd = NL80211_CMD_SET_KEY,
6729 .doit = nl80211_set_key,
6730 .policy = nl80211_policy,
6731 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006732 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006733 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006734 },
6735 {
6736 .cmd = NL80211_CMD_NEW_KEY,
6737 .doit = nl80211_new_key,
6738 .policy = nl80211_policy,
6739 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006741 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006742 },
6743 {
6744 .cmd = NL80211_CMD_DEL_KEY,
6745 .doit = nl80211_del_key,
6746 .policy = nl80211_policy,
6747 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006748 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006749 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006750 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006751 {
6752 .cmd = NL80211_CMD_SET_BEACON,
6753 .policy = nl80211_policy,
6754 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006755 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006756 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006757 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006758 },
6759 {
Johannes Berg88600202012-02-13 15:17:18 +01006760 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006761 .policy = nl80211_policy,
6762 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006763 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006764 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006765 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006766 },
6767 {
Johannes Berg88600202012-02-13 15:17:18 +01006768 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006769 .policy = nl80211_policy,
6770 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006771 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006773 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006774 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006775 {
6776 .cmd = NL80211_CMD_GET_STATION,
6777 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006778 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006779 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006780 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6781 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006782 },
6783 {
6784 .cmd = NL80211_CMD_SET_STATION,
6785 .doit = nl80211_set_station,
6786 .policy = nl80211_policy,
6787 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006789 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006790 },
6791 {
6792 .cmd = NL80211_CMD_NEW_STATION,
6793 .doit = nl80211_new_station,
6794 .policy = nl80211_policy,
6795 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006797 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006798 },
6799 {
6800 .cmd = NL80211_CMD_DEL_STATION,
6801 .doit = nl80211_del_station,
6802 .policy = nl80211_policy,
6803 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006805 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006806 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006807 {
6808 .cmd = NL80211_CMD_GET_MPATH,
6809 .doit = nl80211_get_mpath,
6810 .dumpit = nl80211_dump_mpath,
6811 .policy = nl80211_policy,
6812 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006813 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006814 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006815 },
6816 {
6817 .cmd = NL80211_CMD_SET_MPATH,
6818 .doit = nl80211_set_mpath,
6819 .policy = nl80211_policy,
6820 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006822 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006823 },
6824 {
6825 .cmd = NL80211_CMD_NEW_MPATH,
6826 .doit = nl80211_new_mpath,
6827 .policy = nl80211_policy,
6828 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006830 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006831 },
6832 {
6833 .cmd = NL80211_CMD_DEL_MPATH,
6834 .doit = nl80211_del_mpath,
6835 .policy = nl80211_policy,
6836 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006838 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006839 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006840 {
6841 .cmd = NL80211_CMD_SET_BSS,
6842 .doit = nl80211_set_bss,
6843 .policy = nl80211_policy,
6844 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006846 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006847 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006848 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006849 .cmd = NL80211_CMD_GET_REG,
6850 .doit = nl80211_get_reg,
6851 .policy = nl80211_policy,
6852 /* can be retrieved by unprivileged users */
6853 },
6854 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006855 .cmd = NL80211_CMD_SET_REG,
6856 .doit = nl80211_set_reg,
6857 .policy = nl80211_policy,
6858 .flags = GENL_ADMIN_PERM,
6859 },
6860 {
6861 .cmd = NL80211_CMD_REQ_SET_REG,
6862 .doit = nl80211_req_set_reg,
6863 .policy = nl80211_policy,
6864 .flags = GENL_ADMIN_PERM,
6865 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006866 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006867 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6868 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006869 .policy = nl80211_policy,
6870 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006872 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006873 },
6874 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006875 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6876 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006877 .policy = nl80211_policy,
6878 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006880 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006881 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006882 {
Johannes Berg2a519312009-02-10 21:25:55 +01006883 .cmd = NL80211_CMD_TRIGGER_SCAN,
6884 .doit = nl80211_trigger_scan,
6885 .policy = nl80211_policy,
6886 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006888 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006889 },
6890 {
6891 .cmd = NL80211_CMD_GET_SCAN,
6892 .policy = nl80211_policy,
6893 .dumpit = nl80211_dump_scan,
6894 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006895 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006896 .cmd = NL80211_CMD_START_SCHED_SCAN,
6897 .doit = nl80211_start_sched_scan,
6898 .policy = nl80211_policy,
6899 .flags = GENL_ADMIN_PERM,
6900 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6901 NL80211_FLAG_NEED_RTNL,
6902 },
6903 {
6904 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6905 .doit = nl80211_stop_sched_scan,
6906 .policy = nl80211_policy,
6907 .flags = GENL_ADMIN_PERM,
6908 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6909 NL80211_FLAG_NEED_RTNL,
6910 },
6911 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006912 .cmd = NL80211_CMD_AUTHENTICATE,
6913 .doit = nl80211_authenticate,
6914 .policy = nl80211_policy,
6915 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006917 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006918 },
6919 {
6920 .cmd = NL80211_CMD_ASSOCIATE,
6921 .doit = nl80211_associate,
6922 .policy = nl80211_policy,
6923 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006925 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006926 },
6927 {
6928 .cmd = NL80211_CMD_DEAUTHENTICATE,
6929 .doit = nl80211_deauthenticate,
6930 .policy = nl80211_policy,
6931 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006932 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006933 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006934 },
6935 {
6936 .cmd = NL80211_CMD_DISASSOCIATE,
6937 .doit = nl80211_disassociate,
6938 .policy = nl80211_policy,
6939 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006940 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006941 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006942 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006943 {
6944 .cmd = NL80211_CMD_JOIN_IBSS,
6945 .doit = nl80211_join_ibss,
6946 .policy = nl80211_policy,
6947 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006949 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006950 },
6951 {
6952 .cmd = NL80211_CMD_LEAVE_IBSS,
6953 .doit = nl80211_leave_ibss,
6954 .policy = nl80211_policy,
6955 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006956 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006957 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006958 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006959#ifdef CONFIG_NL80211_TESTMODE
6960 {
6961 .cmd = NL80211_CMD_TESTMODE,
6962 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006963 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006964 .policy = nl80211_policy,
6965 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006966 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6967 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006968 },
6969#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006970 {
6971 .cmd = NL80211_CMD_CONNECT,
6972 .doit = nl80211_connect,
6973 .policy = nl80211_policy,
6974 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006976 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006977 },
6978 {
6979 .cmd = NL80211_CMD_DISCONNECT,
6980 .doit = nl80211_disconnect,
6981 .policy = nl80211_policy,
6982 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006984 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006985 },
Johannes Berg463d0182009-07-14 00:33:35 +02006986 {
6987 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6988 .doit = nl80211_wiphy_netns,
6989 .policy = nl80211_policy,
6990 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006991 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6992 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006993 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006994 {
6995 .cmd = NL80211_CMD_GET_SURVEY,
6996 .policy = nl80211_policy,
6997 .dumpit = nl80211_dump_survey,
6998 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006999 {
7000 .cmd = NL80211_CMD_SET_PMKSA,
7001 .doit = nl80211_setdel_pmksa,
7002 .policy = nl80211_policy,
7003 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007004 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007005 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007006 },
7007 {
7008 .cmd = NL80211_CMD_DEL_PMKSA,
7009 .doit = nl80211_setdel_pmksa,
7010 .policy = nl80211_policy,
7011 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007012 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007013 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007014 },
7015 {
7016 .cmd = NL80211_CMD_FLUSH_PMKSA,
7017 .doit = nl80211_flush_pmksa,
7018 .policy = nl80211_policy,
7019 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007021 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007022 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007023 {
7024 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7025 .doit = nl80211_remain_on_channel,
7026 .policy = nl80211_policy,
7027 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007028 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007029 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007030 },
7031 {
7032 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7033 .doit = nl80211_cancel_remain_on_channel,
7034 .policy = nl80211_policy,
7035 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007037 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007038 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007039 {
7040 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7041 .doit = nl80211_set_tx_bitrate_mask,
7042 .policy = nl80211_policy,
7043 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007044 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7045 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007046 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007047 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007048 .cmd = NL80211_CMD_REGISTER_FRAME,
7049 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007050 .policy = nl80211_policy,
7051 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007052 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7053 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007054 },
7055 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007056 .cmd = NL80211_CMD_FRAME,
7057 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007058 .policy = nl80211_policy,
7059 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007061 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007062 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007063 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007064 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7065 .doit = nl80211_tx_mgmt_cancel_wait,
7066 .policy = nl80211_policy,
7067 .flags = GENL_ADMIN_PERM,
7068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7069 NL80211_FLAG_NEED_RTNL,
7070 },
7071 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007072 .cmd = NL80211_CMD_SET_POWER_SAVE,
7073 .doit = nl80211_set_power_save,
7074 .policy = nl80211_policy,
7075 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007076 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7077 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007078 },
7079 {
7080 .cmd = NL80211_CMD_GET_POWER_SAVE,
7081 .doit = nl80211_get_power_save,
7082 .policy = nl80211_policy,
7083 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007084 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7085 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007086 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007087 {
7088 .cmd = NL80211_CMD_SET_CQM,
7089 .doit = nl80211_set_cqm,
7090 .policy = nl80211_policy,
7091 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007092 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7093 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007094 },
Johannes Bergf444de02010-05-05 15:25:02 +02007095 {
7096 .cmd = NL80211_CMD_SET_CHANNEL,
7097 .doit = nl80211_set_channel,
7098 .policy = nl80211_policy,
7099 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007100 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7101 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007102 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007103 {
7104 .cmd = NL80211_CMD_SET_WDS_PEER,
7105 .doit = nl80211_set_wds_peer,
7106 .policy = nl80211_policy,
7107 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007108 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7109 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007110 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007111 {
7112 .cmd = NL80211_CMD_JOIN_MESH,
7113 .doit = nl80211_join_mesh,
7114 .policy = nl80211_policy,
7115 .flags = GENL_ADMIN_PERM,
7116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7117 NL80211_FLAG_NEED_RTNL,
7118 },
7119 {
7120 .cmd = NL80211_CMD_LEAVE_MESH,
7121 .doit = nl80211_leave_mesh,
7122 .policy = nl80211_policy,
7123 .flags = GENL_ADMIN_PERM,
7124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7125 NL80211_FLAG_NEED_RTNL,
7126 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02007127 {
7128 .cmd = NL80211_CMD_GET_WOWLAN,
7129 .doit = nl80211_get_wowlan,
7130 .policy = nl80211_policy,
7131 /* can be retrieved by unprivileged users */
7132 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7133 NL80211_FLAG_NEED_RTNL,
7134 },
7135 {
7136 .cmd = NL80211_CMD_SET_WOWLAN,
7137 .doit = nl80211_set_wowlan,
7138 .policy = nl80211_policy,
7139 .flags = GENL_ADMIN_PERM,
7140 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7141 NL80211_FLAG_NEED_RTNL,
7142 },
Johannes Berge5497d72011-07-05 16:35:40 +02007143 {
7144 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7145 .doit = nl80211_set_rekey_data,
7146 .policy = nl80211_policy,
7147 .flags = GENL_ADMIN_PERM,
7148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7149 NL80211_FLAG_NEED_RTNL,
7150 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007151 {
7152 .cmd = NL80211_CMD_TDLS_MGMT,
7153 .doit = nl80211_tdls_mgmt,
7154 .policy = nl80211_policy,
7155 .flags = GENL_ADMIN_PERM,
7156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7157 NL80211_FLAG_NEED_RTNL,
7158 },
7159 {
7160 .cmd = NL80211_CMD_TDLS_OPER,
7161 .doit = nl80211_tdls_oper,
7162 .policy = nl80211_policy,
7163 .flags = GENL_ADMIN_PERM,
7164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7165 NL80211_FLAG_NEED_RTNL,
7166 },
Johannes Berg28946da2011-11-04 11:18:12 +01007167 {
7168 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7169 .doit = nl80211_register_unexpected_frame,
7170 .policy = nl80211_policy,
7171 .flags = GENL_ADMIN_PERM,
7172 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7173 NL80211_FLAG_NEED_RTNL,
7174 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007175 {
7176 .cmd = NL80211_CMD_PROBE_CLIENT,
7177 .doit = nl80211_probe_client,
7178 .policy = nl80211_policy,
7179 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007180 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007181 NL80211_FLAG_NEED_RTNL,
7182 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007183 {
7184 .cmd = NL80211_CMD_REGISTER_BEACONS,
7185 .doit = nl80211_register_beacons,
7186 .policy = nl80211_policy,
7187 .flags = GENL_ADMIN_PERM,
7188 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7189 NL80211_FLAG_NEED_RTNL,
7190 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007191 {
7192 .cmd = NL80211_CMD_SET_NOACK_MAP,
7193 .doit = nl80211_set_noack_map,
7194 .policy = nl80211_policy,
7195 .flags = GENL_ADMIN_PERM,
7196 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7197 NL80211_FLAG_NEED_RTNL,
7198 },
7199
Johannes Berg55682962007-09-20 13:09:35 -04007200};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007201
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007202static struct genl_multicast_group nl80211_mlme_mcgrp = {
7203 .name = "mlme",
7204};
Johannes Berg55682962007-09-20 13:09:35 -04007205
7206/* multicast groups */
7207static struct genl_multicast_group nl80211_config_mcgrp = {
7208 .name = "config",
7209};
Johannes Berg2a519312009-02-10 21:25:55 +01007210static struct genl_multicast_group nl80211_scan_mcgrp = {
7211 .name = "scan",
7212};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007213static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7214 .name = "regulatory",
7215};
Johannes Berg55682962007-09-20 13:09:35 -04007216
7217/* notification functions */
7218
7219void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7220{
7221 struct sk_buff *msg;
7222
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007224 if (!msg)
7225 return;
7226
7227 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7228 nlmsg_free(msg);
7229 return;
7230 }
7231
Johannes Berg463d0182009-07-14 00:33:35 +02007232 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7233 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007234}
7235
Johannes Berg362a4152009-05-24 16:43:15 +02007236static int nl80211_add_scan_req(struct sk_buff *msg,
7237 struct cfg80211_registered_device *rdev)
7238{
7239 struct cfg80211_scan_request *req = rdev->scan_req;
7240 struct nlattr *nest;
7241 int i;
7242
Johannes Berg667503dd2009-07-07 03:56:11 +02007243 ASSERT_RDEV_LOCK(rdev);
7244
Johannes Berg362a4152009-05-24 16:43:15 +02007245 if (WARN_ON(!req))
7246 return 0;
7247
7248 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7249 if (!nest)
7250 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007251 for (i = 0; i < req->n_ssids; i++) {
7252 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7253 goto nla_put_failure;
7254 }
Johannes Berg362a4152009-05-24 16:43:15 +02007255 nla_nest_end(msg, nest);
7256
7257 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7258 if (!nest)
7259 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007260 for (i = 0; i < req->n_channels; i++) {
7261 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7262 goto nla_put_failure;
7263 }
Johannes Berg362a4152009-05-24 16:43:15 +02007264 nla_nest_end(msg, nest);
7265
David S. Miller9360ffd2012-03-29 04:41:26 -04007266 if (req->ie &&
7267 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7268 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007269
7270 return 0;
7271 nla_put_failure:
7272 return -ENOBUFS;
7273}
7274
Johannes Berga538e2d2009-06-16 19:56:42 +02007275static int nl80211_send_scan_msg(struct sk_buff *msg,
7276 struct cfg80211_registered_device *rdev,
7277 struct net_device *netdev,
7278 u32 pid, u32 seq, int flags,
7279 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007280{
7281 void *hdr;
7282
7283 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7284 if (!hdr)
7285 return -1;
7286
David S. Miller9360ffd2012-03-29 04:41:26 -04007287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7289 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007290
Johannes Berg362a4152009-05-24 16:43:15 +02007291 /* ignore errors and send incomplete event anyway */
7292 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007293
7294 return genlmsg_end(msg, hdr);
7295
7296 nla_put_failure:
7297 genlmsg_cancel(msg, hdr);
7298 return -EMSGSIZE;
7299}
7300
Luciano Coelho807f8a82011-05-11 17:09:35 +03007301static int
7302nl80211_send_sched_scan_msg(struct sk_buff *msg,
7303 struct cfg80211_registered_device *rdev,
7304 struct net_device *netdev,
7305 u32 pid, u32 seq, int flags, u32 cmd)
7306{
7307 void *hdr;
7308
7309 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7310 if (!hdr)
7311 return -1;
7312
David S. Miller9360ffd2012-03-29 04:41:26 -04007313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7314 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7315 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007316
7317 return genlmsg_end(msg, hdr);
7318
7319 nla_put_failure:
7320 genlmsg_cancel(msg, hdr);
7321 return -EMSGSIZE;
7322}
7323
Johannes Berga538e2d2009-06-16 19:56:42 +02007324void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7325 struct net_device *netdev)
7326{
7327 struct sk_buff *msg;
7328
7329 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7330 if (!msg)
7331 return;
7332
7333 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7334 NL80211_CMD_TRIGGER_SCAN) < 0) {
7335 nlmsg_free(msg);
7336 return;
7337 }
7338
Johannes Berg463d0182009-07-14 00:33:35 +02007339 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7340 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007341}
7342
Johannes Berg2a519312009-02-10 21:25:55 +01007343void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7344 struct net_device *netdev)
7345{
7346 struct sk_buff *msg;
7347
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007348 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007349 if (!msg)
7350 return;
7351
Johannes Berga538e2d2009-06-16 19:56:42 +02007352 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7353 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007354 nlmsg_free(msg);
7355 return;
7356 }
7357
Johannes Berg463d0182009-07-14 00:33:35 +02007358 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7359 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007360}
7361
7362void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7363 struct net_device *netdev)
7364{
7365 struct sk_buff *msg;
7366
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007367 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007368 if (!msg)
7369 return;
7370
Johannes Berga538e2d2009-06-16 19:56:42 +02007371 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7372 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007373 nlmsg_free(msg);
7374 return;
7375 }
7376
Johannes Berg463d0182009-07-14 00:33:35 +02007377 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7378 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007379}
7380
Luciano Coelho807f8a82011-05-11 17:09:35 +03007381void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7382 struct net_device *netdev)
7383{
7384 struct sk_buff *msg;
7385
7386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7387 if (!msg)
7388 return;
7389
7390 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7391 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7392 nlmsg_free(msg);
7393 return;
7394 }
7395
7396 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7397 nl80211_scan_mcgrp.id, GFP_KERNEL);
7398}
7399
7400void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7401 struct net_device *netdev, u32 cmd)
7402{
7403 struct sk_buff *msg;
7404
7405 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7406 if (!msg)
7407 return;
7408
7409 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7410 nlmsg_free(msg);
7411 return;
7412 }
7413
7414 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7415 nl80211_scan_mcgrp.id, GFP_KERNEL);
7416}
7417
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007418/*
7419 * This can happen on global regulatory changes or device specific settings
7420 * based on custom world regulatory domains.
7421 */
7422void nl80211_send_reg_change_event(struct regulatory_request *request)
7423{
7424 struct sk_buff *msg;
7425 void *hdr;
7426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007428 if (!msg)
7429 return;
7430
7431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7432 if (!hdr) {
7433 nlmsg_free(msg);
7434 return;
7435 }
7436
7437 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007438 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7439 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007440
David S. Miller9360ffd2012-03-29 04:41:26 -04007441 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7442 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7443 NL80211_REGDOM_TYPE_WORLD))
7444 goto nla_put_failure;
7445 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7446 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7447 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7448 goto nla_put_failure;
7449 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7450 request->intersect) {
7451 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7452 NL80211_REGDOM_TYPE_INTERSECTION))
7453 goto nla_put_failure;
7454 } else {
7455 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7456 NL80211_REGDOM_TYPE_COUNTRY) ||
7457 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7458 request->alpha2))
7459 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007460 }
7461
David S. Miller9360ffd2012-03-29 04:41:26 -04007462 if (wiphy_idx_valid(request->wiphy_idx) &&
7463 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7464 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007465
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007466 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007467
Johannes Bergbc43b282009-07-25 10:54:13 +02007468 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007469 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007470 GFP_ATOMIC);
7471 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007472
7473 return;
7474
7475nla_put_failure:
7476 genlmsg_cancel(msg, hdr);
7477 nlmsg_free(msg);
7478}
7479
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007480static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7481 struct net_device *netdev,
7482 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007483 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007484{
7485 struct sk_buff *msg;
7486 void *hdr;
7487
Johannes Berge6d6e342009-07-01 21:26:47 +02007488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007489 if (!msg)
7490 return;
7491
7492 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7493 if (!hdr) {
7494 nlmsg_free(msg);
7495 return;
7496 }
7497
David S. Miller9360ffd2012-03-29 04:41:26 -04007498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7499 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7500 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7501 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007502
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007503 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007504
Johannes Berg463d0182009-07-14 00:33:35 +02007505 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7506 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007507 return;
7508
7509 nla_put_failure:
7510 genlmsg_cancel(msg, hdr);
7511 nlmsg_free(msg);
7512}
7513
7514void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007515 struct net_device *netdev, const u8 *buf,
7516 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007517{
7518 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007519 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007520}
7521
7522void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7523 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007524 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007525{
Johannes Berge6d6e342009-07-01 21:26:47 +02007526 nl80211_send_mlme_event(rdev, netdev, buf, len,
7527 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007528}
7529
Jouni Malinen53b46b82009-03-27 20:53:56 +02007530void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007531 struct net_device *netdev, const u8 *buf,
7532 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007533{
7534 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007535 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007536}
7537
Jouni Malinen53b46b82009-03-27 20:53:56 +02007538void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7539 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007540 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007541{
7542 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007543 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007544}
7545
Jouni Malinencf4e5942010-12-16 00:52:40 +02007546void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7547 struct net_device *netdev, const u8 *buf,
7548 size_t len, gfp_t gfp)
7549{
7550 nl80211_send_mlme_event(rdev, netdev, buf, len,
7551 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7552}
7553
7554void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7555 struct net_device *netdev, const u8 *buf,
7556 size_t len, gfp_t gfp)
7557{
7558 nl80211_send_mlme_event(rdev, netdev, buf, len,
7559 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7560}
7561
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007562static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7563 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007564 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007565{
7566 struct sk_buff *msg;
7567 void *hdr;
7568
Johannes Berge6d6e342009-07-01 21:26:47 +02007569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007570 if (!msg)
7571 return;
7572
7573 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7574 if (!hdr) {
7575 nlmsg_free(msg);
7576 return;
7577 }
7578
David S. Miller9360ffd2012-03-29 04:41:26 -04007579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7580 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7581 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7582 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7583 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007584
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007585 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007586
Johannes Berg463d0182009-07-14 00:33:35 +02007587 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7588 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007589 return;
7590
7591 nla_put_failure:
7592 genlmsg_cancel(msg, hdr);
7593 nlmsg_free(msg);
7594}
7595
7596void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007597 struct net_device *netdev, const u8 *addr,
7598 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007599{
7600 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007601 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007602}
7603
7604void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007605 struct net_device *netdev, const u8 *addr,
7606 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007607{
Johannes Berge6d6e342009-07-01 21:26:47 +02007608 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7609 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007610}
7611
Samuel Ortizb23aa672009-07-01 21:26:54 +02007612void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7613 struct net_device *netdev, const u8 *bssid,
7614 const u8 *req_ie, size_t req_ie_len,
7615 const u8 *resp_ie, size_t resp_ie_len,
7616 u16 status, gfp_t gfp)
7617{
7618 struct sk_buff *msg;
7619 void *hdr;
7620
7621 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7622 if (!msg)
7623 return;
7624
7625 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7626 if (!hdr) {
7627 nlmsg_free(msg);
7628 return;
7629 }
7630
David S. Miller9360ffd2012-03-29 04:41:26 -04007631 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7632 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7633 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7634 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7635 (req_ie &&
7636 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7637 (resp_ie &&
7638 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7639 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007640
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007641 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007642
Johannes Berg463d0182009-07-14 00:33:35 +02007643 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7644 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007645 return;
7646
7647 nla_put_failure:
7648 genlmsg_cancel(msg, hdr);
7649 nlmsg_free(msg);
7650
7651}
7652
7653void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7654 struct net_device *netdev, const u8 *bssid,
7655 const u8 *req_ie, size_t req_ie_len,
7656 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7657{
7658 struct sk_buff *msg;
7659 void *hdr;
7660
7661 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7662 if (!msg)
7663 return;
7664
7665 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7666 if (!hdr) {
7667 nlmsg_free(msg);
7668 return;
7669 }
7670
David S. Miller9360ffd2012-03-29 04:41:26 -04007671 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7672 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7673 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7674 (req_ie &&
7675 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7676 (resp_ie &&
7677 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7678 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007679
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007680 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007681
Johannes Berg463d0182009-07-14 00:33:35 +02007682 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7683 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007684 return;
7685
7686 nla_put_failure:
7687 genlmsg_cancel(msg, hdr);
7688 nlmsg_free(msg);
7689
7690}
7691
7692void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7693 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007694 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007695{
7696 struct sk_buff *msg;
7697 void *hdr;
7698
Johannes Berg667503dd2009-07-07 03:56:11 +02007699 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007700 if (!msg)
7701 return;
7702
7703 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7704 if (!hdr) {
7705 nlmsg_free(msg);
7706 return;
7707 }
7708
David S. Miller9360ffd2012-03-29 04:41:26 -04007709 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7710 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7711 (from_ap && reason &&
7712 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7713 (from_ap &&
7714 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7715 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7716 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007717
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007718 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719
Johannes Berg463d0182009-07-14 00:33:35 +02007720 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7721 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007722 return;
7723
7724 nla_put_failure:
7725 genlmsg_cancel(msg, hdr);
7726 nlmsg_free(msg);
7727
7728}
7729
Johannes Berg04a773a2009-04-19 21:24:32 +02007730void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7731 struct net_device *netdev, const u8 *bssid,
7732 gfp_t gfp)
7733{
7734 struct sk_buff *msg;
7735 void *hdr;
7736
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007737 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007738 if (!msg)
7739 return;
7740
7741 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7742 if (!hdr) {
7743 nlmsg_free(msg);
7744 return;
7745 }
7746
David S. Miller9360ffd2012-03-29 04:41:26 -04007747 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7748 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7750 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007751
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007752 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007753
Johannes Berg463d0182009-07-14 00:33:35 +02007754 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7755 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007756 return;
7757
7758 nla_put_failure:
7759 genlmsg_cancel(msg, hdr);
7760 nlmsg_free(msg);
7761}
7762
Javier Cardonac93b5e72011-04-07 15:08:34 -07007763void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7764 struct net_device *netdev,
7765 const u8 *macaddr, const u8* ie, u8 ie_len,
7766 gfp_t gfp)
7767{
7768 struct sk_buff *msg;
7769 void *hdr;
7770
7771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7772 if (!msg)
7773 return;
7774
7775 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7776 if (!hdr) {
7777 nlmsg_free(msg);
7778 return;
7779 }
7780
David S. Miller9360ffd2012-03-29 04:41:26 -04007781 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7782 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7783 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7784 (ie_len && ie &&
7785 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7786 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007787
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007788 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007789
7790 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7791 nl80211_mlme_mcgrp.id, gfp);
7792 return;
7793
7794 nla_put_failure:
7795 genlmsg_cancel(msg, hdr);
7796 nlmsg_free(msg);
7797}
7798
Jouni Malinena3b8b052009-03-27 21:59:49 +02007799void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7800 struct net_device *netdev, const u8 *addr,
7801 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007802 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007803{
7804 struct sk_buff *msg;
7805 void *hdr;
7806
Johannes Berge6d6e342009-07-01 21:26:47 +02007807 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007808 if (!msg)
7809 return;
7810
7811 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7812 if (!hdr) {
7813 nlmsg_free(msg);
7814 return;
7815 }
7816
David S. Miller9360ffd2012-03-29 04:41:26 -04007817 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7818 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7819 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7820 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7821 (key_id != -1 &&
7822 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7823 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7824 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007825
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007826 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007827
Johannes Berg463d0182009-07-14 00:33:35 +02007828 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7829 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007830 return;
7831
7832 nla_put_failure:
7833 genlmsg_cancel(msg, hdr);
7834 nlmsg_free(msg);
7835}
7836
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007837void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7838 struct ieee80211_channel *channel_before,
7839 struct ieee80211_channel *channel_after)
7840{
7841 struct sk_buff *msg;
7842 void *hdr;
7843 struct nlattr *nl_freq;
7844
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007846 if (!msg)
7847 return;
7848
7849 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7850 if (!hdr) {
7851 nlmsg_free(msg);
7852 return;
7853 }
7854
7855 /*
7856 * Since we are applying the beacon hint to a wiphy we know its
7857 * wiphy_idx is valid
7858 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7860 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007861
7862 /* Before */
7863 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7864 if (!nl_freq)
7865 goto nla_put_failure;
7866 if (nl80211_msg_put_channel(msg, channel_before))
7867 goto nla_put_failure;
7868 nla_nest_end(msg, nl_freq);
7869
7870 /* After */
7871 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7872 if (!nl_freq)
7873 goto nla_put_failure;
7874 if (nl80211_msg_put_channel(msg, channel_after))
7875 goto nla_put_failure;
7876 nla_nest_end(msg, nl_freq);
7877
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007878 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007879
Johannes Berg463d0182009-07-14 00:33:35 +02007880 rcu_read_lock();
7881 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7882 GFP_ATOMIC);
7883 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007884
7885 return;
7886
7887nla_put_failure:
7888 genlmsg_cancel(msg, hdr);
7889 nlmsg_free(msg);
7890}
7891
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007892static void nl80211_send_remain_on_chan_event(
7893 int cmd, struct cfg80211_registered_device *rdev,
7894 struct net_device *netdev, u64 cookie,
7895 struct ieee80211_channel *chan,
7896 enum nl80211_channel_type channel_type,
7897 unsigned int duration, gfp_t gfp)
7898{
7899 struct sk_buff *msg;
7900 void *hdr;
7901
7902 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7903 if (!msg)
7904 return;
7905
7906 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7907 if (!hdr) {
7908 nlmsg_free(msg);
7909 return;
7910 }
7911
David S. Miller9360ffd2012-03-29 04:41:26 -04007912 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7913 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7914 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7915 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7916 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7917 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007918
David S. Miller9360ffd2012-03-29 04:41:26 -04007919 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7920 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7921 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007922
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007923 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007924
7925 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7926 nl80211_mlme_mcgrp.id, gfp);
7927 return;
7928
7929 nla_put_failure:
7930 genlmsg_cancel(msg, hdr);
7931 nlmsg_free(msg);
7932}
7933
7934void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7935 struct net_device *netdev, u64 cookie,
7936 struct ieee80211_channel *chan,
7937 enum nl80211_channel_type channel_type,
7938 unsigned int duration, gfp_t gfp)
7939{
7940 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7941 rdev, netdev, cookie, chan,
7942 channel_type, duration, gfp);
7943}
7944
7945void nl80211_send_remain_on_channel_cancel(
7946 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7947 u64 cookie, struct ieee80211_channel *chan,
7948 enum nl80211_channel_type channel_type, gfp_t gfp)
7949{
7950 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7951 rdev, netdev, cookie, chan,
7952 channel_type, 0, gfp);
7953}
7954
Johannes Berg98b62182009-12-23 13:15:44 +01007955void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7956 struct net_device *dev, const u8 *mac_addr,
7957 struct station_info *sinfo, gfp_t gfp)
7958{
7959 struct sk_buff *msg;
7960
7961 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7962 if (!msg)
7963 return;
7964
John W. Linville66266b32012-03-15 13:25:41 -04007965 if (nl80211_send_station(msg, 0, 0, 0,
7966 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007967 nlmsg_free(msg);
7968 return;
7969 }
7970
7971 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7972 nl80211_mlme_mcgrp.id, gfp);
7973}
7974
Jouni Malinenec15e682011-03-23 15:29:52 +02007975void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7976 struct net_device *dev, const u8 *mac_addr,
7977 gfp_t gfp)
7978{
7979 struct sk_buff *msg;
7980 void *hdr;
7981
7982 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7983 if (!msg)
7984 return;
7985
7986 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7987 if (!hdr) {
7988 nlmsg_free(msg);
7989 return;
7990 }
7991
David S. Miller9360ffd2012-03-29 04:41:26 -04007992 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7993 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
7994 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02007995
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007996 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007997
7998 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7999 nl80211_mlme_mcgrp.id, gfp);
8000 return;
8001
8002 nla_put_failure:
8003 genlmsg_cancel(msg, hdr);
8004 nlmsg_free(msg);
8005}
8006
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008007static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8008 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008009{
8010 struct wireless_dev *wdev = dev->ieee80211_ptr;
8011 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8012 struct sk_buff *msg;
8013 void *hdr;
8014 int err;
8015 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8016
8017 if (!nlpid)
8018 return false;
8019
8020 msg = nlmsg_new(100, gfp);
8021 if (!msg)
8022 return true;
8023
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008024 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008025 if (!hdr) {
8026 nlmsg_free(msg);
8027 return true;
8028 }
8029
David S. Miller9360ffd2012-03-29 04:41:26 -04008030 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8031 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8032 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8033 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008034
8035 err = genlmsg_end(msg, hdr);
8036 if (err < 0) {
8037 nlmsg_free(msg);
8038 return true;
8039 }
8040
8041 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8042 return true;
8043
8044 nla_put_failure:
8045 genlmsg_cancel(msg, hdr);
8046 nlmsg_free(msg);
8047 return true;
8048}
8049
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008050bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8051{
8052 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8053 addr, gfp);
8054}
8055
8056bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8057 const u8 *addr, gfp_t gfp)
8058{
8059 return __nl80211_unexpected_frame(dev,
8060 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8061 addr, gfp);
8062}
8063
Johannes Berg2e161f72010-08-12 15:38:38 +02008064int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8065 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008066 int freq, int sig_dbm,
8067 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008068{
8069 struct sk_buff *msg;
8070 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008071
8072 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8073 if (!msg)
8074 return -ENOMEM;
8075
Johannes Berg2e161f72010-08-12 15:38:38 +02008076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008077 if (!hdr) {
8078 nlmsg_free(msg);
8079 return -ENOMEM;
8080 }
8081
David S. Miller9360ffd2012-03-29 04:41:26 -04008082 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8083 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8084 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8085 (sig_dbm &&
8086 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8087 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8088 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008089
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008090 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008091
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008092 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008093
8094 nla_put_failure:
8095 genlmsg_cancel(msg, hdr);
8096 nlmsg_free(msg);
8097 return -ENOBUFS;
8098}
8099
Johannes Berg2e161f72010-08-12 15:38:38 +02008100void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8101 struct net_device *netdev, u64 cookie,
8102 const u8 *buf, size_t len, bool ack,
8103 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008104{
8105 struct sk_buff *msg;
8106 void *hdr;
8107
8108 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8109 if (!msg)
8110 return;
8111
Johannes Berg2e161f72010-08-12 15:38:38 +02008112 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008113 if (!hdr) {
8114 nlmsg_free(msg);
8115 return;
8116 }
8117
David S. Miller9360ffd2012-03-29 04:41:26 -04008118 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8119 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8120 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8121 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8122 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8123 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008124
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008125 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008126
8127 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8128 return;
8129
8130 nla_put_failure:
8131 genlmsg_cancel(msg, hdr);
8132 nlmsg_free(msg);
8133}
8134
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008135void
8136nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8137 struct net_device *netdev,
8138 enum nl80211_cqm_rssi_threshold_event rssi_event,
8139 gfp_t gfp)
8140{
8141 struct sk_buff *msg;
8142 struct nlattr *pinfoattr;
8143 void *hdr;
8144
8145 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8146 if (!msg)
8147 return;
8148
8149 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8150 if (!hdr) {
8151 nlmsg_free(msg);
8152 return;
8153 }
8154
David S. Miller9360ffd2012-03-29 04:41:26 -04008155 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8156 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8157 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008158
8159 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8160 if (!pinfoattr)
8161 goto nla_put_failure;
8162
David S. Miller9360ffd2012-03-29 04:41:26 -04008163 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8164 rssi_event))
8165 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008166
8167 nla_nest_end(msg, pinfoattr);
8168
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008169 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008170
8171 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8172 nl80211_mlme_mcgrp.id, gfp);
8173 return;
8174
8175 nla_put_failure:
8176 genlmsg_cancel(msg, hdr);
8177 nlmsg_free(msg);
8178}
8179
Johannes Berge5497d72011-07-05 16:35:40 +02008180void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8181 struct net_device *netdev, const u8 *bssid,
8182 const u8 *replay_ctr, gfp_t gfp)
8183{
8184 struct sk_buff *msg;
8185 struct nlattr *rekey_attr;
8186 void *hdr;
8187
8188 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8189 if (!msg)
8190 return;
8191
8192 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8193 if (!hdr) {
8194 nlmsg_free(msg);
8195 return;
8196 }
8197
David S. Miller9360ffd2012-03-29 04:41:26 -04008198 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8199 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8200 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8201 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008202
8203 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8204 if (!rekey_attr)
8205 goto nla_put_failure;
8206
David S. Miller9360ffd2012-03-29 04:41:26 -04008207 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8208 NL80211_REPLAY_CTR_LEN, replay_ctr))
8209 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008210
8211 nla_nest_end(msg, rekey_attr);
8212
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008213 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008214
8215 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8216 nl80211_mlme_mcgrp.id, gfp);
8217 return;
8218
8219 nla_put_failure:
8220 genlmsg_cancel(msg, hdr);
8221 nlmsg_free(msg);
8222}
8223
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008224void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8225 struct net_device *netdev, int index,
8226 const u8 *bssid, bool preauth, gfp_t gfp)
8227{
8228 struct sk_buff *msg;
8229 struct nlattr *attr;
8230 void *hdr;
8231
8232 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8233 if (!msg)
8234 return;
8235
8236 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8237 if (!hdr) {
8238 nlmsg_free(msg);
8239 return;
8240 }
8241
David S. Miller9360ffd2012-03-29 04:41:26 -04008242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8243 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8244 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008245
8246 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8247 if (!attr)
8248 goto nla_put_failure;
8249
David S. Miller9360ffd2012-03-29 04:41:26 -04008250 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8251 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8252 (preauth &&
8253 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8254 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008255
8256 nla_nest_end(msg, attr);
8257
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008258 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008259
8260 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8261 nl80211_mlme_mcgrp.id, gfp);
8262 return;
8263
8264 nla_put_failure:
8265 genlmsg_cancel(msg, hdr);
8266 nlmsg_free(msg);
8267}
8268
Thomas Pedersen53145262012-04-06 13:35:47 -07008269void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8270 struct net_device *netdev, int freq,
8271 enum nl80211_channel_type type, gfp_t gfp)
8272{
8273 struct sk_buff *msg;
8274 void *hdr;
8275
8276 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8277 if (!msg)
8278 return;
8279
8280 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8281 if (!hdr) {
8282 nlmsg_free(msg);
8283 return;
8284 }
8285
John W. Linville7eab0f62012-04-12 14:25:14 -04008286 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8287 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8288 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8289 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008290
8291 genlmsg_end(msg, hdr);
8292
8293 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8294 nl80211_mlme_mcgrp.id, gfp);
8295 return;
8296
8297 nla_put_failure:
8298 genlmsg_cancel(msg, hdr);
8299 nlmsg_free(msg);
8300}
8301
Johannes Bergc063dbf2010-11-24 08:10:05 +01008302void
8303nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8304 struct net_device *netdev, const u8 *peer,
8305 u32 num_packets, gfp_t gfp)
8306{
8307 struct sk_buff *msg;
8308 struct nlattr *pinfoattr;
8309 void *hdr;
8310
8311 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8312 if (!msg)
8313 return;
8314
8315 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8316 if (!hdr) {
8317 nlmsg_free(msg);
8318 return;
8319 }
8320
David S. Miller9360ffd2012-03-29 04:41:26 -04008321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8323 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8324 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008325
8326 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8327 if (!pinfoattr)
8328 goto nla_put_failure;
8329
David S. Miller9360ffd2012-03-29 04:41:26 -04008330 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8331 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008332
8333 nla_nest_end(msg, pinfoattr);
8334
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008335 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008336
8337 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8338 nl80211_mlme_mcgrp.id, gfp);
8339 return;
8340
8341 nla_put_failure:
8342 genlmsg_cancel(msg, hdr);
8343 nlmsg_free(msg);
8344}
8345
Johannes Berg7f6cf312011-11-04 11:18:15 +01008346void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8347 u64 cookie, bool acked, gfp_t gfp)
8348{
8349 struct wireless_dev *wdev = dev->ieee80211_ptr;
8350 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8351 struct sk_buff *msg;
8352 void *hdr;
8353 int err;
8354
8355 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8356 if (!msg)
8357 return;
8358
8359 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8360 if (!hdr) {
8361 nlmsg_free(msg);
8362 return;
8363 }
8364
David S. Miller9360ffd2012-03-29 04:41:26 -04008365 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8366 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8367 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8368 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8369 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8370 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008371
8372 err = genlmsg_end(msg, hdr);
8373 if (err < 0) {
8374 nlmsg_free(msg);
8375 return;
8376 }
8377
8378 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8379 nl80211_mlme_mcgrp.id, gfp);
8380 return;
8381
8382 nla_put_failure:
8383 genlmsg_cancel(msg, hdr);
8384 nlmsg_free(msg);
8385}
8386EXPORT_SYMBOL(cfg80211_probe_status);
8387
Johannes Berg5e7602302011-11-04 11:18:17 +01008388void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8389 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008390 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008391{
8392 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8393 struct sk_buff *msg;
8394 void *hdr;
8395 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8396
8397 if (!nlpid)
8398 return;
8399
8400 msg = nlmsg_new(len + 100, gfp);
8401 if (!msg)
8402 return;
8403
8404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8405 if (!hdr) {
8406 nlmsg_free(msg);
8407 return;
8408 }
8409
David S. Miller9360ffd2012-03-29 04:41:26 -04008410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8411 (freq &&
8412 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8413 (sig_dbm &&
8414 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8415 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8416 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008417
8418 genlmsg_end(msg, hdr);
8419
8420 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8421 return;
8422
8423 nla_put_failure:
8424 genlmsg_cancel(msg, hdr);
8425 nlmsg_free(msg);
8426}
8427EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8428
Jouni Malinen026331c2010-02-15 12:53:10 +02008429static int nl80211_netlink_notify(struct notifier_block * nb,
8430 unsigned long state,
8431 void *_notify)
8432{
8433 struct netlink_notify *notify = _notify;
8434 struct cfg80211_registered_device *rdev;
8435 struct wireless_dev *wdev;
8436
8437 if (state != NETLINK_URELEASE)
8438 return NOTIFY_DONE;
8439
8440 rcu_read_lock();
8441
Johannes Berg5e7602302011-11-04 11:18:17 +01008442 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008443 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008444 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008445 if (rdev->ap_beacons_nlpid == notify->pid)
8446 rdev->ap_beacons_nlpid = 0;
8447 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008448
8449 rcu_read_unlock();
8450
8451 return NOTIFY_DONE;
8452}
8453
8454static struct notifier_block nl80211_netlink_notifier = {
8455 .notifier_call = nl80211_netlink_notify,
8456};
8457
Johannes Berg55682962007-09-20 13:09:35 -04008458/* initialisation/exit functions */
8459
8460int nl80211_init(void)
8461{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008462 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008463
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008464 err = genl_register_family_with_ops(&nl80211_fam,
8465 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008466 if (err)
8467 return err;
8468
Johannes Berg55682962007-09-20 13:09:35 -04008469 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8470 if (err)
8471 goto err_out;
8472
Johannes Berg2a519312009-02-10 21:25:55 +01008473 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8474 if (err)
8475 goto err_out;
8476
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008477 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8478 if (err)
8479 goto err_out;
8480
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008481 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8482 if (err)
8483 goto err_out;
8484
Johannes Bergaff89a92009-07-01 21:26:51 +02008485#ifdef CONFIG_NL80211_TESTMODE
8486 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8487 if (err)
8488 goto err_out;
8489#endif
8490
Jouni Malinen026331c2010-02-15 12:53:10 +02008491 err = netlink_register_notifier(&nl80211_netlink_notifier);
8492 if (err)
8493 goto err_out;
8494
Johannes Berg55682962007-09-20 13:09:35 -04008495 return 0;
8496 err_out:
8497 genl_unregister_family(&nl80211_fam);
8498 return err;
8499}
8500
8501void nl80211_exit(void)
8502{
Jouni Malinen026331c2010-02-15 12:53:10 +02008503 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008504 genl_unregister_family(&nl80211_fam);
8505}