blob: 06623d0646061ad0563fe2449273b8b2dc64974f [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
Johannes Berg2bd7e352012-06-15 14:23:16 +02005234 mutex_lock(&cfg80211_mutex);
5235 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5236 nl80211_fam.attrbuf);
5237 if (IS_ERR(rdev)) {
5238 mutex_unlock(&cfg80211_mutex);
5239 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005240 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005241 phy_idx = rdev->wiphy_idx;
5242 rdev = NULL;
5243 mutex_unlock(&cfg80211_mutex);
5244
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005245 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5246 cb->args[1] =
5247 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5248 }
5249
5250 if (cb->args[1]) {
5251 data = nla_data((void *)cb->args[1]);
5252 data_len = nla_len((void *)cb->args[1]);
5253 }
5254
5255 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005256 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5257 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005258 mutex_unlock(&cfg80211_mutex);
5259 return -ENOENT;
5260 }
Johannes Berg00918d32011-12-13 17:22:05 +01005261 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005262 mutex_unlock(&cfg80211_mutex);
5263
Johannes Berg00918d32011-12-13 17:22:05 +01005264 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005265 err = -EOPNOTSUPP;
5266 goto out_err;
5267 }
5268
5269 while (1) {
5270 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5271 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5272 NL80211_CMD_TESTMODE);
5273 struct nlattr *tmdata;
5274
David S. Miller9360ffd2012-03-29 04:41:26 -04005275 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005276 genlmsg_cancel(skb, hdr);
5277 break;
5278 }
5279
5280 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5281 if (!tmdata) {
5282 genlmsg_cancel(skb, hdr);
5283 break;
5284 }
Johannes Berg00918d32011-12-13 17:22:05 +01005285 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5286 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005287 nla_nest_end(skb, tmdata);
5288
5289 if (err == -ENOBUFS || err == -ENOENT) {
5290 genlmsg_cancel(skb, hdr);
5291 break;
5292 } else if (err) {
5293 genlmsg_cancel(skb, hdr);
5294 goto out_err;
5295 }
5296
5297 genlmsg_end(skb, hdr);
5298 }
5299
5300 err = skb->len;
5301 /* see above */
5302 cb->args[0] = phy_idx + 1;
5303 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005304 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005305 return err;
5306}
5307
Johannes Bergaff89a92009-07-01 21:26:51 +02005308static struct sk_buff *
5309__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5310 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5311{
5312 struct sk_buff *skb;
5313 void *hdr;
5314 struct nlattr *data;
5315
5316 skb = nlmsg_new(approxlen + 100, gfp);
5317 if (!skb)
5318 return NULL;
5319
5320 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5321 if (!hdr) {
5322 kfree_skb(skb);
5323 return NULL;
5324 }
5325
David S. Miller9360ffd2012-03-29 04:41:26 -04005326 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5327 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005328 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5329
5330 ((void **)skb->cb)[0] = rdev;
5331 ((void **)skb->cb)[1] = hdr;
5332 ((void **)skb->cb)[2] = data;
5333
5334 return skb;
5335
5336 nla_put_failure:
5337 kfree_skb(skb);
5338 return NULL;
5339}
5340
5341struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5342 int approxlen)
5343{
5344 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5345
5346 if (WARN_ON(!rdev->testmode_info))
5347 return NULL;
5348
5349 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5350 rdev->testmode_info->snd_pid,
5351 rdev->testmode_info->snd_seq,
5352 GFP_KERNEL);
5353}
5354EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5355
5356int cfg80211_testmode_reply(struct sk_buff *skb)
5357{
5358 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5359 void *hdr = ((void **)skb->cb)[1];
5360 struct nlattr *data = ((void **)skb->cb)[2];
5361
5362 if (WARN_ON(!rdev->testmode_info)) {
5363 kfree_skb(skb);
5364 return -EINVAL;
5365 }
5366
5367 nla_nest_end(skb, data);
5368 genlmsg_end(skb, hdr);
5369 return genlmsg_reply(skb, rdev->testmode_info);
5370}
5371EXPORT_SYMBOL(cfg80211_testmode_reply);
5372
5373struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5374 int approxlen, gfp_t gfp)
5375{
5376 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5377
5378 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5379}
5380EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5381
5382void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5383{
5384 void *hdr = ((void **)skb->cb)[1];
5385 struct nlattr *data = ((void **)skb->cb)[2];
5386
5387 nla_nest_end(skb, data);
5388 genlmsg_end(skb, hdr);
5389 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5390}
5391EXPORT_SYMBOL(cfg80211_testmode_event);
5392#endif
5393
Samuel Ortizb23aa672009-07-01 21:26:54 +02005394static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5395{
Johannes Berg4c476992010-10-04 21:36:35 +02005396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5397 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005398 struct cfg80211_connect_params connect;
5399 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005400 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005401 int err;
5402
5403 memset(&connect, 0, sizeof(connect));
5404
5405 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5406 return -EINVAL;
5407
5408 if (!info->attrs[NL80211_ATTR_SSID] ||
5409 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5410 return -EINVAL;
5411
5412 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5413 connect.auth_type =
5414 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5415 if (!nl80211_valid_auth_type(connect.auth_type))
5416 return -EINVAL;
5417 } else
5418 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5419
5420 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5421
Johannes Bergc0692b82010-08-27 14:26:53 +03005422 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005423 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005424 if (err)
5425 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005426
Johannes Berg074ac8d2010-09-16 14:58:22 +02005427 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005428 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5429 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005430
Johannes Berg79c97e92009-07-07 03:56:12 +02005431 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005432
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305433 connect.bg_scan_period = -1;
5434 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5435 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5436 connect.bg_scan_period =
5437 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5438 }
5439
Samuel Ortizb23aa672009-07-01 21:26:54 +02005440 if (info->attrs[NL80211_ATTR_MAC])
5441 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5442 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5443 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5444
5445 if (info->attrs[NL80211_ATTR_IE]) {
5446 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5447 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5448 }
5449
5450 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5451 connect.channel =
5452 ieee80211_get_channel(wiphy,
5453 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5454 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005455 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5456 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005457 }
5458
Johannes Bergfffd0932009-07-08 14:22:54 +02005459 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5460 connkeys = nl80211_parse_connkeys(rdev,
5461 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005462 if (IS_ERR(connkeys))
5463 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005464 }
5465
Ben Greear7e7c8922011-11-18 11:31:59 -08005466 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5467 connect.flags |= ASSOC_REQ_DISABLE_HT;
5468
5469 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5470 memcpy(&connect.ht_capa_mask,
5471 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5472 sizeof(connect.ht_capa_mask));
5473
5474 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5475 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5476 return -EINVAL;
5477 memcpy(&connect.ht_capa,
5478 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5479 sizeof(connect.ht_capa));
5480 }
5481
Johannes Bergfffd0932009-07-08 14:22:54 +02005482 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005483 if (err)
5484 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005485 return err;
5486}
5487
5488static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5489{
Johannes Berg4c476992010-10-04 21:36:35 +02005490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5491 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005492 u16 reason;
5493
5494 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5495 reason = WLAN_REASON_DEAUTH_LEAVING;
5496 else
5497 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5498
5499 if (reason == 0)
5500 return -EINVAL;
5501
Johannes Berg074ac8d2010-09-16 14:58:22 +02005502 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005503 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5504 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005505
Johannes Berg4c476992010-10-04 21:36:35 +02005506 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005507}
5508
Johannes Berg463d0182009-07-14 00:33:35 +02005509static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5510{
Johannes Berg4c476992010-10-04 21:36:35 +02005511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005512 struct net *net;
5513 int err;
5514 u32 pid;
5515
5516 if (!info->attrs[NL80211_ATTR_PID])
5517 return -EINVAL;
5518
5519 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5520
Johannes Berg463d0182009-07-14 00:33:35 +02005521 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005522 if (IS_ERR(net))
5523 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005524
5525 err = 0;
5526
5527 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005528 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5529 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005530
Johannes Berg463d0182009-07-14 00:33:35 +02005531 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005532 return err;
5533}
5534
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005535static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5536{
Johannes Berg4c476992010-10-04 21:36:35 +02005537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005538 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5539 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005540 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005541 struct cfg80211_pmksa pmksa;
5542
5543 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5544
5545 if (!info->attrs[NL80211_ATTR_MAC])
5546 return -EINVAL;
5547
5548 if (!info->attrs[NL80211_ATTR_PMKID])
5549 return -EINVAL;
5550
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005551 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5552 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5553
Johannes Berg074ac8d2010-09-16 14:58:22 +02005554 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005555 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5556 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005557
5558 switch (info->genlhdr->cmd) {
5559 case NL80211_CMD_SET_PMKSA:
5560 rdev_ops = rdev->ops->set_pmksa;
5561 break;
5562 case NL80211_CMD_DEL_PMKSA:
5563 rdev_ops = rdev->ops->del_pmksa;
5564 break;
5565 default:
5566 WARN_ON(1);
5567 break;
5568 }
5569
Johannes Berg4c476992010-10-04 21:36:35 +02005570 if (!rdev_ops)
5571 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005572
Johannes Berg4c476992010-10-04 21:36:35 +02005573 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005574}
5575
5576static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5577{
Johannes Berg4c476992010-10-04 21:36:35 +02005578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5579 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005580
Johannes Berg074ac8d2010-09-16 14:58:22 +02005581 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005582 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5583 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005584
Johannes Berg4c476992010-10-04 21:36:35 +02005585 if (!rdev->ops->flush_pmksa)
5586 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005587
Johannes Berg4c476992010-10-04 21:36:35 +02005588 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005589}
5590
Arik Nemtsov109086c2011-09-28 14:12:50 +03005591static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5592{
5593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5594 struct net_device *dev = info->user_ptr[1];
5595 u8 action_code, dialog_token;
5596 u16 status_code;
5597 u8 *peer;
5598
5599 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5600 !rdev->ops->tdls_mgmt)
5601 return -EOPNOTSUPP;
5602
5603 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5604 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5605 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5606 !info->attrs[NL80211_ATTR_IE] ||
5607 !info->attrs[NL80211_ATTR_MAC])
5608 return -EINVAL;
5609
5610 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5611 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5612 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5613 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5614
5615 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5616 dialog_token, status_code,
5617 nla_data(info->attrs[NL80211_ATTR_IE]),
5618 nla_len(info->attrs[NL80211_ATTR_IE]));
5619}
5620
5621static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5622{
5623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5624 struct net_device *dev = info->user_ptr[1];
5625 enum nl80211_tdls_operation operation;
5626 u8 *peer;
5627
5628 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5629 !rdev->ops->tdls_oper)
5630 return -EOPNOTSUPP;
5631
5632 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5633 !info->attrs[NL80211_ATTR_MAC])
5634 return -EINVAL;
5635
5636 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5637 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5638
5639 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5640}
5641
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005642static int nl80211_remain_on_channel(struct sk_buff *skb,
5643 struct genl_info *info)
5644{
Johannes Berg4c476992010-10-04 21:36:35 +02005645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5646 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005647 struct ieee80211_channel *chan;
5648 struct sk_buff *msg;
5649 void *hdr;
5650 u64 cookie;
5651 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5652 u32 freq, duration;
5653 int err;
5654
5655 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5656 !info->attrs[NL80211_ATTR_DURATION])
5657 return -EINVAL;
5658
5659 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5660
Johannes Berg7c4ef712011-11-18 15:33:48 +01005661 if (!rdev->ops->remain_on_channel ||
5662 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005663 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005664
Johannes Bergebf348f2012-06-01 12:50:54 +02005665 /*
5666 * We should be on that channel for at least a minimum amount of
5667 * time (10ms) but no longer than the driver supports.
5668 */
5669 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5670 duration > rdev->wiphy.max_remain_on_channel_duration)
5671 return -EINVAL;
5672
Johannes Bergcd6c6592012-05-10 21:27:18 +02005673 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5674 !nl80211_valid_channel_type(info, &channel_type))
5675 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005676
5677 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5678 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005679 if (chan == NULL)
5680 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005681
5682 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005683 if (!msg)
5684 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005685
5686 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5687 NL80211_CMD_REMAIN_ON_CHANNEL);
5688
5689 if (IS_ERR(hdr)) {
5690 err = PTR_ERR(hdr);
5691 goto free_msg;
5692 }
5693
5694 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5695 channel_type, duration, &cookie);
5696
5697 if (err)
5698 goto free_msg;
5699
David S. Miller9360ffd2012-03-29 04:41:26 -04005700 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5701 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005702
5703 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005704
5705 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005706
5707 nla_put_failure:
5708 err = -ENOBUFS;
5709 free_msg:
5710 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005711 return err;
5712}
5713
5714static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5715 struct genl_info *info)
5716{
Johannes Berg4c476992010-10-04 21:36:35 +02005717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5718 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005719 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005720
5721 if (!info->attrs[NL80211_ATTR_COOKIE])
5722 return -EINVAL;
5723
Johannes Berg4c476992010-10-04 21:36:35 +02005724 if (!rdev->ops->cancel_remain_on_channel)
5725 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005726
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005727 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5728
Johannes Berg4c476992010-10-04 21:36:35 +02005729 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005730}
5731
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005732static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5733 u8 *rates, u8 rates_len)
5734{
5735 u8 i;
5736 u32 mask = 0;
5737
5738 for (i = 0; i < rates_len; i++) {
5739 int rate = (rates[i] & 0x7f) * 5;
5740 int ridx;
5741 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5742 struct ieee80211_rate *srate =
5743 &sband->bitrates[ridx];
5744 if (rate == srate->bitrate) {
5745 mask |= 1 << ridx;
5746 break;
5747 }
5748 }
5749 if (ridx == sband->n_bitrates)
5750 return 0; /* rate not found */
5751 }
5752
5753 return mask;
5754}
5755
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005756static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5757 u8 *rates, u8 rates_len,
5758 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5759{
5760 u8 i;
5761
5762 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5763
5764 for (i = 0; i < rates_len; i++) {
5765 int ridx, rbit;
5766
5767 ridx = rates[i] / 8;
5768 rbit = BIT(rates[i] % 8);
5769
5770 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005771 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005772 return false;
5773
5774 /* check availability */
5775 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5776 mcs[ridx] |= rbit;
5777 else
5778 return false;
5779 }
5780
5781 return true;
5782}
5783
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005784static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005785 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5786 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005787 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5788 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005789};
5790
5791static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5792 struct genl_info *info)
5793{
5794 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005796 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005797 int rem, i;
5798 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005799 struct nlattr *tx_rates;
5800 struct ieee80211_supported_band *sband;
5801
5802 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5803 return -EINVAL;
5804
Johannes Berg4c476992010-10-04 21:36:35 +02005805 if (!rdev->ops->set_bitrate_mask)
5806 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005807
5808 memset(&mask, 0, sizeof(mask));
5809 /* Default to all rates enabled */
5810 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5811 sband = rdev->wiphy.bands[i];
5812 mask.control[i].legacy =
5813 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005814 if (sband)
5815 memcpy(mask.control[i].mcs,
5816 sband->ht_cap.mcs.rx_mask,
5817 sizeof(mask.control[i].mcs));
5818 else
5819 memset(mask.control[i].mcs, 0,
5820 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005821 }
5822
5823 /*
5824 * The nested attribute uses enum nl80211_band as the index. This maps
5825 * directly to the enum ieee80211_band values used in cfg80211.
5826 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005827 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005828 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5829 {
5830 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005831 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5832 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005833 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005834 if (sband == NULL)
5835 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005836 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5837 nla_len(tx_rates), nl80211_txattr_policy);
5838 if (tb[NL80211_TXRATE_LEGACY]) {
5839 mask.control[band].legacy = rateset_to_mask(
5840 sband,
5841 nla_data(tb[NL80211_TXRATE_LEGACY]),
5842 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305843 if ((mask.control[band].legacy == 0) &&
5844 nla_len(tb[NL80211_TXRATE_LEGACY]))
5845 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005846 }
5847 if (tb[NL80211_TXRATE_MCS]) {
5848 if (!ht_rateset_to_mask(
5849 sband,
5850 nla_data(tb[NL80211_TXRATE_MCS]),
5851 nla_len(tb[NL80211_TXRATE_MCS]),
5852 mask.control[band].mcs))
5853 return -EINVAL;
5854 }
5855
5856 if (mask.control[band].legacy == 0) {
5857 /* don't allow empty legacy rates if HT
5858 * is not even supported. */
5859 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5860 return -EINVAL;
5861
5862 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5863 if (mask.control[band].mcs[i])
5864 break;
5865
5866 /* legacy and mcs rates may not be both empty */
5867 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005868 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005869 }
5870 }
5871
Johannes Berg4c476992010-10-04 21:36:35 +02005872 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005873}
5874
Johannes Berg2e161f72010-08-12 15:38:38 +02005875static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005876{
Johannes Berg4c476992010-10-04 21:36:35 +02005877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5878 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005879 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005880
5881 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5882 return -EINVAL;
5883
Johannes Berg2e161f72010-08-12 15:38:38 +02005884 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5885 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005886
Johannes Berg9d38d852010-06-09 17:20:33 +02005887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005889 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5890 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5894 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005895
5896 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005897 if (!rdev->ops->mgmt_tx)
5898 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005899
Johannes Berg4c476992010-10-04 21:36:35 +02005900 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005901 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005902 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5903 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005904}
5905
Johannes Berg2e161f72010-08-12 15:38:38 +02005906static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005907{
Johannes Berg4c476992010-10-04 21:36:35 +02005908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5909 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005910 struct ieee80211_channel *chan;
5911 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005912 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005913 u32 freq;
5914 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005915 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005916 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005917 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005918 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005919 bool offchan, no_cck, dont_wait_for_ack;
5920
5921 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005922
5923 if (!info->attrs[NL80211_ATTR_FRAME] ||
5924 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5925 return -EINVAL;
5926
Johannes Berg4c476992010-10-04 21:36:35 +02005927 if (!rdev->ops->mgmt_tx)
5928 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005929
Johannes Berg9d38d852010-06-09 17:20:33 +02005930 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005932 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005935 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005936 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5937 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005938
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005939 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005940 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005941 return -EINVAL;
5942 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005943
5944 /*
5945 * We should wait on the channel for at least a minimum amount
5946 * of time (10ms) but no longer than the driver supports.
5947 */
5948 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5949 wait > rdev->wiphy.max_remain_on_channel_duration)
5950 return -EINVAL;
5951
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005952 }
5953
Jouni Malinen026331c2010-02-15 12:53:10 +02005954 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005955 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005956 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005957 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005958 }
5959
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005960 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5961
Johannes Berg7c4ef712011-11-18 15:33:48 +01005962 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5963 return -EINVAL;
5964
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305965 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5966
Jouni Malinen026331c2010-02-15 12:53:10 +02005967 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5968 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005969 if (chan == NULL)
5970 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005971
Johannes Berge247bd902011-11-04 11:18:21 +01005972 if (!dont_wait_for_ack) {
5973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5974 if (!msg)
5975 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005976
Johannes Berge247bd902011-11-04 11:18:21 +01005977 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5978 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005979
Johannes Berge247bd902011-11-04 11:18:21 +01005980 if (IS_ERR(hdr)) {
5981 err = PTR_ERR(hdr);
5982 goto free_msg;
5983 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005984 }
Johannes Berge247bd902011-11-04 11:18:21 +01005985
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005986 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5987 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005988 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5989 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005990 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005991 if (err)
5992 goto free_msg;
5993
Johannes Berge247bd902011-11-04 11:18:21 +01005994 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04005995 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5996 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02005997
Johannes Berge247bd902011-11-04 11:18:21 +01005998 genlmsg_end(msg, hdr);
5999 return genlmsg_reply(msg, info);
6000 }
6001
6002 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006003
6004 nla_put_failure:
6005 err = -ENOBUFS;
6006 free_msg:
6007 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006008 return err;
6009}
6010
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006011static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6012{
6013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6014 struct net_device *dev = info->user_ptr[1];
6015 u64 cookie;
6016
6017 if (!info->attrs[NL80211_ATTR_COOKIE])
6018 return -EINVAL;
6019
6020 if (!rdev->ops->mgmt_tx_cancel_wait)
6021 return -EOPNOTSUPP;
6022
6023 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6025 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6028 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6029 return -EOPNOTSUPP;
6030
6031 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6032
6033 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6034}
6035
Kalle Valoffb9eb32010-02-17 17:58:10 +02006036static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6037{
Johannes Berg4c476992010-10-04 21:36:35 +02006038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006039 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006040 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006041 u8 ps_state;
6042 bool state;
6043 int err;
6044
Johannes Berg4c476992010-10-04 21:36:35 +02006045 if (!info->attrs[NL80211_ATTR_PS_STATE])
6046 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006047
6048 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6049
Johannes Berg4c476992010-10-04 21:36:35 +02006050 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6051 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006052
6053 wdev = dev->ieee80211_ptr;
6054
Johannes Berg4c476992010-10-04 21:36:35 +02006055 if (!rdev->ops->set_power_mgmt)
6056 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006057
6058 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6059
6060 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006061 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006062
Johannes Berg4c476992010-10-04 21:36:35 +02006063 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6064 wdev->ps_timeout);
6065 if (!err)
6066 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006067 return err;
6068}
6069
6070static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6071{
Johannes Berg4c476992010-10-04 21:36:35 +02006072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006073 enum nl80211_ps_state ps_state;
6074 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006075 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006076 struct sk_buff *msg;
6077 void *hdr;
6078 int err;
6079
Kalle Valoffb9eb32010-02-17 17:58:10 +02006080 wdev = dev->ieee80211_ptr;
6081
Johannes Berg4c476992010-10-04 21:36:35 +02006082 if (!rdev->ops->set_power_mgmt)
6083 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006084
6085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006086 if (!msg)
6087 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006088
6089 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6090 NL80211_CMD_GET_POWER_SAVE);
6091 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006092 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006093 goto free_msg;
6094 }
6095
6096 if (wdev->ps)
6097 ps_state = NL80211_PS_ENABLED;
6098 else
6099 ps_state = NL80211_PS_DISABLED;
6100
David S. Miller9360ffd2012-03-29 04:41:26 -04006101 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6102 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006103
6104 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006105 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006106
Johannes Berg4c476992010-10-04 21:36:35 +02006107 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006108 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006109 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006111 return err;
6112}
6113
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006114static struct nla_policy
6115nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6116 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6117 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6118 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6119};
6120
6121static int nl80211_set_cqm_rssi(struct genl_info *info,
6122 s32 threshold, u32 hysteresis)
6123{
Johannes Berg4c476992010-10-04 21:36:35 +02006124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006125 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006126 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006127
6128 if (threshold > 0)
6129 return -EINVAL;
6130
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006131 wdev = dev->ieee80211_ptr;
6132
Johannes Berg4c476992010-10-04 21:36:35 +02006133 if (!rdev->ops->set_cqm_rssi_config)
6134 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006135
Johannes Berg074ac8d2010-09-16 14:58:22 +02006136 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006137 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6138 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006139
Johannes Berg4c476992010-10-04 21:36:35 +02006140 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6141 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006142}
6143
6144static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6145{
6146 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6147 struct nlattr *cqm;
6148 int err;
6149
6150 cqm = info->attrs[NL80211_ATTR_CQM];
6151 if (!cqm) {
6152 err = -EINVAL;
6153 goto out;
6154 }
6155
6156 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6157 nl80211_attr_cqm_policy);
6158 if (err)
6159 goto out;
6160
6161 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6162 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6163 s32 threshold;
6164 u32 hysteresis;
6165 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6166 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6167 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6168 } else
6169 err = -EINVAL;
6170
6171out:
6172 return err;
6173}
6174
Johannes Berg29cbe682010-12-03 09:20:44 +01006175static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6176{
6177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6178 struct net_device *dev = info->user_ptr[1];
6179 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006180 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006181 int err;
6182
6183 /* start with default */
6184 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006185 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006186
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006187 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006188 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006189 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006190 if (err)
6191 return err;
6192 }
6193
6194 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6195 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6196 return -EINVAL;
6197
Javier Cardonac80d5452010-12-16 17:37:49 -08006198 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6199 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6200
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006201 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6202 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6203 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6204 return -EINVAL;
6205
Javier Cardonac80d5452010-12-16 17:37:49 -08006206 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6207 /* parse additional setup parameters if given */
6208 err = nl80211_parse_mesh_setup(info, &setup);
6209 if (err)
6210 return err;
6211 }
6212
Johannes Bergcc1d2802012-05-16 23:50:20 +02006213 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6214 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6215
6216 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6217 !nl80211_valid_channel_type(info, &channel_type))
6218 return -EINVAL;
6219
6220 setup.channel = rdev_freq_to_chan(rdev,
6221 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6222 channel_type);
6223 if (!setup.channel)
6224 return -EINVAL;
6225 setup.channel_type = channel_type;
6226 } else {
6227 /* cfg80211_join_mesh() will sort it out */
6228 setup.channel = NULL;
6229 }
6230
Javier Cardonac80d5452010-12-16 17:37:49 -08006231 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006232}
6233
6234static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6235{
6236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6237 struct net_device *dev = info->user_ptr[1];
6238
6239 return cfg80211_leave_mesh(rdev, dev);
6240}
6241
Johannes Bergff1b6e62011-05-04 15:37:28 +02006242static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6243{
6244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6245 struct sk_buff *msg;
6246 void *hdr;
6247
6248 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6249 return -EOPNOTSUPP;
6250
6251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6252 if (!msg)
6253 return -ENOMEM;
6254
6255 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6256 NL80211_CMD_GET_WOWLAN);
6257 if (!hdr)
6258 goto nla_put_failure;
6259
6260 if (rdev->wowlan) {
6261 struct nlattr *nl_wowlan;
6262
6263 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6264 if (!nl_wowlan)
6265 goto nla_put_failure;
6266
David S. Miller9360ffd2012-03-29 04:41:26 -04006267 if ((rdev->wowlan->any &&
6268 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6269 (rdev->wowlan->disconnect &&
6270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6271 (rdev->wowlan->magic_pkt &&
6272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6273 (rdev->wowlan->gtk_rekey_failure &&
6274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6275 (rdev->wowlan->eap_identity_req &&
6276 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6277 (rdev->wowlan->four_way_handshake &&
6278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6279 (rdev->wowlan->rfkill_release &&
6280 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6281 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006282 if (rdev->wowlan->n_patterns) {
6283 struct nlattr *nl_pats, *nl_pat;
6284 int i, pat_len;
6285
6286 nl_pats = nla_nest_start(msg,
6287 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6288 if (!nl_pats)
6289 goto nla_put_failure;
6290
6291 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6292 nl_pat = nla_nest_start(msg, i + 1);
6293 if (!nl_pat)
6294 goto nla_put_failure;
6295 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006296 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6297 DIV_ROUND_UP(pat_len, 8),
6298 rdev->wowlan->patterns[i].mask) ||
6299 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6300 pat_len,
6301 rdev->wowlan->patterns[i].pattern))
6302 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006303 nla_nest_end(msg, nl_pat);
6304 }
6305 nla_nest_end(msg, nl_pats);
6306 }
6307
6308 nla_nest_end(msg, nl_wowlan);
6309 }
6310
6311 genlmsg_end(msg, hdr);
6312 return genlmsg_reply(msg, info);
6313
6314nla_put_failure:
6315 nlmsg_free(msg);
6316 return -ENOBUFS;
6317}
6318
6319static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6320{
6321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6322 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6323 struct cfg80211_wowlan no_triggers = {};
6324 struct cfg80211_wowlan new_triggers = {};
6325 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6326 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006327 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006328
6329 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6330 return -EOPNOTSUPP;
6331
6332 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6333 goto no_triggers;
6334
6335 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6336 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6337 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6338 nl80211_wowlan_policy);
6339 if (err)
6340 return err;
6341
6342 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6343 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6344 return -EINVAL;
6345 new_triggers.any = true;
6346 }
6347
6348 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6349 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6350 return -EINVAL;
6351 new_triggers.disconnect = true;
6352 }
6353
6354 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6355 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6356 return -EINVAL;
6357 new_triggers.magic_pkt = true;
6358 }
6359
Johannes Berg77dbbb12011-07-13 10:48:55 +02006360 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6361 return -EINVAL;
6362
6363 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6364 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6365 return -EINVAL;
6366 new_triggers.gtk_rekey_failure = true;
6367 }
6368
6369 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6370 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6371 return -EINVAL;
6372 new_triggers.eap_identity_req = true;
6373 }
6374
6375 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6376 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6377 return -EINVAL;
6378 new_triggers.four_way_handshake = true;
6379 }
6380
6381 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6382 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6383 return -EINVAL;
6384 new_triggers.rfkill_release = true;
6385 }
6386
Johannes Bergff1b6e62011-05-04 15:37:28 +02006387 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6388 struct nlattr *pat;
6389 int n_patterns = 0;
6390 int rem, pat_len, mask_len;
6391 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6392
6393 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6394 rem)
6395 n_patterns++;
6396 if (n_patterns > wowlan->n_patterns)
6397 return -EINVAL;
6398
6399 new_triggers.patterns = kcalloc(n_patterns,
6400 sizeof(new_triggers.patterns[0]),
6401 GFP_KERNEL);
6402 if (!new_triggers.patterns)
6403 return -ENOMEM;
6404
6405 new_triggers.n_patterns = n_patterns;
6406 i = 0;
6407
6408 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6409 rem) {
6410 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6411 nla_data(pat), nla_len(pat), NULL);
6412 err = -EINVAL;
6413 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6414 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6415 goto error;
6416 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6417 mask_len = DIV_ROUND_UP(pat_len, 8);
6418 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6419 mask_len)
6420 goto error;
6421 if (pat_len > wowlan->pattern_max_len ||
6422 pat_len < wowlan->pattern_min_len)
6423 goto error;
6424
6425 new_triggers.patterns[i].mask =
6426 kmalloc(mask_len + pat_len, GFP_KERNEL);
6427 if (!new_triggers.patterns[i].mask) {
6428 err = -ENOMEM;
6429 goto error;
6430 }
6431 new_triggers.patterns[i].pattern =
6432 new_triggers.patterns[i].mask + mask_len;
6433 memcpy(new_triggers.patterns[i].mask,
6434 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6435 mask_len);
6436 new_triggers.patterns[i].pattern_len = pat_len;
6437 memcpy(new_triggers.patterns[i].pattern,
6438 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6439 pat_len);
6440 i++;
6441 }
6442 }
6443
6444 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6445 struct cfg80211_wowlan *ntrig;
6446 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6447 GFP_KERNEL);
6448 if (!ntrig) {
6449 err = -ENOMEM;
6450 goto error;
6451 }
6452 cfg80211_rdev_free_wowlan(rdev);
6453 rdev->wowlan = ntrig;
6454 } else {
6455 no_triggers:
6456 cfg80211_rdev_free_wowlan(rdev);
6457 rdev->wowlan = NULL;
6458 }
6459
Johannes Berg6d525632012-04-04 15:05:25 +02006460 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6461 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6462
Johannes Bergff1b6e62011-05-04 15:37:28 +02006463 return 0;
6464 error:
6465 for (i = 0; i < new_triggers.n_patterns; i++)
6466 kfree(new_triggers.patterns[i].mask);
6467 kfree(new_triggers.patterns);
6468 return err;
6469}
6470
Johannes Berge5497d72011-07-05 16:35:40 +02006471static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6472{
6473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6474 struct net_device *dev = info->user_ptr[1];
6475 struct wireless_dev *wdev = dev->ieee80211_ptr;
6476 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6477 struct cfg80211_gtk_rekey_data rekey_data;
6478 int err;
6479
6480 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6481 return -EINVAL;
6482
6483 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6484 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6485 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6486 nl80211_rekey_policy);
6487 if (err)
6488 return err;
6489
6490 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6491 return -ERANGE;
6492 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6493 return -ERANGE;
6494 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6495 return -ERANGE;
6496
6497 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6498 NL80211_KEK_LEN);
6499 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6500 NL80211_KCK_LEN);
6501 memcpy(rekey_data.replay_ctr,
6502 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6503 NL80211_REPLAY_CTR_LEN);
6504
6505 wdev_lock(wdev);
6506 if (!wdev->current_bss) {
6507 err = -ENOTCONN;
6508 goto out;
6509 }
6510
6511 if (!rdev->ops->set_rekey_data) {
6512 err = -EOPNOTSUPP;
6513 goto out;
6514 }
6515
6516 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6517 out:
6518 wdev_unlock(wdev);
6519 return err;
6520}
6521
Johannes Berg28946da2011-11-04 11:18:12 +01006522static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6523 struct genl_info *info)
6524{
6525 struct net_device *dev = info->user_ptr[1];
6526 struct wireless_dev *wdev = dev->ieee80211_ptr;
6527
6528 if (wdev->iftype != NL80211_IFTYPE_AP &&
6529 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6530 return -EINVAL;
6531
6532 if (wdev->ap_unexpected_nlpid)
6533 return -EBUSY;
6534
6535 wdev->ap_unexpected_nlpid = info->snd_pid;
6536 return 0;
6537}
6538
Johannes Berg7f6cf312011-11-04 11:18:15 +01006539static int nl80211_probe_client(struct sk_buff *skb,
6540 struct genl_info *info)
6541{
6542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6543 struct net_device *dev = info->user_ptr[1];
6544 struct wireless_dev *wdev = dev->ieee80211_ptr;
6545 struct sk_buff *msg;
6546 void *hdr;
6547 const u8 *addr;
6548 u64 cookie;
6549 int err;
6550
6551 if (wdev->iftype != NL80211_IFTYPE_AP &&
6552 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6553 return -EOPNOTSUPP;
6554
6555 if (!info->attrs[NL80211_ATTR_MAC])
6556 return -EINVAL;
6557
6558 if (!rdev->ops->probe_client)
6559 return -EOPNOTSUPP;
6560
6561 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6562 if (!msg)
6563 return -ENOMEM;
6564
6565 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6566 NL80211_CMD_PROBE_CLIENT);
6567
6568 if (IS_ERR(hdr)) {
6569 err = PTR_ERR(hdr);
6570 goto free_msg;
6571 }
6572
6573 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6574
6575 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6576 if (err)
6577 goto free_msg;
6578
David S. Miller9360ffd2012-03-29 04:41:26 -04006579 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6580 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006581
6582 genlmsg_end(msg, hdr);
6583
6584 return genlmsg_reply(msg, info);
6585
6586 nla_put_failure:
6587 err = -ENOBUFS;
6588 free_msg:
6589 nlmsg_free(msg);
6590 return err;
6591}
6592
Johannes Berg5e7602302011-11-04 11:18:17 +01006593static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6594{
6595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6596
6597 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6598 return -EOPNOTSUPP;
6599
6600 if (rdev->ap_beacons_nlpid)
6601 return -EBUSY;
6602
6603 rdev->ap_beacons_nlpid = info->snd_pid;
6604
6605 return 0;
6606}
6607
Johannes Berg4c476992010-10-04 21:36:35 +02006608#define NL80211_FLAG_NEED_WIPHY 0x01
6609#define NL80211_FLAG_NEED_NETDEV 0x02
6610#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006611#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6612#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6613 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006614
6615static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6616 struct genl_info *info)
6617{
6618 struct cfg80211_registered_device *rdev;
6619 struct net_device *dev;
6620 int err;
6621 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6622
6623 if (rtnl)
6624 rtnl_lock();
6625
6626 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006627 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006628 if (IS_ERR(rdev)) {
6629 if (rtnl)
6630 rtnl_unlock();
6631 return PTR_ERR(rdev);
6632 }
6633 info->user_ptr[0] = rdev;
6634 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006635 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6636 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006637 if (err) {
6638 if (rtnl)
6639 rtnl_unlock();
6640 return err;
6641 }
Johannes Berg41265712010-10-04 21:14:05 +02006642 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6643 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006644 cfg80211_unlock_rdev(rdev);
6645 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006646 if (rtnl)
6647 rtnl_unlock();
6648 return -ENETDOWN;
6649 }
Johannes Berg4c476992010-10-04 21:36:35 +02006650 info->user_ptr[0] = rdev;
6651 info->user_ptr[1] = dev;
6652 }
6653
6654 return 0;
6655}
6656
6657static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6658 struct genl_info *info)
6659{
6660 if (info->user_ptr[0])
6661 cfg80211_unlock_rdev(info->user_ptr[0]);
6662 if (info->user_ptr[1])
6663 dev_put(info->user_ptr[1]);
6664 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6665 rtnl_unlock();
6666}
6667
Johannes Berg55682962007-09-20 13:09:35 -04006668static struct genl_ops nl80211_ops[] = {
6669 {
6670 .cmd = NL80211_CMD_GET_WIPHY,
6671 .doit = nl80211_get_wiphy,
6672 .dumpit = nl80211_dump_wiphy,
6673 .policy = nl80211_policy,
6674 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006675 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006676 },
6677 {
6678 .cmd = NL80211_CMD_SET_WIPHY,
6679 .doit = nl80211_set_wiphy,
6680 .policy = nl80211_policy,
6681 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006682 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006683 },
6684 {
6685 .cmd = NL80211_CMD_GET_INTERFACE,
6686 .doit = nl80211_get_interface,
6687 .dumpit = nl80211_dump_interface,
6688 .policy = nl80211_policy,
6689 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006690 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006691 },
6692 {
6693 .cmd = NL80211_CMD_SET_INTERFACE,
6694 .doit = nl80211_set_interface,
6695 .policy = nl80211_policy,
6696 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006697 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6698 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006699 },
6700 {
6701 .cmd = NL80211_CMD_NEW_INTERFACE,
6702 .doit = nl80211_new_interface,
6703 .policy = nl80211_policy,
6704 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006705 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6706 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006707 },
6708 {
6709 .cmd = NL80211_CMD_DEL_INTERFACE,
6710 .doit = nl80211_del_interface,
6711 .policy = nl80211_policy,
6712 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006713 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6714 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006715 },
Johannes Berg41ade002007-12-19 02:03:29 +01006716 {
6717 .cmd = NL80211_CMD_GET_KEY,
6718 .doit = nl80211_get_key,
6719 .policy = nl80211_policy,
6720 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006722 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006723 },
6724 {
6725 .cmd = NL80211_CMD_SET_KEY,
6726 .doit = nl80211_set_key,
6727 .policy = nl80211_policy,
6728 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006730 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006731 },
6732 {
6733 .cmd = NL80211_CMD_NEW_KEY,
6734 .doit = nl80211_new_key,
6735 .policy = nl80211_policy,
6736 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006738 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006739 },
6740 {
6741 .cmd = NL80211_CMD_DEL_KEY,
6742 .doit = nl80211_del_key,
6743 .policy = nl80211_policy,
6744 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006746 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006747 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006748 {
6749 .cmd = NL80211_CMD_SET_BEACON,
6750 .policy = nl80211_policy,
6751 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006752 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006754 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006755 },
6756 {
Johannes Berg88600202012-02-13 15:17:18 +01006757 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006758 .policy = nl80211_policy,
6759 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006760 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006761 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006762 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006763 },
6764 {
Johannes Berg88600202012-02-13 15:17:18 +01006765 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006766 .policy = nl80211_policy,
6767 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006768 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006769 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006770 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006771 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006772 {
6773 .cmd = NL80211_CMD_GET_STATION,
6774 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006775 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006776 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6778 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006779 },
6780 {
6781 .cmd = NL80211_CMD_SET_STATION,
6782 .doit = nl80211_set_station,
6783 .policy = nl80211_policy,
6784 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006785 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006786 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006787 },
6788 {
6789 .cmd = NL80211_CMD_NEW_STATION,
6790 .doit = nl80211_new_station,
6791 .policy = nl80211_policy,
6792 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006793 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006794 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006795 },
6796 {
6797 .cmd = NL80211_CMD_DEL_STATION,
6798 .doit = nl80211_del_station,
6799 .policy = nl80211_policy,
6800 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006802 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006803 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006804 {
6805 .cmd = NL80211_CMD_GET_MPATH,
6806 .doit = nl80211_get_mpath,
6807 .dumpit = nl80211_dump_mpath,
6808 .policy = nl80211_policy,
6809 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006811 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006812 },
6813 {
6814 .cmd = NL80211_CMD_SET_MPATH,
6815 .doit = nl80211_set_mpath,
6816 .policy = nl80211_policy,
6817 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006819 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006820 },
6821 {
6822 .cmd = NL80211_CMD_NEW_MPATH,
6823 .doit = nl80211_new_mpath,
6824 .policy = nl80211_policy,
6825 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006826 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006827 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006828 },
6829 {
6830 .cmd = NL80211_CMD_DEL_MPATH,
6831 .doit = nl80211_del_mpath,
6832 .policy = nl80211_policy,
6833 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006834 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006835 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006836 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006837 {
6838 .cmd = NL80211_CMD_SET_BSS,
6839 .doit = nl80211_set_bss,
6840 .policy = nl80211_policy,
6841 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006843 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006844 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006845 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006846 .cmd = NL80211_CMD_GET_REG,
6847 .doit = nl80211_get_reg,
6848 .policy = nl80211_policy,
6849 /* can be retrieved by unprivileged users */
6850 },
6851 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006852 .cmd = NL80211_CMD_SET_REG,
6853 .doit = nl80211_set_reg,
6854 .policy = nl80211_policy,
6855 .flags = GENL_ADMIN_PERM,
6856 },
6857 {
6858 .cmd = NL80211_CMD_REQ_SET_REG,
6859 .doit = nl80211_req_set_reg,
6860 .policy = nl80211_policy,
6861 .flags = GENL_ADMIN_PERM,
6862 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006863 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006864 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6865 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006866 .policy = nl80211_policy,
6867 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006869 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006870 },
6871 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006872 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6873 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006874 .policy = nl80211_policy,
6875 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006877 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006878 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006879 {
Johannes Berg2a519312009-02-10 21:25:55 +01006880 .cmd = NL80211_CMD_TRIGGER_SCAN,
6881 .doit = nl80211_trigger_scan,
6882 .policy = nl80211_policy,
6883 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006884 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006885 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006886 },
6887 {
6888 .cmd = NL80211_CMD_GET_SCAN,
6889 .policy = nl80211_policy,
6890 .dumpit = nl80211_dump_scan,
6891 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006892 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006893 .cmd = NL80211_CMD_START_SCHED_SCAN,
6894 .doit = nl80211_start_sched_scan,
6895 .policy = nl80211_policy,
6896 .flags = GENL_ADMIN_PERM,
6897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6898 NL80211_FLAG_NEED_RTNL,
6899 },
6900 {
6901 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6902 .doit = nl80211_stop_sched_scan,
6903 .policy = nl80211_policy,
6904 .flags = GENL_ADMIN_PERM,
6905 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6906 NL80211_FLAG_NEED_RTNL,
6907 },
6908 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006909 .cmd = NL80211_CMD_AUTHENTICATE,
6910 .doit = nl80211_authenticate,
6911 .policy = nl80211_policy,
6912 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006913 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006914 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006915 },
6916 {
6917 .cmd = NL80211_CMD_ASSOCIATE,
6918 .doit = nl80211_associate,
6919 .policy = nl80211_policy,
6920 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006922 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006923 },
6924 {
6925 .cmd = NL80211_CMD_DEAUTHENTICATE,
6926 .doit = nl80211_deauthenticate,
6927 .policy = nl80211_policy,
6928 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006929 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006930 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006931 },
6932 {
6933 .cmd = NL80211_CMD_DISASSOCIATE,
6934 .doit = nl80211_disassociate,
6935 .policy = nl80211_policy,
6936 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006938 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006939 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006940 {
6941 .cmd = NL80211_CMD_JOIN_IBSS,
6942 .doit = nl80211_join_ibss,
6943 .policy = nl80211_policy,
6944 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006945 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006946 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006947 },
6948 {
6949 .cmd = NL80211_CMD_LEAVE_IBSS,
6950 .doit = nl80211_leave_ibss,
6951 .policy = nl80211_policy,
6952 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006953 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006954 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006955 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006956#ifdef CONFIG_NL80211_TESTMODE
6957 {
6958 .cmd = NL80211_CMD_TESTMODE,
6959 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006960 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006961 .policy = nl80211_policy,
6962 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006963 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6964 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006965 },
6966#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006967 {
6968 .cmd = NL80211_CMD_CONNECT,
6969 .doit = nl80211_connect,
6970 .policy = nl80211_policy,
6971 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006972 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006973 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006974 },
6975 {
6976 .cmd = NL80211_CMD_DISCONNECT,
6977 .doit = nl80211_disconnect,
6978 .policy = nl80211_policy,
6979 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006981 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006982 },
Johannes Berg463d0182009-07-14 00:33:35 +02006983 {
6984 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6985 .doit = nl80211_wiphy_netns,
6986 .policy = nl80211_policy,
6987 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006988 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6989 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006990 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006991 {
6992 .cmd = NL80211_CMD_GET_SURVEY,
6993 .policy = nl80211_policy,
6994 .dumpit = nl80211_dump_survey,
6995 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006996 {
6997 .cmd = NL80211_CMD_SET_PMKSA,
6998 .doit = nl80211_setdel_pmksa,
6999 .policy = nl80211_policy,
7000 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007002 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007003 },
7004 {
7005 .cmd = NL80211_CMD_DEL_PMKSA,
7006 .doit = nl80211_setdel_pmksa,
7007 .policy = nl80211_policy,
7008 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007010 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007011 },
7012 {
7013 .cmd = NL80211_CMD_FLUSH_PMKSA,
7014 .doit = nl80211_flush_pmksa,
7015 .policy = nl80211_policy,
7016 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007017 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007018 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007019 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007020 {
7021 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7022 .doit = nl80211_remain_on_channel,
7023 .policy = nl80211_policy,
7024 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007026 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007027 },
7028 {
7029 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7030 .doit = nl80211_cancel_remain_on_channel,
7031 .policy = nl80211_policy,
7032 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007034 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007035 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007036 {
7037 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7038 .doit = nl80211_set_tx_bitrate_mask,
7039 .policy = nl80211_policy,
7040 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007041 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7042 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007043 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007044 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007045 .cmd = NL80211_CMD_REGISTER_FRAME,
7046 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007047 .policy = nl80211_policy,
7048 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007049 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7050 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007051 },
7052 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007053 .cmd = NL80211_CMD_FRAME,
7054 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007055 .policy = nl80211_policy,
7056 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007058 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007059 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007060 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007061 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7062 .doit = nl80211_tx_mgmt_cancel_wait,
7063 .policy = nl80211_policy,
7064 .flags = GENL_ADMIN_PERM,
7065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7066 NL80211_FLAG_NEED_RTNL,
7067 },
7068 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007069 .cmd = NL80211_CMD_SET_POWER_SAVE,
7070 .doit = nl80211_set_power_save,
7071 .policy = nl80211_policy,
7072 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007073 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7074 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007075 },
7076 {
7077 .cmd = NL80211_CMD_GET_POWER_SAVE,
7078 .doit = nl80211_get_power_save,
7079 .policy = nl80211_policy,
7080 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007081 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7082 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007083 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007084 {
7085 .cmd = NL80211_CMD_SET_CQM,
7086 .doit = nl80211_set_cqm,
7087 .policy = nl80211_policy,
7088 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007089 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7090 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007091 },
Johannes Bergf444de02010-05-05 15:25:02 +02007092 {
7093 .cmd = NL80211_CMD_SET_CHANNEL,
7094 .doit = nl80211_set_channel,
7095 .policy = nl80211_policy,
7096 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007097 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7098 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007099 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007100 {
7101 .cmd = NL80211_CMD_SET_WDS_PEER,
7102 .doit = nl80211_set_wds_peer,
7103 .policy = nl80211_policy,
7104 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007105 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7106 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007107 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007108 {
7109 .cmd = NL80211_CMD_JOIN_MESH,
7110 .doit = nl80211_join_mesh,
7111 .policy = nl80211_policy,
7112 .flags = GENL_ADMIN_PERM,
7113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7114 NL80211_FLAG_NEED_RTNL,
7115 },
7116 {
7117 .cmd = NL80211_CMD_LEAVE_MESH,
7118 .doit = nl80211_leave_mesh,
7119 .policy = nl80211_policy,
7120 .flags = GENL_ADMIN_PERM,
7121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7122 NL80211_FLAG_NEED_RTNL,
7123 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02007124 {
7125 .cmd = NL80211_CMD_GET_WOWLAN,
7126 .doit = nl80211_get_wowlan,
7127 .policy = nl80211_policy,
7128 /* can be retrieved by unprivileged users */
7129 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7130 NL80211_FLAG_NEED_RTNL,
7131 },
7132 {
7133 .cmd = NL80211_CMD_SET_WOWLAN,
7134 .doit = nl80211_set_wowlan,
7135 .policy = nl80211_policy,
7136 .flags = GENL_ADMIN_PERM,
7137 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7138 NL80211_FLAG_NEED_RTNL,
7139 },
Johannes Berge5497d72011-07-05 16:35:40 +02007140 {
7141 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7142 .doit = nl80211_set_rekey_data,
7143 .policy = nl80211_policy,
7144 .flags = GENL_ADMIN_PERM,
7145 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7146 NL80211_FLAG_NEED_RTNL,
7147 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007148 {
7149 .cmd = NL80211_CMD_TDLS_MGMT,
7150 .doit = nl80211_tdls_mgmt,
7151 .policy = nl80211_policy,
7152 .flags = GENL_ADMIN_PERM,
7153 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7154 NL80211_FLAG_NEED_RTNL,
7155 },
7156 {
7157 .cmd = NL80211_CMD_TDLS_OPER,
7158 .doit = nl80211_tdls_oper,
7159 .policy = nl80211_policy,
7160 .flags = GENL_ADMIN_PERM,
7161 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7162 NL80211_FLAG_NEED_RTNL,
7163 },
Johannes Berg28946da2011-11-04 11:18:12 +01007164 {
7165 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7166 .doit = nl80211_register_unexpected_frame,
7167 .policy = nl80211_policy,
7168 .flags = GENL_ADMIN_PERM,
7169 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7170 NL80211_FLAG_NEED_RTNL,
7171 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007172 {
7173 .cmd = NL80211_CMD_PROBE_CLIENT,
7174 .doit = nl80211_probe_client,
7175 .policy = nl80211_policy,
7176 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007177 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007178 NL80211_FLAG_NEED_RTNL,
7179 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007180 {
7181 .cmd = NL80211_CMD_REGISTER_BEACONS,
7182 .doit = nl80211_register_beacons,
7183 .policy = nl80211_policy,
7184 .flags = GENL_ADMIN_PERM,
7185 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7186 NL80211_FLAG_NEED_RTNL,
7187 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007188 {
7189 .cmd = NL80211_CMD_SET_NOACK_MAP,
7190 .doit = nl80211_set_noack_map,
7191 .policy = nl80211_policy,
7192 .flags = GENL_ADMIN_PERM,
7193 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7194 NL80211_FLAG_NEED_RTNL,
7195 },
7196
Johannes Berg55682962007-09-20 13:09:35 -04007197};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007198
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007199static struct genl_multicast_group nl80211_mlme_mcgrp = {
7200 .name = "mlme",
7201};
Johannes Berg55682962007-09-20 13:09:35 -04007202
7203/* multicast groups */
7204static struct genl_multicast_group nl80211_config_mcgrp = {
7205 .name = "config",
7206};
Johannes Berg2a519312009-02-10 21:25:55 +01007207static struct genl_multicast_group nl80211_scan_mcgrp = {
7208 .name = "scan",
7209};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007210static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7211 .name = "regulatory",
7212};
Johannes Berg55682962007-09-20 13:09:35 -04007213
7214/* notification functions */
7215
7216void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7217{
7218 struct sk_buff *msg;
7219
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007220 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007221 if (!msg)
7222 return;
7223
7224 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7225 nlmsg_free(msg);
7226 return;
7227 }
7228
Johannes Berg463d0182009-07-14 00:33:35 +02007229 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7230 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007231}
7232
Johannes Berg362a4152009-05-24 16:43:15 +02007233static int nl80211_add_scan_req(struct sk_buff *msg,
7234 struct cfg80211_registered_device *rdev)
7235{
7236 struct cfg80211_scan_request *req = rdev->scan_req;
7237 struct nlattr *nest;
7238 int i;
7239
Johannes Berg667503dd2009-07-07 03:56:11 +02007240 ASSERT_RDEV_LOCK(rdev);
7241
Johannes Berg362a4152009-05-24 16:43:15 +02007242 if (WARN_ON(!req))
7243 return 0;
7244
7245 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7246 if (!nest)
7247 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007248 for (i = 0; i < req->n_ssids; i++) {
7249 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7250 goto nla_put_failure;
7251 }
Johannes Berg362a4152009-05-24 16:43:15 +02007252 nla_nest_end(msg, nest);
7253
7254 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7255 if (!nest)
7256 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007257 for (i = 0; i < req->n_channels; i++) {
7258 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7259 goto nla_put_failure;
7260 }
Johannes Berg362a4152009-05-24 16:43:15 +02007261 nla_nest_end(msg, nest);
7262
David S. Miller9360ffd2012-03-29 04:41:26 -04007263 if (req->ie &&
7264 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7265 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007266
7267 return 0;
7268 nla_put_failure:
7269 return -ENOBUFS;
7270}
7271
Johannes Berga538e2d2009-06-16 19:56:42 +02007272static int nl80211_send_scan_msg(struct sk_buff *msg,
7273 struct cfg80211_registered_device *rdev,
7274 struct net_device *netdev,
7275 u32 pid, u32 seq, int flags,
7276 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007277{
7278 void *hdr;
7279
7280 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7281 if (!hdr)
7282 return -1;
7283
David S. Miller9360ffd2012-03-29 04:41:26 -04007284 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7285 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7286 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007287
Johannes Berg362a4152009-05-24 16:43:15 +02007288 /* ignore errors and send incomplete event anyway */
7289 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007290
7291 return genlmsg_end(msg, hdr);
7292
7293 nla_put_failure:
7294 genlmsg_cancel(msg, hdr);
7295 return -EMSGSIZE;
7296}
7297
Luciano Coelho807f8a82011-05-11 17:09:35 +03007298static int
7299nl80211_send_sched_scan_msg(struct sk_buff *msg,
7300 struct cfg80211_registered_device *rdev,
7301 struct net_device *netdev,
7302 u32 pid, u32 seq, int flags, u32 cmd)
7303{
7304 void *hdr;
7305
7306 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7307 if (!hdr)
7308 return -1;
7309
David S. Miller9360ffd2012-03-29 04:41:26 -04007310 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7311 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7312 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007313
7314 return genlmsg_end(msg, hdr);
7315
7316 nla_put_failure:
7317 genlmsg_cancel(msg, hdr);
7318 return -EMSGSIZE;
7319}
7320
Johannes Berga538e2d2009-06-16 19:56:42 +02007321void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7322 struct net_device *netdev)
7323{
7324 struct sk_buff *msg;
7325
7326 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7327 if (!msg)
7328 return;
7329
7330 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7331 NL80211_CMD_TRIGGER_SCAN) < 0) {
7332 nlmsg_free(msg);
7333 return;
7334 }
7335
Johannes Berg463d0182009-07-14 00:33:35 +02007336 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7337 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007338}
7339
Johannes Berg2a519312009-02-10 21:25:55 +01007340void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7341 struct net_device *netdev)
7342{
7343 struct sk_buff *msg;
7344
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007345 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007346 if (!msg)
7347 return;
7348
Johannes Berga538e2d2009-06-16 19:56:42 +02007349 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7350 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007351 nlmsg_free(msg);
7352 return;
7353 }
7354
Johannes Berg463d0182009-07-14 00:33:35 +02007355 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7356 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007357}
7358
7359void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7360 struct net_device *netdev)
7361{
7362 struct sk_buff *msg;
7363
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007365 if (!msg)
7366 return;
7367
Johannes Berga538e2d2009-06-16 19:56:42 +02007368 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7369 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007370 nlmsg_free(msg);
7371 return;
7372 }
7373
Johannes Berg463d0182009-07-14 00:33:35 +02007374 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7375 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007376}
7377
Luciano Coelho807f8a82011-05-11 17:09:35 +03007378void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7379 struct net_device *netdev)
7380{
7381 struct sk_buff *msg;
7382
7383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7384 if (!msg)
7385 return;
7386
7387 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7388 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7389 nlmsg_free(msg);
7390 return;
7391 }
7392
7393 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7394 nl80211_scan_mcgrp.id, GFP_KERNEL);
7395}
7396
7397void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7398 struct net_device *netdev, u32 cmd)
7399{
7400 struct sk_buff *msg;
7401
7402 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7403 if (!msg)
7404 return;
7405
7406 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7407 nlmsg_free(msg);
7408 return;
7409 }
7410
7411 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7412 nl80211_scan_mcgrp.id, GFP_KERNEL);
7413}
7414
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007415/*
7416 * This can happen on global regulatory changes or device specific settings
7417 * based on custom world regulatory domains.
7418 */
7419void nl80211_send_reg_change_event(struct regulatory_request *request)
7420{
7421 struct sk_buff *msg;
7422 void *hdr;
7423
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007425 if (!msg)
7426 return;
7427
7428 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7429 if (!hdr) {
7430 nlmsg_free(msg);
7431 return;
7432 }
7433
7434 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007435 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7436 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007437
David S. Miller9360ffd2012-03-29 04:41:26 -04007438 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7439 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7440 NL80211_REGDOM_TYPE_WORLD))
7441 goto nla_put_failure;
7442 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7443 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7444 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7445 goto nla_put_failure;
7446 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7447 request->intersect) {
7448 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7449 NL80211_REGDOM_TYPE_INTERSECTION))
7450 goto nla_put_failure;
7451 } else {
7452 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7453 NL80211_REGDOM_TYPE_COUNTRY) ||
7454 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7455 request->alpha2))
7456 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007457 }
7458
David S. Miller9360ffd2012-03-29 04:41:26 -04007459 if (wiphy_idx_valid(request->wiphy_idx) &&
7460 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7461 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007462
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007463 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007464
Johannes Bergbc43b282009-07-25 10:54:13 +02007465 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007466 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007467 GFP_ATOMIC);
7468 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007469
7470 return;
7471
7472nla_put_failure:
7473 genlmsg_cancel(msg, hdr);
7474 nlmsg_free(msg);
7475}
7476
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007477static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7478 struct net_device *netdev,
7479 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007480 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007481{
7482 struct sk_buff *msg;
7483 void *hdr;
7484
Johannes Berge6d6e342009-07-01 21:26:47 +02007485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007486 if (!msg)
7487 return;
7488
7489 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7490 if (!hdr) {
7491 nlmsg_free(msg);
7492 return;
7493 }
7494
David S. Miller9360ffd2012-03-29 04:41:26 -04007495 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7496 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7497 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7498 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007499
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007500 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007501
Johannes Berg463d0182009-07-14 00:33:35 +02007502 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7503 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007504 return;
7505
7506 nla_put_failure:
7507 genlmsg_cancel(msg, hdr);
7508 nlmsg_free(msg);
7509}
7510
7511void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007512 struct net_device *netdev, const u8 *buf,
7513 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007514{
7515 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007516 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007517}
7518
7519void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7520 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007521 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007522{
Johannes Berge6d6e342009-07-01 21:26:47 +02007523 nl80211_send_mlme_event(rdev, netdev, buf, len,
7524 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007525}
7526
Jouni Malinen53b46b82009-03-27 20:53:56 +02007527void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007528 struct net_device *netdev, const u8 *buf,
7529 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007530{
7531 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007532 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007533}
7534
Jouni Malinen53b46b82009-03-27 20:53:56 +02007535void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7536 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007537 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007538{
7539 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007540 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007541}
7542
Jouni Malinencf4e5942010-12-16 00:52:40 +02007543void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7544 struct net_device *netdev, const u8 *buf,
7545 size_t len, gfp_t gfp)
7546{
7547 nl80211_send_mlme_event(rdev, netdev, buf, len,
7548 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7549}
7550
7551void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7552 struct net_device *netdev, const u8 *buf,
7553 size_t len, gfp_t gfp)
7554{
7555 nl80211_send_mlme_event(rdev, netdev, buf, len,
7556 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7557}
7558
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007559static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7560 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007561 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007562{
7563 struct sk_buff *msg;
7564 void *hdr;
7565
Johannes Berge6d6e342009-07-01 21:26:47 +02007566 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007567 if (!msg)
7568 return;
7569
7570 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7571 if (!hdr) {
7572 nlmsg_free(msg);
7573 return;
7574 }
7575
David S. Miller9360ffd2012-03-29 04:41:26 -04007576 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7577 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7578 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7579 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7580 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007581
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007582 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007583
Johannes Berg463d0182009-07-14 00:33:35 +02007584 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7585 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007586 return;
7587
7588 nla_put_failure:
7589 genlmsg_cancel(msg, hdr);
7590 nlmsg_free(msg);
7591}
7592
7593void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007594 struct net_device *netdev, const u8 *addr,
7595 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007596{
7597 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007598 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007599}
7600
7601void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007602 struct net_device *netdev, const u8 *addr,
7603 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007604{
Johannes Berge6d6e342009-07-01 21:26:47 +02007605 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7606 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007607}
7608
Samuel Ortizb23aa672009-07-01 21:26:54 +02007609void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7610 struct net_device *netdev, const u8 *bssid,
7611 const u8 *req_ie, size_t req_ie_len,
7612 const u8 *resp_ie, size_t resp_ie_len,
7613 u16 status, gfp_t gfp)
7614{
7615 struct sk_buff *msg;
7616 void *hdr;
7617
7618 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7619 if (!msg)
7620 return;
7621
7622 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7623 if (!hdr) {
7624 nlmsg_free(msg);
7625 return;
7626 }
7627
David S. Miller9360ffd2012-03-29 04:41:26 -04007628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7629 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7630 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7631 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7632 (req_ie &&
7633 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7634 (resp_ie &&
7635 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7636 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007637
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007638 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007639
Johannes Berg463d0182009-07-14 00:33:35 +02007640 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7641 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007642 return;
7643
7644 nla_put_failure:
7645 genlmsg_cancel(msg, hdr);
7646 nlmsg_free(msg);
7647
7648}
7649
7650void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7651 struct net_device *netdev, const u8 *bssid,
7652 const u8 *req_ie, size_t req_ie_len,
7653 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7654{
7655 struct sk_buff *msg;
7656 void *hdr;
7657
7658 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7659 if (!msg)
7660 return;
7661
7662 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7663 if (!hdr) {
7664 nlmsg_free(msg);
7665 return;
7666 }
7667
David S. Miller9360ffd2012-03-29 04:41:26 -04007668 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7669 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7671 (req_ie &&
7672 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7673 (resp_ie &&
7674 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7675 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007676
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007677 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007678
Johannes Berg463d0182009-07-14 00:33:35 +02007679 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7680 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007681 return;
7682
7683 nla_put_failure:
7684 genlmsg_cancel(msg, hdr);
7685 nlmsg_free(msg);
7686
7687}
7688
7689void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7690 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007691 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007692{
7693 struct sk_buff *msg;
7694 void *hdr;
7695
Johannes Berg667503dd2009-07-07 03:56:11 +02007696 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007697 if (!msg)
7698 return;
7699
7700 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7701 if (!hdr) {
7702 nlmsg_free(msg);
7703 return;
7704 }
7705
David S. Miller9360ffd2012-03-29 04:41:26 -04007706 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7708 (from_ap && reason &&
7709 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7710 (from_ap &&
7711 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7712 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7713 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007714
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007715 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007716
Johannes Berg463d0182009-07-14 00:33:35 +02007717 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7718 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719 return;
7720
7721 nla_put_failure:
7722 genlmsg_cancel(msg, hdr);
7723 nlmsg_free(msg);
7724
7725}
7726
Johannes Berg04a773a2009-04-19 21:24:32 +02007727void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7728 struct net_device *netdev, const u8 *bssid,
7729 gfp_t gfp)
7730{
7731 struct sk_buff *msg;
7732 void *hdr;
7733
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007735 if (!msg)
7736 return;
7737
7738 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7739 if (!hdr) {
7740 nlmsg_free(msg);
7741 return;
7742 }
7743
David S. Miller9360ffd2012-03-29 04:41:26 -04007744 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7746 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7747 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007748
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007749 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007750
Johannes Berg463d0182009-07-14 00:33:35 +02007751 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7752 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007753 return;
7754
7755 nla_put_failure:
7756 genlmsg_cancel(msg, hdr);
7757 nlmsg_free(msg);
7758}
7759
Javier Cardonac93b5e72011-04-07 15:08:34 -07007760void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7761 struct net_device *netdev,
7762 const u8 *macaddr, const u8* ie, u8 ie_len,
7763 gfp_t gfp)
7764{
7765 struct sk_buff *msg;
7766 void *hdr;
7767
7768 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7769 if (!msg)
7770 return;
7771
7772 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7773 if (!hdr) {
7774 nlmsg_free(msg);
7775 return;
7776 }
7777
David S. Miller9360ffd2012-03-29 04:41:26 -04007778 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7779 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7780 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7781 (ie_len && ie &&
7782 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7783 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007784
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007785 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007786
7787 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7788 nl80211_mlme_mcgrp.id, gfp);
7789 return;
7790
7791 nla_put_failure:
7792 genlmsg_cancel(msg, hdr);
7793 nlmsg_free(msg);
7794}
7795
Jouni Malinena3b8b052009-03-27 21:59:49 +02007796void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7797 struct net_device *netdev, const u8 *addr,
7798 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007799 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007800{
7801 struct sk_buff *msg;
7802 void *hdr;
7803
Johannes Berge6d6e342009-07-01 21:26:47 +02007804 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007805 if (!msg)
7806 return;
7807
7808 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7809 if (!hdr) {
7810 nlmsg_free(msg);
7811 return;
7812 }
7813
David S. Miller9360ffd2012-03-29 04:41:26 -04007814 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7815 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7816 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7817 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7818 (key_id != -1 &&
7819 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7820 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7821 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007822
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007823 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007824
Johannes Berg463d0182009-07-14 00:33:35 +02007825 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7826 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007827 return;
7828
7829 nla_put_failure:
7830 genlmsg_cancel(msg, hdr);
7831 nlmsg_free(msg);
7832}
7833
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007834void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7835 struct ieee80211_channel *channel_before,
7836 struct ieee80211_channel *channel_after)
7837{
7838 struct sk_buff *msg;
7839 void *hdr;
7840 struct nlattr *nl_freq;
7841
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007843 if (!msg)
7844 return;
7845
7846 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7847 if (!hdr) {
7848 nlmsg_free(msg);
7849 return;
7850 }
7851
7852 /*
7853 * Since we are applying the beacon hint to a wiphy we know its
7854 * wiphy_idx is valid
7855 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007856 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7857 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007858
7859 /* Before */
7860 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7861 if (!nl_freq)
7862 goto nla_put_failure;
7863 if (nl80211_msg_put_channel(msg, channel_before))
7864 goto nla_put_failure;
7865 nla_nest_end(msg, nl_freq);
7866
7867 /* After */
7868 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7869 if (!nl_freq)
7870 goto nla_put_failure;
7871 if (nl80211_msg_put_channel(msg, channel_after))
7872 goto nla_put_failure;
7873 nla_nest_end(msg, nl_freq);
7874
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007875 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007876
Johannes Berg463d0182009-07-14 00:33:35 +02007877 rcu_read_lock();
7878 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7879 GFP_ATOMIC);
7880 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007881
7882 return;
7883
7884nla_put_failure:
7885 genlmsg_cancel(msg, hdr);
7886 nlmsg_free(msg);
7887}
7888
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007889static void nl80211_send_remain_on_chan_event(
7890 int cmd, struct cfg80211_registered_device *rdev,
7891 struct net_device *netdev, u64 cookie,
7892 struct ieee80211_channel *chan,
7893 enum nl80211_channel_type channel_type,
7894 unsigned int duration, gfp_t gfp)
7895{
7896 struct sk_buff *msg;
7897 void *hdr;
7898
7899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7900 if (!msg)
7901 return;
7902
7903 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7904 if (!hdr) {
7905 nlmsg_free(msg);
7906 return;
7907 }
7908
David S. Miller9360ffd2012-03-29 04:41:26 -04007909 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7911 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7912 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7913 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7914 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007915
David S. Miller9360ffd2012-03-29 04:41:26 -04007916 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7917 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7918 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007919
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007920 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007921
7922 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7923 nl80211_mlme_mcgrp.id, gfp);
7924 return;
7925
7926 nla_put_failure:
7927 genlmsg_cancel(msg, hdr);
7928 nlmsg_free(msg);
7929}
7930
7931void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7932 struct net_device *netdev, u64 cookie,
7933 struct ieee80211_channel *chan,
7934 enum nl80211_channel_type channel_type,
7935 unsigned int duration, gfp_t gfp)
7936{
7937 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7938 rdev, netdev, cookie, chan,
7939 channel_type, duration, gfp);
7940}
7941
7942void nl80211_send_remain_on_channel_cancel(
7943 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7944 u64 cookie, struct ieee80211_channel *chan,
7945 enum nl80211_channel_type channel_type, gfp_t gfp)
7946{
7947 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7948 rdev, netdev, cookie, chan,
7949 channel_type, 0, gfp);
7950}
7951
Johannes Berg98b62182009-12-23 13:15:44 +01007952void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7953 struct net_device *dev, const u8 *mac_addr,
7954 struct station_info *sinfo, gfp_t gfp)
7955{
7956 struct sk_buff *msg;
7957
7958 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7959 if (!msg)
7960 return;
7961
John W. Linville66266b32012-03-15 13:25:41 -04007962 if (nl80211_send_station(msg, 0, 0, 0,
7963 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007964 nlmsg_free(msg);
7965 return;
7966 }
7967
7968 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7969 nl80211_mlme_mcgrp.id, gfp);
7970}
7971
Jouni Malinenec15e682011-03-23 15:29:52 +02007972void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7973 struct net_device *dev, const u8 *mac_addr,
7974 gfp_t gfp)
7975{
7976 struct sk_buff *msg;
7977 void *hdr;
7978
7979 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7980 if (!msg)
7981 return;
7982
7983 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7984 if (!hdr) {
7985 nlmsg_free(msg);
7986 return;
7987 }
7988
David S. Miller9360ffd2012-03-29 04:41:26 -04007989 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7990 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
7991 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02007992
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007993 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007994
7995 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7996 nl80211_mlme_mcgrp.id, gfp);
7997 return;
7998
7999 nla_put_failure:
8000 genlmsg_cancel(msg, hdr);
8001 nlmsg_free(msg);
8002}
8003
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008004static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8005 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008006{
8007 struct wireless_dev *wdev = dev->ieee80211_ptr;
8008 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8009 struct sk_buff *msg;
8010 void *hdr;
8011 int err;
8012 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8013
8014 if (!nlpid)
8015 return false;
8016
8017 msg = nlmsg_new(100, gfp);
8018 if (!msg)
8019 return true;
8020
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008021 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008022 if (!hdr) {
8023 nlmsg_free(msg);
8024 return true;
8025 }
8026
David S. Miller9360ffd2012-03-29 04:41:26 -04008027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8028 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8029 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8030 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008031
8032 err = genlmsg_end(msg, hdr);
8033 if (err < 0) {
8034 nlmsg_free(msg);
8035 return true;
8036 }
8037
8038 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8039 return true;
8040
8041 nla_put_failure:
8042 genlmsg_cancel(msg, hdr);
8043 nlmsg_free(msg);
8044 return true;
8045}
8046
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008047bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8048{
8049 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8050 addr, gfp);
8051}
8052
8053bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8054 const u8 *addr, gfp_t gfp)
8055{
8056 return __nl80211_unexpected_frame(dev,
8057 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8058 addr, gfp);
8059}
8060
Johannes Berg2e161f72010-08-12 15:38:38 +02008061int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8062 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008063 int freq, int sig_dbm,
8064 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008065{
8066 struct sk_buff *msg;
8067 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008068
8069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8070 if (!msg)
8071 return -ENOMEM;
8072
Johannes Berg2e161f72010-08-12 15:38:38 +02008073 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008074 if (!hdr) {
8075 nlmsg_free(msg);
8076 return -ENOMEM;
8077 }
8078
David S. Miller9360ffd2012-03-29 04:41:26 -04008079 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8080 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8081 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8082 (sig_dbm &&
8083 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8084 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8085 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008086
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008087 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008088
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008089 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008090
8091 nla_put_failure:
8092 genlmsg_cancel(msg, hdr);
8093 nlmsg_free(msg);
8094 return -ENOBUFS;
8095}
8096
Johannes Berg2e161f72010-08-12 15:38:38 +02008097void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8098 struct net_device *netdev, u64 cookie,
8099 const u8 *buf, size_t len, bool ack,
8100 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008101{
8102 struct sk_buff *msg;
8103 void *hdr;
8104
8105 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8106 if (!msg)
8107 return;
8108
Johannes Berg2e161f72010-08-12 15:38:38 +02008109 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008110 if (!hdr) {
8111 nlmsg_free(msg);
8112 return;
8113 }
8114
David S. Miller9360ffd2012-03-29 04:41:26 -04008115 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8116 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8117 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8118 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8119 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8120 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008121
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008122 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008123
8124 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8125 return;
8126
8127 nla_put_failure:
8128 genlmsg_cancel(msg, hdr);
8129 nlmsg_free(msg);
8130}
8131
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008132void
8133nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8134 struct net_device *netdev,
8135 enum nl80211_cqm_rssi_threshold_event rssi_event,
8136 gfp_t gfp)
8137{
8138 struct sk_buff *msg;
8139 struct nlattr *pinfoattr;
8140 void *hdr;
8141
8142 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8143 if (!msg)
8144 return;
8145
8146 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8147 if (!hdr) {
8148 nlmsg_free(msg);
8149 return;
8150 }
8151
David S. Miller9360ffd2012-03-29 04:41:26 -04008152 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8153 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8154 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008155
8156 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8157 if (!pinfoattr)
8158 goto nla_put_failure;
8159
David S. Miller9360ffd2012-03-29 04:41:26 -04008160 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8161 rssi_event))
8162 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008163
8164 nla_nest_end(msg, pinfoattr);
8165
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008166 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008167
8168 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8169 nl80211_mlme_mcgrp.id, gfp);
8170 return;
8171
8172 nla_put_failure:
8173 genlmsg_cancel(msg, hdr);
8174 nlmsg_free(msg);
8175}
8176
Johannes Berge5497d72011-07-05 16:35:40 +02008177void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8178 struct net_device *netdev, const u8 *bssid,
8179 const u8 *replay_ctr, gfp_t gfp)
8180{
8181 struct sk_buff *msg;
8182 struct nlattr *rekey_attr;
8183 void *hdr;
8184
8185 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8186 if (!msg)
8187 return;
8188
8189 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8190 if (!hdr) {
8191 nlmsg_free(msg);
8192 return;
8193 }
8194
David S. Miller9360ffd2012-03-29 04:41:26 -04008195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8196 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8197 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8198 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008199
8200 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8201 if (!rekey_attr)
8202 goto nla_put_failure;
8203
David S. Miller9360ffd2012-03-29 04:41:26 -04008204 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8205 NL80211_REPLAY_CTR_LEN, replay_ctr))
8206 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008207
8208 nla_nest_end(msg, rekey_attr);
8209
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008210 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008211
8212 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8213 nl80211_mlme_mcgrp.id, gfp);
8214 return;
8215
8216 nla_put_failure:
8217 genlmsg_cancel(msg, hdr);
8218 nlmsg_free(msg);
8219}
8220
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008221void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8222 struct net_device *netdev, int index,
8223 const u8 *bssid, bool preauth, gfp_t gfp)
8224{
8225 struct sk_buff *msg;
8226 struct nlattr *attr;
8227 void *hdr;
8228
8229 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8230 if (!msg)
8231 return;
8232
8233 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8234 if (!hdr) {
8235 nlmsg_free(msg);
8236 return;
8237 }
8238
David S. Miller9360ffd2012-03-29 04:41:26 -04008239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8240 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8241 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008242
8243 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8244 if (!attr)
8245 goto nla_put_failure;
8246
David S. Miller9360ffd2012-03-29 04:41:26 -04008247 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8248 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8249 (preauth &&
8250 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8251 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008252
8253 nla_nest_end(msg, attr);
8254
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008255 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008256
8257 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8258 nl80211_mlme_mcgrp.id, gfp);
8259 return;
8260
8261 nla_put_failure:
8262 genlmsg_cancel(msg, hdr);
8263 nlmsg_free(msg);
8264}
8265
Thomas Pedersen53145262012-04-06 13:35:47 -07008266void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8267 struct net_device *netdev, int freq,
8268 enum nl80211_channel_type type, gfp_t gfp)
8269{
8270 struct sk_buff *msg;
8271 void *hdr;
8272
8273 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8274 if (!msg)
8275 return;
8276
8277 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8278 if (!hdr) {
8279 nlmsg_free(msg);
8280 return;
8281 }
8282
John W. Linville7eab0f62012-04-12 14:25:14 -04008283 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8284 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8285 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8286 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008287
8288 genlmsg_end(msg, hdr);
8289
8290 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8291 nl80211_mlme_mcgrp.id, gfp);
8292 return;
8293
8294 nla_put_failure:
8295 genlmsg_cancel(msg, hdr);
8296 nlmsg_free(msg);
8297}
8298
Johannes Bergc063dbf2010-11-24 08:10:05 +01008299void
8300nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8301 struct net_device *netdev, const u8 *peer,
8302 u32 num_packets, gfp_t gfp)
8303{
8304 struct sk_buff *msg;
8305 struct nlattr *pinfoattr;
8306 void *hdr;
8307
8308 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8309 if (!msg)
8310 return;
8311
8312 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8313 if (!hdr) {
8314 nlmsg_free(msg);
8315 return;
8316 }
8317
David S. Miller9360ffd2012-03-29 04:41:26 -04008318 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8319 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8320 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8321 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008322
8323 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8324 if (!pinfoattr)
8325 goto nla_put_failure;
8326
David S. Miller9360ffd2012-03-29 04:41:26 -04008327 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8328 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008329
8330 nla_nest_end(msg, pinfoattr);
8331
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008332 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008333
8334 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8335 nl80211_mlme_mcgrp.id, gfp);
8336 return;
8337
8338 nla_put_failure:
8339 genlmsg_cancel(msg, hdr);
8340 nlmsg_free(msg);
8341}
8342
Johannes Berg7f6cf312011-11-04 11:18:15 +01008343void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8344 u64 cookie, bool acked, gfp_t gfp)
8345{
8346 struct wireless_dev *wdev = dev->ieee80211_ptr;
8347 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8348 struct sk_buff *msg;
8349 void *hdr;
8350 int err;
8351
8352 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8353 if (!msg)
8354 return;
8355
8356 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8357 if (!hdr) {
8358 nlmsg_free(msg);
8359 return;
8360 }
8361
David S. Miller9360ffd2012-03-29 04:41:26 -04008362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8363 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8364 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8365 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8366 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8367 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008368
8369 err = genlmsg_end(msg, hdr);
8370 if (err < 0) {
8371 nlmsg_free(msg);
8372 return;
8373 }
8374
8375 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8376 nl80211_mlme_mcgrp.id, gfp);
8377 return;
8378
8379 nla_put_failure:
8380 genlmsg_cancel(msg, hdr);
8381 nlmsg_free(msg);
8382}
8383EXPORT_SYMBOL(cfg80211_probe_status);
8384
Johannes Berg5e7602302011-11-04 11:18:17 +01008385void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8386 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008387 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008388{
8389 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8390 struct sk_buff *msg;
8391 void *hdr;
8392 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8393
8394 if (!nlpid)
8395 return;
8396
8397 msg = nlmsg_new(len + 100, gfp);
8398 if (!msg)
8399 return;
8400
8401 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8402 if (!hdr) {
8403 nlmsg_free(msg);
8404 return;
8405 }
8406
David S. Miller9360ffd2012-03-29 04:41:26 -04008407 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8408 (freq &&
8409 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8410 (sig_dbm &&
8411 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8412 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8413 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008414
8415 genlmsg_end(msg, hdr);
8416
8417 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8418 return;
8419
8420 nla_put_failure:
8421 genlmsg_cancel(msg, hdr);
8422 nlmsg_free(msg);
8423}
8424EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8425
Jouni Malinen026331c2010-02-15 12:53:10 +02008426static int nl80211_netlink_notify(struct notifier_block * nb,
8427 unsigned long state,
8428 void *_notify)
8429{
8430 struct netlink_notify *notify = _notify;
8431 struct cfg80211_registered_device *rdev;
8432 struct wireless_dev *wdev;
8433
8434 if (state != NETLINK_URELEASE)
8435 return NOTIFY_DONE;
8436
8437 rcu_read_lock();
8438
Johannes Berg5e7602302011-11-04 11:18:17 +01008439 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008440 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008441 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008442 if (rdev->ap_beacons_nlpid == notify->pid)
8443 rdev->ap_beacons_nlpid = 0;
8444 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008445
8446 rcu_read_unlock();
8447
8448 return NOTIFY_DONE;
8449}
8450
8451static struct notifier_block nl80211_netlink_notifier = {
8452 .notifier_call = nl80211_netlink_notify,
8453};
8454
Johannes Berg55682962007-09-20 13:09:35 -04008455/* initialisation/exit functions */
8456
8457int nl80211_init(void)
8458{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008459 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008460
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008461 err = genl_register_family_with_ops(&nl80211_fam,
8462 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008463 if (err)
8464 return err;
8465
Johannes Berg55682962007-09-20 13:09:35 -04008466 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8467 if (err)
8468 goto err_out;
8469
Johannes Berg2a519312009-02-10 21:25:55 +01008470 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8471 if (err)
8472 goto err_out;
8473
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008474 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8475 if (err)
8476 goto err_out;
8477
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008478 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8479 if (err)
8480 goto err_out;
8481
Johannes Bergaff89a92009-07-01 21:26:51 +02008482#ifdef CONFIG_NL80211_TESTMODE
8483 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8484 if (err)
8485 goto err_out;
8486#endif
8487
Jouni Malinen026331c2010-02-15 12:53:10 +02008488 err = netlink_register_notifier(&nl80211_netlink_notifier);
8489 if (err)
8490 goto err_out;
8491
Johannes Berg55682962007-09-20 13:09:35 -04008492 return 0;
8493 err_out:
8494 genl_unregister_family(&nl80211_fam);
8495 return err;
8496}
8497
8498void nl80211_exit(void)
8499{
Jouni Malinen026331c2010-02-15 12:53:10 +02008500 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008501 genl_unregister_family(&nl80211_fam);
8502}