blob: 5d29ed1f7c62bfc64305ceff1903383ea8745504 [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 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700343 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344};
345
Holger Schuriga0438972009-11-11 11:30:02 +0100346/* ifidx get helper */
347static int nl80211_get_ifidx(struct netlink_callback *cb)
348{
349 int res;
350
351 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
352 nl80211_fam.attrbuf, nl80211_fam.maxattr,
353 nl80211_policy);
354 if (res)
355 return res;
356
357 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
358 return -EINVAL;
359
360 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
361 if (!res)
362 return -EINVAL;
363 return res;
364}
365
Johannes Berg67748892010-10-04 21:14:06 +0200366static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
367 struct netlink_callback *cb,
368 struct cfg80211_registered_device **rdev,
369 struct net_device **dev)
370{
371 int ifidx = cb->args[0];
372 int err;
373
374 if (!ifidx)
375 ifidx = nl80211_get_ifidx(cb);
376 if (ifidx < 0)
377 return ifidx;
378
379 cb->args[0] = ifidx;
380
381 rtnl_lock();
382
383 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
384 if (!*dev) {
385 err = -ENODEV;
386 goto out_rtnl;
387 }
388
389 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100390 if (IS_ERR(*rdev)) {
391 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200392 goto out_rtnl;
393 }
394
395 return 0;
396 out_rtnl:
397 rtnl_unlock();
398 return err;
399}
400
401static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
402{
403 cfg80211_unlock_rdev(rdev);
404 rtnl_unlock();
405}
406
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100407/* IE validation */
408static bool is_valid_ie_attr(const struct nlattr *attr)
409{
410 const u8 *pos;
411 int len;
412
413 if (!attr)
414 return true;
415
416 pos = nla_data(attr);
417 len = nla_len(attr);
418
419 while (len) {
420 u8 elemlen;
421
422 if (len < 2)
423 return false;
424 len -= 2;
425
426 elemlen = pos[1];
427 if (elemlen > len)
428 return false;
429
430 len -= elemlen;
431 pos += 2 + elemlen;
432 }
433
434 return true;
435}
436
Johannes Berg55682962007-09-20 13:09:35 -0400437/* message building helper */
438static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
439 int flags, u8 cmd)
440{
441 /* since there is no private header just add the generic one */
442 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
443}
444
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400445static int nl80211_msg_put_channel(struct sk_buff *msg,
446 struct ieee80211_channel *chan)
447{
David S. Miller9360ffd2012-03-29 04:41:26 -0400448 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
449 chan->center_freq))
450 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400451
David S. Miller9360ffd2012-03-29 04:41:26 -0400452 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
453 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
454 goto nla_put_failure;
455 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
456 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
457 goto nla_put_failure;
458 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
459 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
460 goto nla_put_failure;
461 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
462 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
463 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400464
David S. Miller9360ffd2012-03-29 04:41:26 -0400465 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
466 DBM_TO_MBM(chan->max_power)))
467 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400468
469 return 0;
470
471 nla_put_failure:
472 return -ENOBUFS;
473}
474
Johannes Berg55682962007-09-20 13:09:35 -0400475/* netlink command implementations */
476
Johannes Bergb9454e82009-07-08 13:29:08 +0200477struct key_parse {
478 struct key_params p;
479 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200480 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200481 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100482 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200483};
484
485static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
486{
487 struct nlattr *tb[NL80211_KEY_MAX + 1];
488 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
489 nl80211_key_policy);
490 if (err)
491 return err;
492
493 k->def = !!tb[NL80211_KEY_DEFAULT];
494 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
495
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100496 if (k->def) {
497 k->def_uni = true;
498 k->def_multi = true;
499 }
500 if (k->defmgmt)
501 k->def_multi = true;
502
Johannes Bergb9454e82009-07-08 13:29:08 +0200503 if (tb[NL80211_KEY_IDX])
504 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
505
506 if (tb[NL80211_KEY_DATA]) {
507 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
508 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
509 }
510
511 if (tb[NL80211_KEY_SEQ]) {
512 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
513 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
514 }
515
516 if (tb[NL80211_KEY_CIPHER])
517 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
518
Johannes Berge31b8212010-10-05 19:39:30 +0200519 if (tb[NL80211_KEY_TYPE]) {
520 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
521 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
522 return -EINVAL;
523 }
524
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100525 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
526 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100527 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
528 tb[NL80211_KEY_DEFAULT_TYPES],
529 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100530 if (err)
531 return err;
532
533 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
534 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
535 }
536
Johannes Bergb9454e82009-07-08 13:29:08 +0200537 return 0;
538}
539
540static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
541{
542 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
543 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
544 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
545 }
546
547 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
548 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
550 }
551
552 if (info->attrs[NL80211_ATTR_KEY_IDX])
553 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
554
555 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
556 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
557
558 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
559 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
560
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100561 if (k->def) {
562 k->def_uni = true;
563 k->def_multi = true;
564 }
565 if (k->defmgmt)
566 k->def_multi = true;
567
Johannes Berge31b8212010-10-05 19:39:30 +0200568 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
569 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
570 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
571 return -EINVAL;
572 }
573
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100574 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
575 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
576 int err = nla_parse_nested(
577 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
578 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
579 nl80211_key_default_policy);
580 if (err)
581 return err;
582
583 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
584 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
585 }
586
Johannes Bergb9454e82009-07-08 13:29:08 +0200587 return 0;
588}
589
590static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
591{
592 int err;
593
594 memset(k, 0, sizeof(*k));
595 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200596 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200597
598 if (info->attrs[NL80211_ATTR_KEY])
599 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
600 else
601 err = nl80211_parse_key_old(info, k);
602
603 if (err)
604 return err;
605
606 if (k->def && k->defmgmt)
607 return -EINVAL;
608
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100609 if (k->defmgmt) {
610 if (k->def_uni || !k->def_multi)
611 return -EINVAL;
612 }
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (k->idx != -1) {
615 if (k->defmgmt) {
616 if (k->idx < 4 || k->idx > 5)
617 return -EINVAL;
618 } else if (k->def) {
619 if (k->idx < 0 || k->idx > 3)
620 return -EINVAL;
621 } else {
622 if (k->idx < 0 || k->idx > 5)
623 return -EINVAL;
624 }
625 }
626
627 return 0;
628}
629
Johannes Bergfffd0932009-07-08 14:22:54 +0200630static struct cfg80211_cached_keys *
631nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
632 struct nlattr *keys)
633{
634 struct key_parse parse;
635 struct nlattr *key;
636 struct cfg80211_cached_keys *result;
637 int rem, err, def = 0;
638
639 result = kzalloc(sizeof(*result), GFP_KERNEL);
640 if (!result)
641 return ERR_PTR(-ENOMEM);
642
643 result->def = -1;
644 result->defmgmt = -1;
645
646 nla_for_each_nested(key, keys, rem) {
647 memset(&parse, 0, sizeof(parse));
648 parse.idx = -1;
649
650 err = nl80211_parse_key_new(key, &parse);
651 if (err)
652 goto error;
653 err = -EINVAL;
654 if (!parse.p.key)
655 goto error;
656 if (parse.idx < 0 || parse.idx > 4)
657 goto error;
658 if (parse.def) {
659 if (def)
660 goto error;
661 def = 1;
662 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (!parse.def_uni || !parse.def_multi)
664 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200665 } else if (parse.defmgmt)
666 goto error;
667 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200668 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200669 if (err)
670 goto error;
671 result->params[parse.idx].cipher = parse.p.cipher;
672 result->params[parse.idx].key_len = parse.p.key_len;
673 result->params[parse.idx].key = result->data[parse.idx];
674 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
675 }
676
677 return result;
678 error:
679 kfree(result);
680 return ERR_PTR(err);
681}
682
683static int nl80211_key_allowed(struct wireless_dev *wdev)
684{
685 ASSERT_WDEV_LOCK(wdev);
686
Johannes Bergfffd0932009-07-08 14:22:54 +0200687 switch (wdev->iftype) {
688 case NL80211_IFTYPE_AP:
689 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200690 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700691 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200692 break;
693 case NL80211_IFTYPE_ADHOC:
694 if (!wdev->current_bss)
695 return -ENOLINK;
696 break;
697 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200698 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200699 if (wdev->sme_state != CFG80211_SME_CONNECTED)
700 return -ENOLINK;
701 break;
702 default:
703 return -EINVAL;
704 }
705
706 return 0;
707}
708
Johannes Berg7527a782011-05-13 10:58:57 +0200709static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
710{
711 struct nlattr *nl_modes = nla_nest_start(msg, attr);
712 int i;
713
714 if (!nl_modes)
715 goto nla_put_failure;
716
717 i = 0;
718 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400719 if ((ifmodes & 1) && nla_put_flag(msg, i))
720 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200721 ifmodes >>= 1;
722 i++;
723 }
724
725 nla_nest_end(msg, nl_modes);
726 return 0;
727
728nla_put_failure:
729 return -ENOBUFS;
730}
731
732static int nl80211_put_iface_combinations(struct wiphy *wiphy,
733 struct sk_buff *msg)
734{
735 struct nlattr *nl_combis;
736 int i, j;
737
738 nl_combis = nla_nest_start(msg,
739 NL80211_ATTR_INTERFACE_COMBINATIONS);
740 if (!nl_combis)
741 goto nla_put_failure;
742
743 for (i = 0; i < wiphy->n_iface_combinations; i++) {
744 const struct ieee80211_iface_combination *c;
745 struct nlattr *nl_combi, *nl_limits;
746
747 c = &wiphy->iface_combinations[i];
748
749 nl_combi = nla_nest_start(msg, i + 1);
750 if (!nl_combi)
751 goto nla_put_failure;
752
753 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
754 if (!nl_limits)
755 goto nla_put_failure;
756
757 for (j = 0; j < c->n_limits; j++) {
758 struct nlattr *nl_limit;
759
760 nl_limit = nla_nest_start(msg, j + 1);
761 if (!nl_limit)
762 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400763 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
764 c->limits[j].max))
765 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200766 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
767 c->limits[j].types))
768 goto nla_put_failure;
769 nla_nest_end(msg, nl_limit);
770 }
771
772 nla_nest_end(msg, nl_limits);
773
David S. Miller9360ffd2012-03-29 04:41:26 -0400774 if (c->beacon_int_infra_match &&
775 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
776 goto nla_put_failure;
777 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
778 c->num_different_channels) ||
779 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
780 c->max_interfaces))
781 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200782
783 nla_nest_end(msg, nl_combi);
784 }
785
786 nla_nest_end(msg, nl_combis);
787
788 return 0;
789nla_put_failure:
790 return -ENOBUFS;
791}
792
Johannes Berg55682962007-09-20 13:09:35 -0400793static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
794 struct cfg80211_registered_device *dev)
795{
796 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100797 struct nlattr *nl_bands, *nl_band;
798 struct nlattr *nl_freqs, *nl_freq;
799 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100800 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100801 enum ieee80211_band band;
802 struct ieee80211_channel *chan;
803 struct ieee80211_rate *rate;
804 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200805 const struct ieee80211_txrx_stypes *mgmt_stypes =
806 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400807
808 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
809 if (!hdr)
810 return -1;
811
David S. Miller9360ffd2012-03-29 04:41:26 -0400812 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
813 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
814 nla_put_u32(msg, NL80211_ATTR_GENERATION,
815 cfg80211_rdev_list_generation) ||
816 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
817 dev->wiphy.retry_short) ||
818 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
819 dev->wiphy.retry_long) ||
820 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
821 dev->wiphy.frag_threshold) ||
822 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
823 dev->wiphy.rts_threshold) ||
824 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
825 dev->wiphy.coverage_class) ||
826 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
827 dev->wiphy.max_scan_ssids) ||
828 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
829 dev->wiphy.max_sched_scan_ssids) ||
830 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
831 dev->wiphy.max_scan_ie_len) ||
832 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
833 dev->wiphy.max_sched_scan_ie_len) ||
834 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
835 dev->wiphy.max_match_sets))
836 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200837
David S. Miller9360ffd2012-03-29 04:41:26 -0400838 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
839 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
840 goto nla_put_failure;
841 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
842 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
843 goto nla_put_failure;
844 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
845 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
846 goto nla_put_failure;
847 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
848 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
849 goto nla_put_failure;
850 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
851 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
852 goto nla_put_failure;
853 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
854 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
855 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200856
David S. Miller9360ffd2012-03-29 04:41:26 -0400857 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
858 sizeof(u32) * dev->wiphy.n_cipher_suites,
859 dev->wiphy.cipher_suites))
860 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100861
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
863 dev->wiphy.max_num_pmkids))
864 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530865
David S. Miller9360ffd2012-03-29 04:41:26 -0400866 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
867 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
868 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200869
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
871 dev->wiphy.available_antennas_tx) ||
872 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
873 dev->wiphy.available_antennas_rx))
874 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100875
David S. Miller9360ffd2012-03-29 04:41:26 -0400876 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
877 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
878 dev->wiphy.probe_resp_offload))
879 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200880
Bruno Randolf7f531e02010-12-16 11:30:22 +0900881 if ((dev->wiphy.available_antennas_tx ||
882 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900883 u32 tx_ant = 0, rx_ant = 0;
884 int res;
885 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
886 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
888 tx_ant) ||
889 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
890 rx_ant))
891 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900892 }
893 }
894
Johannes Berg7527a782011-05-13 10:58:57 +0200895 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
896 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700897 goto nla_put_failure;
898
Johannes Bergee688b002008-01-24 19:38:39 +0100899 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
900 if (!nl_bands)
901 goto nla_put_failure;
902
903 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
904 if (!dev->wiphy.bands[band])
905 continue;
906
907 nl_band = nla_nest_start(msg, band);
908 if (!nl_band)
909 goto nla_put_failure;
910
Johannes Bergd51626d2008-10-09 12:20:13 +0200911 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400912 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
913 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
914 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
915 &dev->wiphy.bands[band]->ht_cap.mcs) ||
916 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
917 dev->wiphy.bands[band]->ht_cap.cap) ||
918 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
919 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
920 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
921 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
922 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200923
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000924 /* add VHT info */
925 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
926 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
927 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
928 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
929 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
930 dev->wiphy.bands[band]->vht_cap.cap)))
931 goto nla_put_failure;
932
Johannes Bergee688b002008-01-24 19:38:39 +0100933 /* add frequencies */
934 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
935 if (!nl_freqs)
936 goto nla_put_failure;
937
938 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
939 nl_freq = nla_nest_start(msg, i);
940 if (!nl_freq)
941 goto nla_put_failure;
942
943 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100944
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400945 if (nl80211_msg_put_channel(msg, chan))
946 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200947
Johannes Bergee688b002008-01-24 19:38:39 +0100948 nla_nest_end(msg, nl_freq);
949 }
950
951 nla_nest_end(msg, nl_freqs);
952
953 /* add bitrates */
954 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
955 if (!nl_rates)
956 goto nla_put_failure;
957
958 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
959 nl_rate = nla_nest_start(msg, i);
960 if (!nl_rate)
961 goto nla_put_failure;
962
963 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400964 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
965 rate->bitrate))
966 goto nla_put_failure;
967 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
968 nla_put_flag(msg,
969 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
970 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100971
972 nla_nest_end(msg, nl_rate);
973 }
974
975 nla_nest_end(msg, nl_rates);
976
977 nla_nest_end(msg, nl_band);
978 }
979 nla_nest_end(msg, nl_bands);
980
Johannes Berg8fdc6212009-03-14 09:34:01 +0100981 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
982 if (!nl_cmds)
983 goto nla_put_failure;
984
985 i = 0;
986#define CMD(op, n) \
987 do { \
988 if (dev->ops->op) { \
989 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400990 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
991 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 } \
993 } while (0)
994
995 CMD(add_virtual_intf, NEW_INTERFACE);
996 CMD(change_virtual_intf, SET_INTERFACE);
997 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100998 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100999 CMD(add_station, NEW_STATION);
1000 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001001 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001002 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001003 CMD(auth, AUTHENTICATE);
1004 CMD(assoc, ASSOCIATE);
1005 CMD(deauth, DEAUTHENTICATE);
1006 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001007 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001008 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001009 CMD(set_pmksa, SET_PMKSA);
1010 CMD(del_pmksa, DEL_PMKSA);
1011 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001012 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1013 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001014 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001015 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001016 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001017 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001018 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001019 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1020 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001021 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001022 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001023 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001024 i++;
1025 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1026 goto nla_put_failure;
1027 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001028 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001029 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1030 CMD(tdls_mgmt, TDLS_MGMT);
1031 CMD(tdls_oper, TDLS_OPER);
1032 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001033 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1034 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001035 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001036 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e7602302011-11-04 11:18:17 +01001037 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1038 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001039 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1040 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01001041 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001042
Kalle Valo4745fc02011-11-17 19:06:10 +02001043#ifdef CONFIG_NL80211_TESTMODE
1044 CMD(testmode_cmd, TESTMODE);
1045#endif
1046
Johannes Berg8fdc6212009-03-14 09:34:01 +01001047#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001048
Johannes Berg6829c872009-07-02 09:13:27 +02001049 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001050 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1052 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001053 }
1054
Johannes Berg6829c872009-07-02 09:13:27 +02001055 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001056 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001057 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1058 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001059 }
1060
Johannes Berg8fdc6212009-03-14 09:34:01 +01001061 nla_nest_end(msg, nl_cmds);
1062
Johannes Berg7c4ef712011-11-18 15:33:48 +01001063 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001064 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1065 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1066 dev->wiphy.max_remain_on_channel_duration))
1067 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001068
David S. Miller9360ffd2012-03-29 04:41:26 -04001069 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1070 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1071 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001072
Johannes Berg2e161f72010-08-12 15:38:38 +02001073 if (mgmt_stypes) {
1074 u16 stypes;
1075 struct nlattr *nl_ftypes, *nl_ifs;
1076 enum nl80211_iftype ift;
1077
1078 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1079 if (!nl_ifs)
1080 goto nla_put_failure;
1081
1082 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1083 nl_ftypes = nla_nest_start(msg, ift);
1084 if (!nl_ftypes)
1085 goto nla_put_failure;
1086 i = 0;
1087 stypes = mgmt_stypes[ift].tx;
1088 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001089 if ((stypes & 1) &&
1090 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1091 (i << 4) | IEEE80211_FTYPE_MGMT))
1092 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001093 stypes >>= 1;
1094 i++;
1095 }
1096 nla_nest_end(msg, nl_ftypes);
1097 }
1098
Johannes Berg74b70a42010-08-24 12:15:53 +02001099 nla_nest_end(msg, nl_ifs);
1100
Johannes Berg2e161f72010-08-12 15:38:38 +02001101 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1102 if (!nl_ifs)
1103 goto nla_put_failure;
1104
1105 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1106 nl_ftypes = nla_nest_start(msg, ift);
1107 if (!nl_ftypes)
1108 goto nla_put_failure;
1109 i = 0;
1110 stypes = mgmt_stypes[ift].rx;
1111 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001112 if ((stypes & 1) &&
1113 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1114 (i << 4) | IEEE80211_FTYPE_MGMT))
1115 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001116 stypes >>= 1;
1117 i++;
1118 }
1119 nla_nest_end(msg, nl_ftypes);
1120 }
1121 nla_nest_end(msg, nl_ifs);
1122 }
1123
Johannes Bergdfb89c52012-06-27 09:23:48 +02001124#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001125 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1126 struct nlattr *nl_wowlan;
1127
1128 nl_wowlan = nla_nest_start(msg,
1129 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1130 if (!nl_wowlan)
1131 goto nla_put_failure;
1132
David S. Miller9360ffd2012-03-29 04:41:26 -04001133 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1135 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1136 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1137 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1138 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1139 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1140 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1141 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1143 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1144 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1145 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1147 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1148 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 if (dev->wiphy.wowlan.n_patterns) {
1151 struct nl80211_wowlan_pattern_support pat = {
1152 .max_patterns = dev->wiphy.wowlan.n_patterns,
1153 .min_pattern_len =
1154 dev->wiphy.wowlan.pattern_min_len,
1155 .max_pattern_len =
1156 dev->wiphy.wowlan.pattern_max_len,
1157 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001158 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1159 sizeof(pat), &pat))
1160 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001161 }
1162
1163 nla_nest_end(msg, nl_wowlan);
1164 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001165#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001166
Johannes Berg7527a782011-05-13 10:58:57 +02001167 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1168 dev->wiphy.software_iftypes))
1169 goto nla_put_failure;
1170
1171 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1172 goto nla_put_failure;
1173
David S. Miller9360ffd2012-03-29 04:41:26 -04001174 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1175 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1176 dev->wiphy.ap_sme_capa))
1177 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001178
David S. Miller9360ffd2012-03-29 04:41:26 -04001179 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1180 dev->wiphy.features))
1181 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001182
David S. Miller9360ffd2012-03-29 04:41:26 -04001183 if (dev->wiphy.ht_capa_mod_mask &&
1184 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1185 sizeof(*dev->wiphy.ht_capa_mod_mask),
1186 dev->wiphy.ht_capa_mod_mask))
1187 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001188
Johannes Berg55682962007-09-20 13:09:35 -04001189 return genlmsg_end(msg, hdr);
1190
1191 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001192 genlmsg_cancel(msg, hdr);
1193 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001194}
1195
1196static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1197{
1198 int idx = 0;
1199 int start = cb->args[0];
1200 struct cfg80211_registered_device *dev;
1201
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001202 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001203 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001204 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1205 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001206 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001207 continue;
1208 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1209 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001210 dev) < 0) {
1211 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001212 break;
Julius Volzb4637272008-07-08 14:02:19 +02001213 }
Johannes Berg55682962007-09-20 13:09:35 -04001214 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001215 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001216
1217 cb->args[0] = idx;
1218
1219 return skb->len;
1220}
1221
1222static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1223{
1224 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001225 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001226
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001227 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001228 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001229 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001230
Johannes Berg4c476992010-10-04 21:36:35 +02001231 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1232 nlmsg_free(msg);
1233 return -ENOBUFS;
1234 }
Johannes Berg55682962007-09-20 13:09:35 -04001235
Johannes Berg134e6372009-07-10 09:51:34 +00001236 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001237}
1238
Jouni Malinen31888482008-10-30 16:59:24 +02001239static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1240 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1241 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1242 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1243 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1244 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1245};
1246
1247static int parse_txq_params(struct nlattr *tb[],
1248 struct ieee80211_txq_params *txq_params)
1249{
Johannes Berga3304b02012-03-28 11:04:24 +02001250 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001251 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1252 !tb[NL80211_TXQ_ATTR_AIFS])
1253 return -EINVAL;
1254
Johannes Berga3304b02012-03-28 11:04:24 +02001255 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001256 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1257 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1258 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1259 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1260
Johannes Berga3304b02012-03-28 11:04:24 +02001261 if (txq_params->ac >= NL80211_NUM_ACS)
1262 return -EINVAL;
1263
Jouni Malinen31888482008-10-30 16:59:24 +02001264 return 0;
1265}
1266
Johannes Bergf444de02010-05-05 15:25:02 +02001267static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1268{
1269 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001270 * You can only set the channel explicitly for WDS interfaces,
1271 * all others have their channel managed via their respective
1272 * "establish a connection" command (connect, join, ...)
1273 *
1274 * For AP/GO and mesh mode, the channel can be set with the
1275 * channel userspace API, but is only stored and passed to the
1276 * low-level driver when the AP starts or the mesh is joined.
1277 * This is for backward compatibility, userspace can also give
1278 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001279 *
1280 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001281 * whatever else is going on, so they have their own special
1282 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001283 */
1284 return !wdev ||
1285 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001286 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001287 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1288 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001289}
1290
Johannes Bergcd6c6592012-05-10 21:27:18 +02001291static bool nl80211_valid_channel_type(struct genl_info *info,
1292 enum nl80211_channel_type *channel_type)
1293{
1294 enum nl80211_channel_type tmp;
1295
1296 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1297 return false;
1298
1299 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1300 if (tmp != NL80211_CHAN_NO_HT &&
1301 tmp != NL80211_CHAN_HT20 &&
1302 tmp != NL80211_CHAN_HT40PLUS &&
1303 tmp != NL80211_CHAN_HT40MINUS)
1304 return false;
1305
1306 if (channel_type)
1307 *channel_type = tmp;
1308
1309 return true;
1310}
1311
Johannes Bergf444de02010-05-05 15:25:02 +02001312static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1313 struct wireless_dev *wdev,
1314 struct genl_info *info)
1315{
Johannes Bergaa430da2012-05-16 23:50:18 +02001316 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001317 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1318 u32 freq;
1319 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001320 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1321
1322 if (wdev)
1323 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001324
1325 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1326 return -EINVAL;
1327
1328 if (!nl80211_can_set_dev_channel(wdev))
1329 return -EOPNOTSUPP;
1330
Johannes Bergcd6c6592012-05-10 21:27:18 +02001331 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1332 !nl80211_valid_channel_type(info, &channel_type))
1333 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001334
1335 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1336
1337 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001338 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001339 case NL80211_IFTYPE_AP:
1340 case NL80211_IFTYPE_P2P_GO:
1341 if (wdev->beacon_interval) {
1342 result = -EBUSY;
1343 break;
1344 }
1345 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1346 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1347 channel,
1348 channel_type)) {
1349 result = -EINVAL;
1350 break;
1351 }
1352 wdev->preset_chan = channel;
1353 wdev->preset_chantype = channel_type;
1354 result = 0;
1355 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001356 case NL80211_IFTYPE_MESH_POINT:
1357 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1358 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001359 case NL80211_IFTYPE_MONITOR:
1360 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1361 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001362 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001363 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001364 }
1365 mutex_unlock(&rdev->devlist_mtx);
1366
1367 return result;
1368}
1369
1370static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1371{
Johannes Berg4c476992010-10-04 21:36:35 +02001372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1373 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001374
Johannes Berg4c476992010-10-04 21:36:35 +02001375 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001376}
1377
Bill Jordane8347eb2010-10-01 13:54:28 -04001378static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1379{
Johannes Berg43b19952010-10-07 13:10:30 +02001380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1381 struct net_device *dev = info->user_ptr[1];
1382 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001383 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 if (!info->attrs[NL80211_ATTR_MAC])
1386 return -EINVAL;
1387
Johannes Berg43b19952010-10-07 13:10:30 +02001388 if (netif_running(dev))
1389 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001390
Johannes Berg43b19952010-10-07 13:10:30 +02001391 if (!rdev->ops->set_wds_peer)
1392 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001393
Johannes Berg43b19952010-10-07 13:10:30 +02001394 if (wdev->iftype != NL80211_IFTYPE_WDS)
1395 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001396
1397 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001398 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001399}
1400
1401
Johannes Berg55682962007-09-20 13:09:35 -04001402static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1403{
1404 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001405 struct net_device *netdev = NULL;
1406 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001407 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001408 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001409 u32 changed;
1410 u8 retry_short = 0, retry_long = 0;
1411 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001412 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001413
Johannes Bergf444de02010-05-05 15:25:02 +02001414 /*
1415 * Try to find the wiphy and netdev. Normally this
1416 * function shouldn't need the netdev, but this is
1417 * done for backward compatibility -- previously
1418 * setting the channel was done per wiphy, but now
1419 * it is per netdev. Previous userland like hostapd
1420 * also passed a netdev to set_wiphy, so that it is
1421 * possible to let that go to the right netdev!
1422 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001423 mutex_lock(&cfg80211_mutex);
1424
Johannes Bergf444de02010-05-05 15:25:02 +02001425 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1426 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1427
1428 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1429 if (netdev && netdev->ieee80211_ptr) {
1430 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1431 mutex_lock(&rdev->mtx);
1432 } else
1433 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001434 }
1435
Johannes Bergf444de02010-05-05 15:25:02 +02001436 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001437 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1438 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001439 if (IS_ERR(rdev)) {
1440 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001441 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001442 }
1443 wdev = NULL;
1444 netdev = NULL;
1445 result = 0;
1446
1447 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001448 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001449 wdev = netdev->ieee80211_ptr;
1450 else
1451 wdev = NULL;
1452
1453 /*
1454 * end workaround code, by now the rdev is available
1455 * and locked, and wdev may or may not be NULL.
1456 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001457
1458 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001459 result = cfg80211_dev_rename(
1460 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001461
1462 mutex_unlock(&cfg80211_mutex);
1463
1464 if (result)
1465 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001466
Jouni Malinen31888482008-10-30 16:59:24 +02001467 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1468 struct ieee80211_txq_params txq_params;
1469 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1470
1471 if (!rdev->ops->set_txq_params) {
1472 result = -EOPNOTSUPP;
1473 goto bad_res;
1474 }
1475
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001476 if (!netdev) {
1477 result = -EINVAL;
1478 goto bad_res;
1479 }
1480
Johannes Berg133a3ff2011-11-03 14:50:13 +01001481 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1482 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1483 result = -EINVAL;
1484 goto bad_res;
1485 }
1486
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001487 if (!netif_running(netdev)) {
1488 result = -ENETDOWN;
1489 goto bad_res;
1490 }
1491
Jouni Malinen31888482008-10-30 16:59:24 +02001492 nla_for_each_nested(nl_txq_params,
1493 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1494 rem_txq_params) {
1495 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1496 nla_data(nl_txq_params),
1497 nla_len(nl_txq_params),
1498 txq_params_policy);
1499 result = parse_txq_params(tb, &txq_params);
1500 if (result)
1501 goto bad_res;
1502
1503 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001504 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001505 &txq_params);
1506 if (result)
1507 goto bad_res;
1508 }
1509 }
1510
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001511 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001512 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001513 if (result)
1514 goto bad_res;
1515 }
1516
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001517 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1518 enum nl80211_tx_power_setting type;
1519 int idx, mbm = 0;
1520
1521 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001522 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001523 goto bad_res;
1524 }
1525
1526 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1527 type = nla_get_u32(info->attrs[idx]);
1528
1529 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1530 (type != NL80211_TX_POWER_AUTOMATIC)) {
1531 result = -EINVAL;
1532 goto bad_res;
1533 }
1534
1535 if (type != NL80211_TX_POWER_AUTOMATIC) {
1536 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1537 mbm = nla_get_u32(info->attrs[idx]);
1538 }
1539
1540 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1541 if (result)
1542 goto bad_res;
1543 }
1544
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001545 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1546 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1547 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001548 if ((!rdev->wiphy.available_antennas_tx &&
1549 !rdev->wiphy.available_antennas_rx) ||
1550 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001551 result = -EOPNOTSUPP;
1552 goto bad_res;
1553 }
1554
1555 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1556 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1557
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001558 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001559 * available antenna masks, except for the "all" mask */
1560 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1561 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001562 result = -EINVAL;
1563 goto bad_res;
1564 }
1565
Bruno Randolf7f531e02010-12-16 11:30:22 +09001566 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1567 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001568
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001569 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1570 if (result)
1571 goto bad_res;
1572 }
1573
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001574 changed = 0;
1575
1576 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1577 retry_short = nla_get_u8(
1578 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1579 if (retry_short == 0) {
1580 result = -EINVAL;
1581 goto bad_res;
1582 }
1583 changed |= WIPHY_PARAM_RETRY_SHORT;
1584 }
1585
1586 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1587 retry_long = nla_get_u8(
1588 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1589 if (retry_long == 0) {
1590 result = -EINVAL;
1591 goto bad_res;
1592 }
1593 changed |= WIPHY_PARAM_RETRY_LONG;
1594 }
1595
1596 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1597 frag_threshold = nla_get_u32(
1598 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1599 if (frag_threshold < 256) {
1600 result = -EINVAL;
1601 goto bad_res;
1602 }
1603 if (frag_threshold != (u32) -1) {
1604 /*
1605 * Fragments (apart from the last one) are required to
1606 * have even length. Make the fragmentation code
1607 * simpler by stripping LSB should someone try to use
1608 * odd threshold value.
1609 */
1610 frag_threshold &= ~0x1;
1611 }
1612 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1613 }
1614
1615 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1616 rts_threshold = nla_get_u32(
1617 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1618 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1619 }
1620
Lukáš Turek81077e82009-12-21 22:50:47 +01001621 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1622 coverage_class = nla_get_u8(
1623 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1624 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1625 }
1626
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001627 if (changed) {
1628 u8 old_retry_short, old_retry_long;
1629 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001630 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001631
1632 if (!rdev->ops->set_wiphy_params) {
1633 result = -EOPNOTSUPP;
1634 goto bad_res;
1635 }
1636
1637 old_retry_short = rdev->wiphy.retry_short;
1638 old_retry_long = rdev->wiphy.retry_long;
1639 old_frag_threshold = rdev->wiphy.frag_threshold;
1640 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001641 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001642
1643 if (changed & WIPHY_PARAM_RETRY_SHORT)
1644 rdev->wiphy.retry_short = retry_short;
1645 if (changed & WIPHY_PARAM_RETRY_LONG)
1646 rdev->wiphy.retry_long = retry_long;
1647 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1648 rdev->wiphy.frag_threshold = frag_threshold;
1649 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1650 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001651 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1652 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001653
1654 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1655 if (result) {
1656 rdev->wiphy.retry_short = old_retry_short;
1657 rdev->wiphy.retry_long = old_retry_long;
1658 rdev->wiphy.frag_threshold = old_frag_threshold;
1659 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001660 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001661 }
1662 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001663
Johannes Berg306d6112008-12-08 12:39:04 +01001664 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001665 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001666 if (netdev)
1667 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001668 return result;
1669}
1670
1671
1672static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001673 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001674 struct net_device *dev)
1675{
1676 void *hdr;
1677
1678 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1679 if (!hdr)
1680 return -1;
1681
David S. Miller9360ffd2012-03-29 04:41:26 -04001682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1683 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1684 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1685 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1686 dev->ieee80211_ptr->iftype) ||
1687 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1688 rdev->devlist_generation ^
1689 (cfg80211_rdev_list_generation << 2)))
1690 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001691
Michal Kazior2e165b82012-06-29 12:47:06 +02001692 if (rdev->monitor_channel) {
1693 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1694 rdev->monitor_channel->center_freq) ||
1695 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1696 rdev->monitor_channel_type))
John W. Linville59ef43e2012-04-18 14:17:13 -04001697 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001698 }
1699
Johannes Berg55682962007-09-20 13:09:35 -04001700 return genlmsg_end(msg, hdr);
1701
1702 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001703 genlmsg_cancel(msg, hdr);
1704 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001705}
1706
1707static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1708{
1709 int wp_idx = 0;
1710 int if_idx = 0;
1711 int wp_start = cb->args[0];
1712 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001713 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001714 struct wireless_dev *wdev;
1715
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001716 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001717 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1718 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001719 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001720 if (wp_idx < wp_start) {
1721 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001722 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001723 }
Johannes Berg55682962007-09-20 13:09:35 -04001724 if_idx = 0;
1725
Johannes Bergf5ea9122009-08-07 16:17:38 +02001726 mutex_lock(&rdev->devlist_mtx);
1727 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001728 if (if_idx < if_start) {
1729 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001730 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001731 }
Johannes Berg55682962007-09-20 13:09:35 -04001732 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1733 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001734 rdev, wdev->netdev) < 0) {
1735 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001736 goto out;
1737 }
1738 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001739 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001740 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001741
1742 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001743 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001744 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001745 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001746
1747 cb->args[0] = wp_idx;
1748 cb->args[1] = if_idx;
1749
1750 return skb->len;
1751}
1752
1753static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1754{
1755 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001756 struct cfg80211_registered_device *dev = info->user_ptr[0];
1757 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001758
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001759 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001760 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001761 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001762
Johannes Bergd7264052009-04-19 16:23:20 +02001763 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001764 dev, netdev) < 0) {
1765 nlmsg_free(msg);
1766 return -ENOBUFS;
1767 }
Johannes Berg55682962007-09-20 13:09:35 -04001768
Johannes Berg134e6372009-07-10 09:51:34 +00001769 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001770}
1771
Michael Wu66f7ac52008-01-31 19:48:22 +01001772static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1773 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1774 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1775 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1776 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1777 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1778};
1779
1780static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1781{
1782 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1783 int flag;
1784
1785 *mntrflags = 0;
1786
1787 if (!nla)
1788 return -EINVAL;
1789
1790 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1791 nla, mntr_flags_policy))
1792 return -EINVAL;
1793
1794 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1795 if (flags[flag])
1796 *mntrflags |= (1<<flag);
1797
1798 return 0;
1799}
1800
Johannes Berg9bc383d2009-11-19 11:55:19 +01001801static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001802 struct net_device *netdev, u8 use_4addr,
1803 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001804{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001805 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001806 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001807 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001808 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001809 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001810
1811 switch (iftype) {
1812 case NL80211_IFTYPE_AP_VLAN:
1813 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1814 return 0;
1815 break;
1816 case NL80211_IFTYPE_STATION:
1817 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1818 return 0;
1819 break;
1820 default:
1821 break;
1822 }
1823
1824 return -EOPNOTSUPP;
1825}
1826
Johannes Berg55682962007-09-20 13:09:35 -04001827static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1828{
Johannes Berg4c476992010-10-04 21:36:35 +02001829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001830 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001831 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001832 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001833 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001834 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001835 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001836
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001837 memset(&params, 0, sizeof(params));
1838
Johannes Berg04a773a2009-04-19 21:24:32 +02001839 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001840
Johannes Berg723b0382008-09-16 20:22:09 +02001841 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001842 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001843 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001844 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001845 if (ntype > NL80211_IFTYPE_MAX)
1846 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001847 }
1848
Johannes Berg92ffe052008-09-16 20:39:36 +02001849 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001850 struct wireless_dev *wdev = dev->ieee80211_ptr;
1851
Johannes Berg4c476992010-10-04 21:36:35 +02001852 if (ntype != NL80211_IFTYPE_MESH_POINT)
1853 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001854 if (netif_running(dev))
1855 return -EBUSY;
1856
1857 wdev_lock(wdev);
1858 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1859 IEEE80211_MAX_MESH_ID_LEN);
1860 wdev->mesh_id_up_len =
1861 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1862 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1863 wdev->mesh_id_up_len);
1864 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001865 }
1866
Felix Fietkau8b787642009-11-10 18:53:10 +01001867 if (info->attrs[NL80211_ATTR_4ADDR]) {
1868 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1869 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001870 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001871 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001872 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001873 } else {
1874 params.use_4addr = -1;
1875 }
1876
Johannes Berg92ffe052008-09-16 20:39:36 +02001877 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001878 if (ntype != NL80211_IFTYPE_MONITOR)
1879 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001880 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1881 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001882 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001883 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001884
1885 flags = &_flags;
1886 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001887 }
Johannes Berg3b858752009-03-12 09:55:09 +01001888
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001889 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001890 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001891 else
1892 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001893
Johannes Berg9bc383d2009-11-19 11:55:19 +01001894 if (!err && params.use_4addr != -1)
1895 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1896
Johannes Berg55682962007-09-20 13:09:35 -04001897 return err;
1898}
1899
1900static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1901{
Johannes Berg4c476992010-10-04 21:36:35 +02001902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001903 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001904 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001905 int err;
1906 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001907 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001908
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001909 memset(&params, 0, sizeof(params));
1910
Johannes Berg55682962007-09-20 13:09:35 -04001911 if (!info->attrs[NL80211_ATTR_IFNAME])
1912 return -EINVAL;
1913
1914 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1915 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1916 if (type > NL80211_IFTYPE_MAX)
1917 return -EINVAL;
1918 }
1919
Johannes Berg79c97e92009-07-07 03:56:12 +02001920 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001921 !(rdev->wiphy.interface_modes & (1 << type)))
1922 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001923
Johannes Berg9bc383d2009-11-19 11:55:19 +01001924 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001925 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001926 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001927 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001928 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001929 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001930
Michael Wu66f7ac52008-01-31 19:48:22 +01001931 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1932 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1933 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001934 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001935 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001936 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001937 if (IS_ERR(dev))
1938 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001939
Johannes Berg29cbe682010-12-03 09:20:44 +01001940 if (type == NL80211_IFTYPE_MESH_POINT &&
1941 info->attrs[NL80211_ATTR_MESH_ID]) {
1942 struct wireless_dev *wdev = dev->ieee80211_ptr;
1943
1944 wdev_lock(wdev);
1945 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1946 IEEE80211_MAX_MESH_ID_LEN);
1947 wdev->mesh_id_up_len =
1948 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1949 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1950 wdev->mesh_id_up_len);
1951 wdev_unlock(wdev);
1952 }
1953
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001954 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001955}
1956
1957static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1958{
Johannes Berg4c476992010-10-04 21:36:35 +02001959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1960 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001961
Johannes Berg4c476992010-10-04 21:36:35 +02001962 if (!rdev->ops->del_virtual_intf)
1963 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001964
Johannes Berg4c476992010-10-04 21:36:35 +02001965 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001966}
1967
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001968static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1969{
1970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1971 struct net_device *dev = info->user_ptr[1];
1972 u16 noack_map;
1973
1974 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1975 return -EINVAL;
1976
1977 if (!rdev->ops->set_noack_map)
1978 return -EOPNOTSUPP;
1979
1980 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1981
1982 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1983}
1984
Johannes Berg41ade002007-12-19 02:03:29 +01001985struct get_key_cookie {
1986 struct sk_buff *msg;
1987 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001988 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001989};
1990
1991static void get_key_callback(void *c, struct key_params *params)
1992{
Johannes Bergb9454e82009-07-08 13:29:08 +02001993 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001994 struct get_key_cookie *cookie = c;
1995
David S. Miller9360ffd2012-03-29 04:41:26 -04001996 if ((params->key &&
1997 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1998 params->key_len, params->key)) ||
1999 (params->seq &&
2000 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2001 params->seq_len, params->seq)) ||
2002 (params->cipher &&
2003 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2004 params->cipher)))
2005 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002006
Johannes Bergb9454e82009-07-08 13:29:08 +02002007 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2008 if (!key)
2009 goto nla_put_failure;
2010
David S. Miller9360ffd2012-03-29 04:41:26 -04002011 if ((params->key &&
2012 nla_put(cookie->msg, NL80211_KEY_DATA,
2013 params->key_len, params->key)) ||
2014 (params->seq &&
2015 nla_put(cookie->msg, NL80211_KEY_SEQ,
2016 params->seq_len, params->seq)) ||
2017 (params->cipher &&
2018 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2019 params->cipher)))
2020 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002021
David S. Miller9360ffd2012-03-29 04:41:26 -04002022 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2023 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002024
2025 nla_nest_end(cookie->msg, key);
2026
Johannes Berg41ade002007-12-19 02:03:29 +01002027 return;
2028 nla_put_failure:
2029 cookie->error = 1;
2030}
2031
2032static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2033{
Johannes Berg4c476992010-10-04 21:36:35 +02002034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002035 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002036 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002037 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002038 const u8 *mac_addr = NULL;
2039 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002040 struct get_key_cookie cookie = {
2041 .error = 0,
2042 };
2043 void *hdr;
2044 struct sk_buff *msg;
2045
2046 if (info->attrs[NL80211_ATTR_KEY_IDX])
2047 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2048
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002049 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002050 return -EINVAL;
2051
2052 if (info->attrs[NL80211_ATTR_MAC])
2053 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2054
Johannes Berge31b8212010-10-05 19:39:30 +02002055 pairwise = !!mac_addr;
2056 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2057 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2058 if (kt >= NUM_NL80211_KEYTYPES)
2059 return -EINVAL;
2060 if (kt != NL80211_KEYTYPE_GROUP &&
2061 kt != NL80211_KEYTYPE_PAIRWISE)
2062 return -EINVAL;
2063 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2064 }
2065
Johannes Berg4c476992010-10-04 21:36:35 +02002066 if (!rdev->ops->get_key)
2067 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002068
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002070 if (!msg)
2071 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002072
2073 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2074 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002075 if (IS_ERR(hdr))
2076 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002077
2078 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002079 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002080
David S. Miller9360ffd2012-03-29 04:41:26 -04002081 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2082 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2083 goto nla_put_failure;
2084 if (mac_addr &&
2085 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2086 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002087
Johannes Berge31b8212010-10-05 19:39:30 +02002088 if (pairwise && mac_addr &&
2089 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2090 return -ENOENT;
2091
2092 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2093 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002094
2095 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002096 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002097
2098 if (cookie.error)
2099 goto nla_put_failure;
2100
2101 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002102 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002103
2104 nla_put_failure:
2105 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002106 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002107 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002108 return err;
2109}
2110
2111static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2112{
Johannes Berg4c476992010-10-04 21:36:35 +02002113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002114 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002115 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002116 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002117
Johannes Bergb9454e82009-07-08 13:29:08 +02002118 err = nl80211_parse_key(info, &key);
2119 if (err)
2120 return err;
2121
2122 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002123 return -EINVAL;
2124
Johannes Bergb9454e82009-07-08 13:29:08 +02002125 /* only support setting default key */
2126 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002127 return -EINVAL;
2128
Johannes Bergfffd0932009-07-08 14:22:54 +02002129 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002130
2131 if (key.def) {
2132 if (!rdev->ops->set_default_key) {
2133 err = -EOPNOTSUPP;
2134 goto out;
2135 }
2136
2137 err = nl80211_key_allowed(dev->ieee80211_ptr);
2138 if (err)
2139 goto out;
2140
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002141 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2142 key.def_uni, key.def_multi);
2143
2144 if (err)
2145 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002146
Johannes Berg3d23e342009-09-29 23:27:28 +02002147#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002148 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002149#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002150 } else {
2151 if (key.def_uni || !key.def_multi) {
2152 err = -EINVAL;
2153 goto out;
2154 }
2155
2156 if (!rdev->ops->set_default_mgmt_key) {
2157 err = -EOPNOTSUPP;
2158 goto out;
2159 }
2160
2161 err = nl80211_key_allowed(dev->ieee80211_ptr);
2162 if (err)
2163 goto out;
2164
2165 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2166 dev, key.idx);
2167 if (err)
2168 goto out;
2169
2170#ifdef CONFIG_CFG80211_WEXT
2171 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2172#endif
2173 }
2174
2175 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002176 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002177
Johannes Berg41ade002007-12-19 02:03:29 +01002178 return err;
2179}
2180
2181static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2182{
Johannes Berg4c476992010-10-04 21:36:35 +02002183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002184 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002185 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002186 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002187 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002188
Johannes Bergb9454e82009-07-08 13:29:08 +02002189 err = nl80211_parse_key(info, &key);
2190 if (err)
2191 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002192
Johannes Bergb9454e82009-07-08 13:29:08 +02002193 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002194 return -EINVAL;
2195
Johannes Berg41ade002007-12-19 02:03:29 +01002196 if (info->attrs[NL80211_ATTR_MAC])
2197 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2198
Johannes Berge31b8212010-10-05 19:39:30 +02002199 if (key.type == -1) {
2200 if (mac_addr)
2201 key.type = NL80211_KEYTYPE_PAIRWISE;
2202 else
2203 key.type = NL80211_KEYTYPE_GROUP;
2204 }
2205
2206 /* for now */
2207 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2208 key.type != NL80211_KEYTYPE_GROUP)
2209 return -EINVAL;
2210
Johannes Berg4c476992010-10-04 21:36:35 +02002211 if (!rdev->ops->add_key)
2212 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002213
Johannes Berge31b8212010-10-05 19:39:30 +02002214 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2215 key.type == NL80211_KEYTYPE_PAIRWISE,
2216 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002217 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002218
2219 wdev_lock(dev->ieee80211_ptr);
2220 err = nl80211_key_allowed(dev->ieee80211_ptr);
2221 if (!err)
2222 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002223 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002224 mac_addr, &key.p);
2225 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002226
Johannes Berg41ade002007-12-19 02:03:29 +01002227 return err;
2228}
2229
2230static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2231{
Johannes Berg4c476992010-10-04 21:36:35 +02002232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002233 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002234 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002235 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002236 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002237
Johannes Bergb9454e82009-07-08 13:29:08 +02002238 err = nl80211_parse_key(info, &key);
2239 if (err)
2240 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002241
2242 if (info->attrs[NL80211_ATTR_MAC])
2243 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2244
Johannes Berge31b8212010-10-05 19:39:30 +02002245 if (key.type == -1) {
2246 if (mac_addr)
2247 key.type = NL80211_KEYTYPE_PAIRWISE;
2248 else
2249 key.type = NL80211_KEYTYPE_GROUP;
2250 }
2251
2252 /* for now */
2253 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2254 key.type != NL80211_KEYTYPE_GROUP)
2255 return -EINVAL;
2256
Johannes Berg4c476992010-10-04 21:36:35 +02002257 if (!rdev->ops->del_key)
2258 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002259
Johannes Bergfffd0932009-07-08 14:22:54 +02002260 wdev_lock(dev->ieee80211_ptr);
2261 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002262
2263 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2264 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2265 err = -ENOENT;
2266
Johannes Bergfffd0932009-07-08 14:22:54 +02002267 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002268 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2269 key.type == NL80211_KEYTYPE_PAIRWISE,
2270 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002271
Johannes Berg3d23e342009-09-29 23:27:28 +02002272#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002273 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002274 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002275 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002276 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002277 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2278 }
2279#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002280 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002281
Johannes Berg41ade002007-12-19 02:03:29 +01002282 return err;
2283}
2284
Johannes Berg88600202012-02-13 15:17:18 +01002285static int nl80211_parse_beacon(struct genl_info *info,
2286 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002287{
Johannes Berg88600202012-02-13 15:17:18 +01002288 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002289
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002290 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2291 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2292 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2293 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002294 return -EINVAL;
2295
Johannes Berg88600202012-02-13 15:17:18 +01002296 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002297
Johannes Berged1b6cc2007-12-19 02:03:32 +01002298 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002299 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2300 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2301 if (!bcn->head_len)
2302 return -EINVAL;
2303 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002304 }
2305
2306 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002307 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2308 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002309 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002310 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002311 }
2312
Johannes Berg4c476992010-10-04 21:36:35 +02002313 if (!haveinfo)
2314 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002315
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002316 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002317 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2318 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002319 }
2320
2321 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002323 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002324 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002325 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2326 }
2327
2328 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002330 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002331 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002332 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2333 }
2334
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002335 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002336 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002337 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002338 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002339 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2340 }
2341
Johannes Berg88600202012-02-13 15:17:18 +01002342 return 0;
2343}
2344
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002345static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2346 struct cfg80211_ap_settings *params)
2347{
2348 struct wireless_dev *wdev;
2349 bool ret = false;
2350
2351 mutex_lock(&rdev->devlist_mtx);
2352
2353 list_for_each_entry(wdev, &rdev->netdev_list, list) {
2354 if (wdev->iftype != NL80211_IFTYPE_AP &&
2355 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2356 continue;
2357
2358 if (!wdev->preset_chan)
2359 continue;
2360
2361 params->channel = wdev->preset_chan;
2362 params->channel_type = wdev->preset_chantype;
2363 ret = true;
2364 break;
2365 }
2366
2367 mutex_unlock(&rdev->devlist_mtx);
2368
2369 return ret;
2370}
2371
Johannes Berg88600202012-02-13 15:17:18 +01002372static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2373{
2374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2375 struct net_device *dev = info->user_ptr[1];
2376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377 struct cfg80211_ap_settings params;
2378 int err;
2379
2380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2382 return -EOPNOTSUPP;
2383
2384 if (!rdev->ops->start_ap)
2385 return -EOPNOTSUPP;
2386
2387 if (wdev->beacon_interval)
2388 return -EALREADY;
2389
2390 memset(&params, 0, sizeof(params));
2391
2392 /* these are required for START_AP */
2393 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2394 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2395 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2396 return -EINVAL;
2397
2398 err = nl80211_parse_beacon(info, &params.beacon);
2399 if (err)
2400 return err;
2401
2402 params.beacon_interval =
2403 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2404 params.dtim_period =
2405 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2406
2407 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2408 if (err)
2409 return err;
2410
2411 /*
2412 * In theory, some of these attributes should be required here
2413 * but since they were not used when the command was originally
2414 * added, keep them optional for old user space programs to let
2415 * them continue to work with drivers that do not need the
2416 * additional information -- drivers must check!
2417 */
2418 if (info->attrs[NL80211_ATTR_SSID]) {
2419 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2420 params.ssid_len =
2421 nla_len(info->attrs[NL80211_ATTR_SSID]);
2422 if (params.ssid_len == 0 ||
2423 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2424 return -EINVAL;
2425 }
2426
2427 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2428 params.hidden_ssid = nla_get_u32(
2429 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2430 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2431 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2432 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2433 return -EINVAL;
2434 }
2435
2436 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2437
2438 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2439 params.auth_type = nla_get_u32(
2440 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2441 if (!nl80211_valid_auth_type(params.auth_type))
2442 return -EINVAL;
2443 } else
2444 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2445
2446 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2447 NL80211_MAX_NR_CIPHER_SUITES);
2448 if (err)
2449 return err;
2450
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302451 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2452 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2453 return -EOPNOTSUPP;
2454 params.inactivity_timeout = nla_get_u16(
2455 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2456 }
2457
Johannes Bergaa430da2012-05-16 23:50:18 +02002458 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2459 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2460
2461 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2462 !nl80211_valid_channel_type(info, &channel_type))
2463 return -EINVAL;
2464
2465 params.channel = rdev_freq_to_chan(rdev,
2466 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2467 channel_type);
2468 if (!params.channel)
2469 return -EINVAL;
2470 params.channel_type = channel_type;
2471 } else if (wdev->preset_chan) {
2472 params.channel = wdev->preset_chan;
2473 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002474 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002475 return -EINVAL;
2476
2477 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2478 params.channel_type))
2479 return -EINVAL;
2480
Johannes Berg88600202012-02-13 15:17:18 +01002481 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002482 if (!err) {
2483 wdev->preset_chan = params.channel;
2484 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002485 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002486 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002487 }
Johannes Berg56d18932011-05-09 18:41:15 +02002488 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002489}
2490
Johannes Berg88600202012-02-13 15:17:18 +01002491static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2492{
2493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2494 struct net_device *dev = info->user_ptr[1];
2495 struct wireless_dev *wdev = dev->ieee80211_ptr;
2496 struct cfg80211_beacon_data params;
2497 int err;
2498
2499 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2500 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2501 return -EOPNOTSUPP;
2502
2503 if (!rdev->ops->change_beacon)
2504 return -EOPNOTSUPP;
2505
2506 if (!wdev->beacon_interval)
2507 return -EINVAL;
2508
2509 err = nl80211_parse_beacon(info, &params);
2510 if (err)
2511 return err;
2512
2513 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2514}
2515
2516static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002517{
Johannes Berg4c476992010-10-04 21:36:35 +02002518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2519 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002520
Michal Kazior60771782012-06-29 12:46:56 +02002521 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002522}
2523
Johannes Berg5727ef12007-12-19 02:03:34 +01002524static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2525 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2526 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2527 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002528 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002529 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002530 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002531};
2532
Johannes Bergeccb8e82009-05-11 21:57:56 +03002533static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002534 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002535 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002536{
2537 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002538 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002539 int flag;
2540
Johannes Bergeccb8e82009-05-11 21:57:56 +03002541 /*
2542 * Try parsing the new attribute first so userspace
2543 * can specify both for older kernels.
2544 */
2545 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2546 if (nla) {
2547 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002548
Johannes Bergeccb8e82009-05-11 21:57:56 +03002549 sta_flags = nla_data(nla);
2550 params->sta_flags_mask = sta_flags->mask;
2551 params->sta_flags_set = sta_flags->set;
2552 if ((params->sta_flags_mask |
2553 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2554 return -EINVAL;
2555 return 0;
2556 }
2557
2558 /* if present, parse the old attribute */
2559
2560 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002561 if (!nla)
2562 return 0;
2563
2564 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2565 nla, sta_flags_policy))
2566 return -EINVAL;
2567
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002568 /*
2569 * Only allow certain flags for interface types so that
2570 * other attributes are silently ignored. Remember that
2571 * this is backward compatibility code with old userspace
2572 * and shouldn't be hit in other cases anyway.
2573 */
2574 switch (iftype) {
2575 case NL80211_IFTYPE_AP:
2576 case NL80211_IFTYPE_AP_VLAN:
2577 case NL80211_IFTYPE_P2P_GO:
2578 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2579 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2580 BIT(NL80211_STA_FLAG_WME) |
2581 BIT(NL80211_STA_FLAG_MFP);
2582 break;
2583 case NL80211_IFTYPE_P2P_CLIENT:
2584 case NL80211_IFTYPE_STATION:
2585 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2586 BIT(NL80211_STA_FLAG_TDLS_PEER);
2587 break;
2588 case NL80211_IFTYPE_MESH_POINT:
2589 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2590 BIT(NL80211_STA_FLAG_MFP) |
2591 BIT(NL80211_STA_FLAG_AUTHORIZED);
2592 default:
2593 return -EINVAL;
2594 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002595
Johannes Berg3383b5a2012-05-10 20:14:43 +02002596 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2597 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002598 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002599
Johannes Berg3383b5a2012-05-10 20:14:43 +02002600 /* no longer support new API additions in old API */
2601 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2602 return -EINVAL;
2603 }
2604 }
2605
Johannes Berg5727ef12007-12-19 02:03:34 +01002606 return 0;
2607}
2608
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002609static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2610 int attr)
2611{
2612 struct nlattr *rate;
2613 u16 bitrate;
2614
2615 rate = nla_nest_start(msg, attr);
2616 if (!rate)
2617 goto nla_put_failure;
2618
2619 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2620 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002621 if ((bitrate > 0 &&
2622 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2623 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2624 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2625 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2626 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2627 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2628 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2629 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002630
2631 nla_nest_end(msg, rate);
2632 return true;
2633
2634nla_put_failure:
2635 return false;
2636}
2637
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002638static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002639 int flags,
2640 struct cfg80211_registered_device *rdev,
2641 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002642 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002643{
2644 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002645 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002646
2647 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2648 if (!hdr)
2649 return -1;
2650
David S. Miller9360ffd2012-03-29 04:41:26 -04002651 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2652 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2653 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2654 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002655
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002656 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2657 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002658 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002659 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2660 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2661 sinfo->connected_time))
2662 goto nla_put_failure;
2663 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2664 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2665 sinfo->inactive_time))
2666 goto nla_put_failure;
2667 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2668 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2669 sinfo->rx_bytes))
2670 goto nla_put_failure;
2671 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2672 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2673 sinfo->tx_bytes))
2674 goto nla_put_failure;
2675 if ((sinfo->filled & STATION_INFO_LLID) &&
2676 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2677 goto nla_put_failure;
2678 if ((sinfo->filled & STATION_INFO_PLID) &&
2679 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2680 goto nla_put_failure;
2681 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2682 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2683 sinfo->plink_state))
2684 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002685 switch (rdev->wiphy.signal_type) {
2686 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002687 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2688 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2689 sinfo->signal))
2690 goto nla_put_failure;
2691 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2692 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2693 sinfo->signal_avg))
2694 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002695 break;
2696 default:
2697 break;
2698 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002699 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002700 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2701 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002702 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002703 }
2704 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2705 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2706 NL80211_STA_INFO_RX_BITRATE))
2707 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002708 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002709 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2710 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2711 sinfo->rx_packets))
2712 goto nla_put_failure;
2713 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2714 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2715 sinfo->tx_packets))
2716 goto nla_put_failure;
2717 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2718 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2719 sinfo->tx_retries))
2720 goto nla_put_failure;
2721 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2722 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2723 sinfo->tx_failed))
2724 goto nla_put_failure;
2725 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2726 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2727 sinfo->beacon_loss_count))
2728 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002729 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2730 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2731 if (!bss_param)
2732 goto nla_put_failure;
2733
David S. Miller9360ffd2012-03-29 04:41:26 -04002734 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2735 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2736 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2737 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2738 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2739 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2740 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2741 sinfo->bss_param.dtim_period) ||
2742 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2743 sinfo->bss_param.beacon_interval))
2744 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002745
2746 nla_nest_end(msg, bss_param);
2747 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002748 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2749 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2750 sizeof(struct nl80211_sta_flag_update),
2751 &sinfo->sta_flags))
2752 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002753 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2754 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2755 sinfo->t_offset))
2756 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002757 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002758
David S. Miller9360ffd2012-03-29 04:41:26 -04002759 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2760 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2761 sinfo->assoc_req_ies))
2762 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002763
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002764 return genlmsg_end(msg, hdr);
2765
2766 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002767 genlmsg_cancel(msg, hdr);
2768 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002769}
2770
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002771static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002772 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002773{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002774 struct station_info sinfo;
2775 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002776 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002777 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002778 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002779 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002780
Johannes Berg67748892010-10-04 21:14:06 +02002781 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2782 if (err)
2783 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002784
2785 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002786 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002787 goto out_err;
2788 }
2789
Johannes Bergbba95fe2008-07-29 13:22:51 +02002790 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002791 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002792 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2793 mac_addr, &sinfo);
2794 if (err == -ENOENT)
2795 break;
2796 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002797 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002798
2799 if (nl80211_send_station(skb,
2800 NETLINK_CB(cb->skb).pid,
2801 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002802 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002803 &sinfo) < 0)
2804 goto out;
2805
2806 sta_idx++;
2807 }
2808
2809
2810 out:
2811 cb->args[1] = sta_idx;
2812 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002813 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002814 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002815
2816 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002817}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002818
Johannes Berg5727ef12007-12-19 02:03:34 +01002819static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2820{
Johannes Berg4c476992010-10-04 21:36:35 +02002821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2822 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002823 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002824 struct sk_buff *msg;
2825 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002826 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002827
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002828 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002829
2830 if (!info->attrs[NL80211_ATTR_MAC])
2831 return -EINVAL;
2832
2833 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2834
Johannes Berg4c476992010-10-04 21:36:35 +02002835 if (!rdev->ops->get_station)
2836 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002837
Johannes Berg79c97e92009-07-07 03:56:12 +02002838 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002839 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002840 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002841
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002843 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002844 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002845
2846 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002847 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002848 nlmsg_free(msg);
2849 return -ENOBUFS;
2850 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002851
Johannes Berg4c476992010-10-04 21:36:35 +02002852 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002853}
2854
2855/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002856 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002857 */
Johannes Berg80b99892011-11-18 16:23:01 +01002858static struct net_device *get_vlan(struct genl_info *info,
2859 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002860{
Johannes Berg463d0182009-07-14 00:33:35 +02002861 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002862 struct net_device *v;
2863 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002864
Johannes Berg80b99892011-11-18 16:23:01 +01002865 if (!vlanattr)
2866 return NULL;
2867
2868 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2869 if (!v)
2870 return ERR_PTR(-ENODEV);
2871
2872 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2873 ret = -EINVAL;
2874 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002875 }
Johannes Berg80b99892011-11-18 16:23:01 +01002876
2877 if (!netif_running(v)) {
2878 ret = -ENETDOWN;
2879 goto error;
2880 }
2881
2882 return v;
2883 error:
2884 dev_put(v);
2885 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002886}
2887
2888static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2889{
Johannes Berg4c476992010-10-04 21:36:35 +02002890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002891 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002892 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002893 struct station_parameters params;
2894 u8 *mac_addr = NULL;
2895
2896 memset(&params, 0, sizeof(params));
2897
2898 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002899 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002900
2901 if (info->attrs[NL80211_ATTR_STA_AID])
2902 return -EINVAL;
2903
2904 if (!info->attrs[NL80211_ATTR_MAC])
2905 return -EINVAL;
2906
2907 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2908
2909 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2910 params.supported_rates =
2911 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2912 params.supported_rates_len =
2913 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2914 }
2915
2916 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2917 params.listen_interval =
2918 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2919
Jouni Malinen36aedc902008-08-25 11:58:58 +03002920 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2921 params.ht_capa =
2922 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2923
Johannes Bergbdd90d52011-12-14 12:20:27 +01002924 if (!rdev->ops->change_station)
2925 return -EOPNOTSUPP;
2926
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002927 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002928 return -EINVAL;
2929
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002930 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2931 params.plink_action =
2932 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2933
Javier Cardona9c3990a2011-05-03 16:57:11 -07002934 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2935 params.plink_state =
2936 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2937
Johannes Berga97f4422009-06-18 17:23:43 +02002938 switch (dev->ieee80211_ptr->iftype) {
2939 case NL80211_IFTYPE_AP:
2940 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002941 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002942 /* disallow mesh-specific things */
2943 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002944 return -EINVAL;
2945
2946 /* TDLS can't be set, ... */
2947 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2948 return -EINVAL;
2949 /*
2950 * ... but don't bother the driver with it. This works around
2951 * a hostapd/wpa_supplicant issue -- it always includes the
2952 * TLDS_PEER flag in the mask even for AP mode.
2953 */
2954 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2955
2956 /* accept only the listed bits */
2957 if (params.sta_flags_mask &
2958 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2959 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2960 BIT(NL80211_STA_FLAG_WME) |
2961 BIT(NL80211_STA_FLAG_MFP)))
2962 return -EINVAL;
2963
2964 /* must be last in here for error handling */
2965 params.vlan = get_vlan(info, rdev);
2966 if (IS_ERR(params.vlan))
2967 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002968 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002969 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002970 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002971 /*
2972 * Don't allow userspace to change the TDLS_PEER flag,
2973 * but silently ignore attempts to change it since we
2974 * don't have state here to verify that it doesn't try
2975 * to change the flag.
2976 */
2977 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002978 /* fall through */
2979 case NL80211_IFTYPE_ADHOC:
2980 /* disallow things sta doesn't support */
2981 if (params.plink_action)
2982 return -EINVAL;
2983 if (params.ht_capa)
2984 return -EINVAL;
2985 if (params.listen_interval >= 0)
2986 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002987 /* reject any changes other than AUTHORIZED */
2988 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2989 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002990 break;
2991 case NL80211_IFTYPE_MESH_POINT:
2992 /* disallow things mesh doesn't support */
2993 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002994 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002995 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002996 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002997 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002998 return -EINVAL;
2999 /*
3000 * No special handling for TDLS here -- the userspace
3001 * mesh code doesn't have this bug.
3002 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003003 if (params.sta_flags_mask &
3004 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003005 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003006 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003007 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003008 break;
3009 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003010 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003011 }
3012
Johannes Bergbdd90d52011-12-14 12:20:27 +01003013 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003014
Johannes Berg79c97e92009-07-07 03:56:12 +02003015 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003016
Johannes Berg5727ef12007-12-19 02:03:34 +01003017 if (params.vlan)
3018 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003019
Johannes Berg5727ef12007-12-19 02:03:34 +01003020 return err;
3021}
3022
Eliad Pellerc75786c2011-08-23 14:37:46 +03003023static struct nla_policy
3024nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3025 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3026 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3027};
3028
Johannes Berg5727ef12007-12-19 02:03:34 +01003029static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3030{
Johannes Berg4c476992010-10-04 21:36:35 +02003031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003032 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003033 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003034 struct station_parameters params;
3035 u8 *mac_addr = NULL;
3036
3037 memset(&params, 0, sizeof(params));
3038
3039 if (!info->attrs[NL80211_ATTR_MAC])
3040 return -EINVAL;
3041
Johannes Berg5727ef12007-12-19 02:03:34 +01003042 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3043 return -EINVAL;
3044
3045 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3046 return -EINVAL;
3047
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003048 if (!info->attrs[NL80211_ATTR_STA_AID])
3049 return -EINVAL;
3050
Johannes Berg5727ef12007-12-19 02:03:34 +01003051 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3052 params.supported_rates =
3053 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3054 params.supported_rates_len =
3055 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3056 params.listen_interval =
3057 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003058
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003059 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3060 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3061 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003062
Jouni Malinen36aedc902008-08-25 11:58:58 +03003063 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3064 params.ht_capa =
3065 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003066
Javier Cardona96b78df2011-04-07 15:08:33 -07003067 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3068 params.plink_action =
3069 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3070
Johannes Bergbdd90d52011-12-14 12:20:27 +01003071 if (!rdev->ops->add_station)
3072 return -EOPNOTSUPP;
3073
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003074 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003075 return -EINVAL;
3076
Johannes Bergbdd90d52011-12-14 12:20:27 +01003077 switch (dev->ieee80211_ptr->iftype) {
3078 case NL80211_IFTYPE_AP:
3079 case NL80211_IFTYPE_AP_VLAN:
3080 case NL80211_IFTYPE_P2P_GO:
3081 /* parse WME attributes if sta is WME capable */
3082 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3083 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3084 info->attrs[NL80211_ATTR_STA_WME]) {
3085 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3086 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003087
Johannes Bergbdd90d52011-12-14 12:20:27 +01003088 nla = info->attrs[NL80211_ATTR_STA_WME];
3089 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3090 nl80211_sta_wme_policy);
3091 if (err)
3092 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003093
Johannes Bergbdd90d52011-12-14 12:20:27 +01003094 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3095 params.uapsd_queues =
3096 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3097 if (params.uapsd_queues &
3098 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3099 return -EINVAL;
3100
3101 if (tb[NL80211_STA_WME_MAX_SP])
3102 params.max_sp =
3103 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3104
3105 if (params.max_sp &
3106 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3107 return -EINVAL;
3108
3109 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3110 }
3111 /* TDLS peers cannot be added */
3112 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003113 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003114 /* but don't bother the driver with it */
3115 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003116
Johannes Bergbdd90d52011-12-14 12:20:27 +01003117 /* must be last in here for error handling */
3118 params.vlan = get_vlan(info, rdev);
3119 if (IS_ERR(params.vlan))
3120 return PTR_ERR(params.vlan);
3121 break;
3122 case NL80211_IFTYPE_MESH_POINT:
3123 /* TDLS peers cannot be added */
3124 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003125 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003126 break;
3127 case NL80211_IFTYPE_STATION:
3128 /* Only TDLS peers can be added */
3129 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3130 return -EINVAL;
3131 /* Can only add if TDLS ... */
3132 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3133 return -EOPNOTSUPP;
3134 /* ... with external setup is supported */
3135 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3136 return -EOPNOTSUPP;
3137 break;
3138 default:
3139 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003140 }
3141
Johannes Bergbdd90d52011-12-14 12:20:27 +01003142 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003143
Johannes Berg79c97e92009-07-07 03:56:12 +02003144 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003145
Johannes Berg5727ef12007-12-19 02:03:34 +01003146 if (params.vlan)
3147 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003148 return err;
3149}
3150
3151static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3152{
Johannes Berg4c476992010-10-04 21:36:35 +02003153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3154 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003155 u8 *mac_addr = NULL;
3156
3157 if (info->attrs[NL80211_ATTR_MAC])
3158 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3159
Johannes Berge80cf852009-05-11 14:43:13 +02003160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003161 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003162 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003163 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3164 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003165
Johannes Berg4c476992010-10-04 21:36:35 +02003166 if (!rdev->ops->del_station)
3167 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003168
Johannes Berg4c476992010-10-04 21:36:35 +02003169 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003170}
3171
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003172static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3173 int flags, struct net_device *dev,
3174 u8 *dst, u8 *next_hop,
3175 struct mpath_info *pinfo)
3176{
3177 void *hdr;
3178 struct nlattr *pinfoattr;
3179
3180 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3181 if (!hdr)
3182 return -1;
3183
David S. Miller9360ffd2012-03-29 04:41:26 -04003184 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3185 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3186 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3187 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3188 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003189
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003190 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3191 if (!pinfoattr)
3192 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003193 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3194 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3195 pinfo->frame_qlen))
3196 goto nla_put_failure;
3197 if (((pinfo->filled & MPATH_INFO_SN) &&
3198 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3199 ((pinfo->filled & MPATH_INFO_METRIC) &&
3200 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3201 pinfo->metric)) ||
3202 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3203 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3204 pinfo->exptime)) ||
3205 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3206 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3207 pinfo->flags)) ||
3208 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3209 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3210 pinfo->discovery_timeout)) ||
3211 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3212 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3213 pinfo->discovery_retries)))
3214 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003215
3216 nla_nest_end(msg, pinfoattr);
3217
3218 return genlmsg_end(msg, hdr);
3219
3220 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003221 genlmsg_cancel(msg, hdr);
3222 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003223}
3224
3225static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003226 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003227{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003228 struct mpath_info pinfo;
3229 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003230 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003231 u8 dst[ETH_ALEN];
3232 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003233 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003234 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003235
Johannes Berg67748892010-10-04 21:14:06 +02003236 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3237 if (err)
3238 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003239
3240 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003241 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003242 goto out_err;
3243 }
3244
Jouni Malineneec60b02009-03-20 21:21:19 +02003245 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3246 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003247 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003248 }
3249
Johannes Bergbba95fe2008-07-29 13:22:51 +02003250 while (1) {
3251 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3252 dst, next_hop, &pinfo);
3253 if (err == -ENOENT)
3254 break;
3255 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003256 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003257
3258 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3259 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3260 netdev, dst, next_hop,
3261 &pinfo) < 0)
3262 goto out;
3263
3264 path_idx++;
3265 }
3266
3267
3268 out:
3269 cb->args[1] = path_idx;
3270 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003271 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003272 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003273 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003274}
3275
3276static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3277{
Johannes Berg4c476992010-10-04 21:36:35 +02003278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003279 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003280 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003281 struct mpath_info pinfo;
3282 struct sk_buff *msg;
3283 u8 *dst = NULL;
3284 u8 next_hop[ETH_ALEN];
3285
3286 memset(&pinfo, 0, sizeof(pinfo));
3287
3288 if (!info->attrs[NL80211_ATTR_MAC])
3289 return -EINVAL;
3290
3291 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3292
Johannes Berg4c476992010-10-04 21:36:35 +02003293 if (!rdev->ops->get_mpath)
3294 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003295
Johannes Berg4c476992010-10-04 21:36:35 +02003296 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3297 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003298
Johannes Berg79c97e92009-07-07 03:56:12 +02003299 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003300 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003301 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003302
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003304 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003305 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003306
3307 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003308 dev, dst, next_hop, &pinfo) < 0) {
3309 nlmsg_free(msg);
3310 return -ENOBUFS;
3311 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003312
Johannes Berg4c476992010-10-04 21:36:35 +02003313 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003314}
3315
3316static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3317{
Johannes Berg4c476992010-10-04 21:36:35 +02003318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3319 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003320 u8 *dst = NULL;
3321 u8 *next_hop = NULL;
3322
3323 if (!info->attrs[NL80211_ATTR_MAC])
3324 return -EINVAL;
3325
3326 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3327 return -EINVAL;
3328
3329 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3330 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3331
Johannes Berg4c476992010-10-04 21:36:35 +02003332 if (!rdev->ops->change_mpath)
3333 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003334
Johannes Berg4c476992010-10-04 21:36:35 +02003335 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3336 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003337
Johannes Berg4c476992010-10-04 21:36:35 +02003338 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003339}
Johannes Berg4c476992010-10-04 21:36:35 +02003340
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003341static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3342{
Johannes Berg4c476992010-10-04 21:36:35 +02003343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3344 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003345 u8 *dst = NULL;
3346 u8 *next_hop = NULL;
3347
3348 if (!info->attrs[NL80211_ATTR_MAC])
3349 return -EINVAL;
3350
3351 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3352 return -EINVAL;
3353
3354 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3355 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3356
Johannes Berg4c476992010-10-04 21:36:35 +02003357 if (!rdev->ops->add_mpath)
3358 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003359
Johannes Berg4c476992010-10-04 21:36:35 +02003360 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3361 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003362
Johannes Berg4c476992010-10-04 21:36:35 +02003363 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003364}
3365
3366static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3367{
Johannes Berg4c476992010-10-04 21:36:35 +02003368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3369 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003370 u8 *dst = NULL;
3371
3372 if (info->attrs[NL80211_ATTR_MAC])
3373 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3374
Johannes Berg4c476992010-10-04 21:36:35 +02003375 if (!rdev->ops->del_mpath)
3376 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003377
Johannes Berg4c476992010-10-04 21:36:35 +02003378 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003379}
3380
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003381static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3382{
Johannes Berg4c476992010-10-04 21:36:35 +02003383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3384 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003385 struct bss_parameters params;
3386
3387 memset(&params, 0, sizeof(params));
3388 /* default to not changing parameters */
3389 params.use_cts_prot = -1;
3390 params.use_short_preamble = -1;
3391 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003392 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003393 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003394
3395 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3396 params.use_cts_prot =
3397 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3398 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3399 params.use_short_preamble =
3400 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3401 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3402 params.use_short_slot_time =
3403 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003404 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3405 params.basic_rates =
3406 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3407 params.basic_rates_len =
3408 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3409 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003410 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3411 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003412 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3413 params.ht_opmode =
3414 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003415
Johannes Berg4c476992010-10-04 21:36:35 +02003416 if (!rdev->ops->change_bss)
3417 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003418
Johannes Berg074ac8d2010-09-16 14:58:22 +02003419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003420 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3421 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003422
Johannes Berg4c476992010-10-04 21:36:35 +02003423 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003424}
3425
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003426static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003427 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3428 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3429 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3430 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3431 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3432 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3433};
3434
3435static int parse_reg_rule(struct nlattr *tb[],
3436 struct ieee80211_reg_rule *reg_rule)
3437{
3438 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3439 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3440
3441 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3442 return -EINVAL;
3443 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3444 return -EINVAL;
3445 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3446 return -EINVAL;
3447 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3448 return -EINVAL;
3449 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3450 return -EINVAL;
3451
3452 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3453
3454 freq_range->start_freq_khz =
3455 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3456 freq_range->end_freq_khz =
3457 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3458 freq_range->max_bandwidth_khz =
3459 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3460
3461 power_rule->max_eirp =
3462 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3463
3464 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3465 power_rule->max_antenna_gain =
3466 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3467
3468 return 0;
3469}
3470
3471static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3472{
3473 int r;
3474 char *data = NULL;
3475
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003476 /*
3477 * You should only get this when cfg80211 hasn't yet initialized
3478 * completely when built-in to the kernel right between the time
3479 * window between nl80211_init() and regulatory_init(), if that is
3480 * even possible.
3481 */
3482 mutex_lock(&cfg80211_mutex);
3483 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003484 mutex_unlock(&cfg80211_mutex);
3485 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003486 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003487 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003488
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003489 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3490 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003491
3492 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3493
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003494 r = regulatory_hint_user(data);
3495
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003496 return r;
3497}
3498
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003499static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003500 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003501{
Johannes Berg4c476992010-10-04 21:36:35 +02003502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003503 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003504 struct wireless_dev *wdev = dev->ieee80211_ptr;
3505 struct mesh_config cur_params;
3506 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003507 void *hdr;
3508 struct nlattr *pinfoattr;
3509 struct sk_buff *msg;
3510
Johannes Berg29cbe682010-12-03 09:20:44 +01003511 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3512 return -EOPNOTSUPP;
3513
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003514 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003515 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003516
Johannes Berg29cbe682010-12-03 09:20:44 +01003517 wdev_lock(wdev);
3518 /* If not connected, get default parameters */
3519 if (!wdev->mesh_id_len)
3520 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3521 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003522 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003523 &cur_params);
3524 wdev_unlock(wdev);
3525
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003526 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003527 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003528
3529 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003530 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003531 if (!msg)
3532 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003533 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003534 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003535 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003536 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003537 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003538 if (!pinfoattr)
3539 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003540 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3541 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3542 cur_params.dot11MeshRetryTimeout) ||
3543 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3544 cur_params.dot11MeshConfirmTimeout) ||
3545 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3546 cur_params.dot11MeshHoldingTimeout) ||
3547 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3548 cur_params.dot11MeshMaxPeerLinks) ||
3549 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3550 cur_params.dot11MeshMaxRetries) ||
3551 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3552 cur_params.dot11MeshTTL) ||
3553 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3554 cur_params.element_ttl) ||
3555 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3556 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003557 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3558 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003559 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3560 cur_params.dot11MeshHWMPmaxPREQretries) ||
3561 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3562 cur_params.path_refresh_time) ||
3563 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3564 cur_params.min_discovery_timeout) ||
3565 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3566 cur_params.dot11MeshHWMPactivePathTimeout) ||
3567 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3568 cur_params.dot11MeshHWMPpreqMinInterval) ||
3569 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3570 cur_params.dot11MeshHWMPperrMinInterval) ||
3571 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3572 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3573 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3574 cur_params.dot11MeshHWMPRootMode) ||
3575 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3576 cur_params.dot11MeshHWMPRannInterval) ||
3577 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3578 cur_params.dot11MeshGateAnnouncementProtocol) ||
3579 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3580 cur_params.dot11MeshForwarding) ||
3581 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003582 cur_params.rssi_threshold) ||
3583 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003584 cur_params.ht_opmode) ||
3585 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3586 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3587 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003588 cur_params.dot11MeshHWMProotInterval) ||
3589 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3590 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003591 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003592 nla_nest_end(msg, pinfoattr);
3593 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003594 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003595
Johannes Berg3b858752009-03-12 09:55:09 +01003596 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003597 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003598 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003599 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003600 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003601}
3602
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003603static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003604 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3605 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3606 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3607 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3608 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3609 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003610 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003611 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003612 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003613 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3614 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3615 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3616 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3617 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003618 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003619 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003620 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003621 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003622 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003623 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003624 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3625 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003626 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3627 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003628 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003629};
3630
Javier Cardonac80d5452010-12-16 17:37:49 -08003631static const struct nla_policy
3632 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003633 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003634 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3635 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003636 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003637 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003638 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003639 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003640};
3641
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003642static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003643 struct mesh_config *cfg,
3644 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003645{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003646 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003647 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003648
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003649#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3650do {\
3651 if (table[attr_num]) {\
3652 cfg->param = nla_fn(table[attr_num]); \
3653 mask |= (1 << (attr_num - 1)); \
3654 } \
3655} while (0);\
3656
3657
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003658 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003659 return -EINVAL;
3660 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003661 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003662 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003663 return -EINVAL;
3664
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003665 /* This makes sure that there aren't more than 32 mesh config
3666 * parameters (otherwise our bitfield scheme would not work.) */
3667 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3668
3669 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003671 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3672 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003674 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3675 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003677 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3678 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003680 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3681 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003683 mask, NL80211_MESHCONF_MAX_RETRIES,
3684 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003686 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003688 mask, NL80211_MESHCONF_ELEMENT_TTL,
3689 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003691 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3692 nla_get_u8);
3693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3694 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3695 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003697 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3698 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003700 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3701 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003702 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003703 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3704 nla_get_u16);
3705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3706 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3707 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003709 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3710 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003712 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3713 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003715 dot11MeshHWMPnetDiameterTraversalTime, mask,
3716 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3717 nla_get_u16);
3718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3719 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3721 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3722 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003724 dot11MeshGateAnnouncementProtocol, mask,
3725 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3726 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003728 mask, NL80211_MESHCONF_FORWARDING,
3729 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003731 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3732 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003734 mask, NL80211_MESHCONF_HT_OPMODE,
3735 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3737 mask,
3738 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3739 nla_get_u32);
3740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3741 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3742 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3744 dot11MeshHWMPconfirmationInterval, mask,
3745 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3746 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003747 if (mask_out)
3748 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003749
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003750 return 0;
3751
3752#undef FILL_IN_MESH_PARAM_IF_SET
3753}
3754
Javier Cardonac80d5452010-12-16 17:37:49 -08003755static int nl80211_parse_mesh_setup(struct genl_info *info,
3756 struct mesh_setup *setup)
3757{
3758 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3759
3760 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3761 return -EINVAL;
3762 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3763 info->attrs[NL80211_ATTR_MESH_SETUP],
3764 nl80211_mesh_setup_params_policy))
3765 return -EINVAL;
3766
Javier Cardonad299a1f2012-03-31 11:31:33 -07003767 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3768 setup->sync_method =
3769 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3770 IEEE80211_SYNC_METHOD_VENDOR :
3771 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3772
Javier Cardonac80d5452010-12-16 17:37:49 -08003773 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3774 setup->path_sel_proto =
3775 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3776 IEEE80211_PATH_PROTOCOL_VENDOR :
3777 IEEE80211_PATH_PROTOCOL_HWMP;
3778
3779 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3780 setup->path_metric =
3781 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3782 IEEE80211_PATH_METRIC_VENDOR :
3783 IEEE80211_PATH_METRIC_AIRTIME;
3784
Javier Cardona581a8b02011-04-07 15:08:27 -07003785
3786 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003787 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003788 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003789 if (!is_valid_ie_attr(ieattr))
3790 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003791 setup->ie = nla_data(ieattr);
3792 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003793 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003794 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3795 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003796
3797 return 0;
3798}
3799
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003800static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003801 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003802{
3803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3804 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003805 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003806 struct mesh_config cfg;
3807 u32 mask;
3808 int err;
3809
Johannes Berg29cbe682010-12-03 09:20:44 +01003810 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3811 return -EOPNOTSUPP;
3812
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003813 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003814 return -EOPNOTSUPP;
3815
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003816 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003817 if (err)
3818 return err;
3819
Johannes Berg29cbe682010-12-03 09:20:44 +01003820 wdev_lock(wdev);
3821 if (!wdev->mesh_id_len)
3822 err = -ENOLINK;
3823
3824 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003825 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003826 mask, &cfg);
3827
3828 wdev_unlock(wdev);
3829
3830 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003831}
3832
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003833static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3834{
3835 struct sk_buff *msg;
3836 void *hdr = NULL;
3837 struct nlattr *nl_reg_rules;
3838 unsigned int i;
3839 int err = -EINVAL;
3840
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003841 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003842
3843 if (!cfg80211_regdomain)
3844 goto out;
3845
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003847 if (!msg) {
3848 err = -ENOBUFS;
3849 goto out;
3850 }
3851
3852 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3853 NL80211_CMD_GET_REG);
3854 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003855 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003856
David S. Miller9360ffd2012-03-29 04:41:26 -04003857 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3858 cfg80211_regdomain->alpha2) ||
3859 (cfg80211_regdomain->dfs_region &&
3860 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3861 cfg80211_regdomain->dfs_region)))
3862 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003863
3864 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3865 if (!nl_reg_rules)
3866 goto nla_put_failure;
3867
3868 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3869 struct nlattr *nl_reg_rule;
3870 const struct ieee80211_reg_rule *reg_rule;
3871 const struct ieee80211_freq_range *freq_range;
3872 const struct ieee80211_power_rule *power_rule;
3873
3874 reg_rule = &cfg80211_regdomain->reg_rules[i];
3875 freq_range = &reg_rule->freq_range;
3876 power_rule = &reg_rule->power_rule;
3877
3878 nl_reg_rule = nla_nest_start(msg, i);
3879 if (!nl_reg_rule)
3880 goto nla_put_failure;
3881
David S. Miller9360ffd2012-03-29 04:41:26 -04003882 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3883 reg_rule->flags) ||
3884 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3885 freq_range->start_freq_khz) ||
3886 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3887 freq_range->end_freq_khz) ||
3888 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3889 freq_range->max_bandwidth_khz) ||
3890 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3891 power_rule->max_antenna_gain) ||
3892 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3893 power_rule->max_eirp))
3894 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003895
3896 nla_nest_end(msg, nl_reg_rule);
3897 }
3898
3899 nla_nest_end(msg, nl_reg_rules);
3900
3901 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003902 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003903 goto out;
3904
3905nla_put_failure:
3906 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003907put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003908 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003909 err = -EMSGSIZE;
3910out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003911 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003912 return err;
3913}
3914
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003915static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3916{
3917 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3918 struct nlattr *nl_reg_rule;
3919 char *alpha2 = NULL;
3920 int rem_reg_rules = 0, r = 0;
3921 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003922 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003923 struct ieee80211_regdomain *rd = NULL;
3924
3925 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3926 return -EINVAL;
3927
3928 if (!info->attrs[NL80211_ATTR_REG_RULES])
3929 return -EINVAL;
3930
3931 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3932
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003933 if (info->attrs[NL80211_ATTR_DFS_REGION])
3934 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3935
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003936 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3937 rem_reg_rules) {
3938 num_rules++;
3939 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003940 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003941 }
3942
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003943 mutex_lock(&cfg80211_mutex);
3944
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003945 if (!reg_is_valid_request(alpha2)) {
3946 r = -EINVAL;
3947 goto bad_reg;
3948 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003949
3950 size_of_regd = sizeof(struct ieee80211_regdomain) +
3951 (num_rules * sizeof(struct ieee80211_reg_rule));
3952
3953 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003954 if (!rd) {
3955 r = -ENOMEM;
3956 goto bad_reg;
3957 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003958
3959 rd->n_reg_rules = num_rules;
3960 rd->alpha2[0] = alpha2[0];
3961 rd->alpha2[1] = alpha2[1];
3962
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003963 /*
3964 * Disable DFS master mode if the DFS region was
3965 * not supported or known on this kernel.
3966 */
3967 if (reg_supported_dfs_region(dfs_region))
3968 rd->dfs_region = dfs_region;
3969
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003970 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3971 rem_reg_rules) {
3972 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3973 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3974 reg_rule_policy);
3975 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3976 if (r)
3977 goto bad_reg;
3978
3979 rule_idx++;
3980
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003981 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3982 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003983 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003984 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003985 }
3986
3987 BUG_ON(rule_idx != num_rules);
3988
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003989 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003990
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003991 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003992
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003993 return r;
3994
Johannes Bergd2372b32008-10-24 20:32:20 +02003995 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003996 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003997 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003998 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003999}
4000
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004001static int validate_scan_freqs(struct nlattr *freqs)
4002{
4003 struct nlattr *attr1, *attr2;
4004 int n_channels = 0, tmp1, tmp2;
4005
4006 nla_for_each_nested(attr1, freqs, tmp1) {
4007 n_channels++;
4008 /*
4009 * Some hardware has a limited channel list for
4010 * scanning, and it is pretty much nonsensical
4011 * to scan for a channel twice, so disallow that
4012 * and don't require drivers to check that the
4013 * channel list they get isn't longer than what
4014 * they can scan, as long as they can scan all
4015 * the channels they registered at once.
4016 */
4017 nla_for_each_nested(attr2, freqs, tmp2)
4018 if (attr1 != attr2 &&
4019 nla_get_u32(attr1) == nla_get_u32(attr2))
4020 return 0;
4021 }
4022
4023 return n_channels;
4024}
4025
Johannes Berg2a519312009-02-10 21:25:55 +01004026static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4027{
Johannes Berg4c476992010-10-04 21:36:35 +02004028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4029 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004030 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004031 struct nlattr *attr;
4032 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004033 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004034 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004035
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004036 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4037 return -EINVAL;
4038
Johannes Berg79c97e92009-07-07 03:56:12 +02004039 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004040
Johannes Berg4c476992010-10-04 21:36:35 +02004041 if (!rdev->ops->scan)
4042 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004043
Johannes Berg4c476992010-10-04 21:36:35 +02004044 if (rdev->scan_req)
4045 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004046
4047 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004048 n_channels = validate_scan_freqs(
4049 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004050 if (!n_channels)
4051 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004052 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004053 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004054 n_channels = 0;
4055
Johannes Berg2a519312009-02-10 21:25:55 +01004056 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4057 if (wiphy->bands[band])
4058 n_channels += wiphy->bands[band]->n_channels;
4059 }
4060
4061 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4062 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4063 n_ssids++;
4064
Johannes Berg4c476992010-10-04 21:36:35 +02004065 if (n_ssids > wiphy->max_scan_ssids)
4066 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004067
Jouni Malinen70692ad2009-02-16 19:39:13 +02004068 if (info->attrs[NL80211_ATTR_IE])
4069 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4070 else
4071 ie_len = 0;
4072
Johannes Berg4c476992010-10-04 21:36:35 +02004073 if (ie_len > wiphy->max_scan_ie_len)
4074 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004075
Johannes Berg2a519312009-02-10 21:25:55 +01004076 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004077 + sizeof(*request->ssids) * n_ssids
4078 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004079 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004080 if (!request)
4081 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004082
Johannes Berg2a519312009-02-10 21:25:55 +01004083 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004084 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004085 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004086 if (ie_len) {
4087 if (request->ssids)
4088 request->ie = (void *)(request->ssids + n_ssids);
4089 else
4090 request->ie = (void *)(request->channels + n_channels);
4091 }
Johannes Berg2a519312009-02-10 21:25:55 +01004092
Johannes Berg584991d2009-11-02 13:32:03 +01004093 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004094 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4095 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004096 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004097 struct ieee80211_channel *chan;
4098
4099 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4100
4101 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004102 err = -EINVAL;
4103 goto out_free;
4104 }
Johannes Berg584991d2009-11-02 13:32:03 +01004105
4106 /* ignore disabled channels */
4107 if (chan->flags & IEEE80211_CHAN_DISABLED)
4108 continue;
4109
4110 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004111 i++;
4112 }
4113 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004114 enum ieee80211_band band;
4115
Johannes Berg2a519312009-02-10 21:25:55 +01004116 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004117 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4118 int j;
4119 if (!wiphy->bands[band])
4120 continue;
4121 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004122 struct ieee80211_channel *chan;
4123
4124 chan = &wiphy->bands[band]->channels[j];
4125
4126 if (chan->flags & IEEE80211_CHAN_DISABLED)
4127 continue;
4128
4129 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004130 i++;
4131 }
4132 }
4133 }
4134
Johannes Berg584991d2009-11-02 13:32:03 +01004135 if (!i) {
4136 err = -EINVAL;
4137 goto out_free;
4138 }
4139
4140 request->n_channels = i;
4141
Johannes Berg2a519312009-02-10 21:25:55 +01004142 i = 0;
4143 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4144 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004145 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004146 err = -EINVAL;
4147 goto out_free;
4148 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004149 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004150 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004151 i++;
4152 }
4153 }
4154
Jouni Malinen70692ad2009-02-16 19:39:13 +02004155 if (info->attrs[NL80211_ATTR_IE]) {
4156 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004157 memcpy((void *)request->ie,
4158 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004159 request->ie_len);
4160 }
4161
Johannes Berg34850ab2011-07-18 18:08:35 +02004162 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004163 if (wiphy->bands[i])
4164 request->rates[i] =
4165 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004166
4167 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4168 nla_for_each_nested(attr,
4169 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4170 tmp) {
4171 enum ieee80211_band band = nla_type(attr);
4172
Dan Carpenter84404622011-07-29 11:52:18 +03004173 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004174 err = -EINVAL;
4175 goto out_free;
4176 }
4177 err = ieee80211_get_ratemask(wiphy->bands[band],
4178 nla_data(attr),
4179 nla_len(attr),
4180 &request->rates[band]);
4181 if (err)
4182 goto out_free;
4183 }
4184 }
4185
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304186 request->no_cck =
4187 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4188
Johannes Berg463d0182009-07-14 00:33:35 +02004189 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004190 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004191
Johannes Berg79c97e92009-07-07 03:56:12 +02004192 rdev->scan_req = request;
4193 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004194
Johannes Berg463d0182009-07-14 00:33:35 +02004195 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004196 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004197 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004198 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004199 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004200 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004201 kfree(request);
4202 }
Johannes Berg3b858752009-03-12 09:55:09 +01004203
Johannes Berg2a519312009-02-10 21:25:55 +01004204 return err;
4205}
4206
Luciano Coelho807f8a82011-05-11 17:09:35 +03004207static int nl80211_start_sched_scan(struct sk_buff *skb,
4208 struct genl_info *info)
4209{
4210 struct cfg80211_sched_scan_request *request;
4211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4212 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004213 struct nlattr *attr;
4214 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004215 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004216 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004217 enum ieee80211_band band;
4218 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004219 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004220
4221 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4222 !rdev->ops->sched_scan_start)
4223 return -EOPNOTSUPP;
4224
4225 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4226 return -EINVAL;
4227
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004228 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4229 return -EINVAL;
4230
4231 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4232 if (interval == 0)
4233 return -EINVAL;
4234
Luciano Coelho807f8a82011-05-11 17:09:35 +03004235 wiphy = &rdev->wiphy;
4236
4237 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4238 n_channels = validate_scan_freqs(
4239 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4240 if (!n_channels)
4241 return -EINVAL;
4242 } else {
4243 n_channels = 0;
4244
4245 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4246 if (wiphy->bands[band])
4247 n_channels += wiphy->bands[band]->n_channels;
4248 }
4249
4250 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4251 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4252 tmp)
4253 n_ssids++;
4254
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004255 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004256 return -EINVAL;
4257
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004258 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4259 nla_for_each_nested(attr,
4260 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4261 tmp)
4262 n_match_sets++;
4263
4264 if (n_match_sets > wiphy->max_match_sets)
4265 return -EINVAL;
4266
Luciano Coelho807f8a82011-05-11 17:09:35 +03004267 if (info->attrs[NL80211_ATTR_IE])
4268 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4269 else
4270 ie_len = 0;
4271
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004272 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004273 return -EINVAL;
4274
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004275 mutex_lock(&rdev->sched_scan_mtx);
4276
4277 if (rdev->sched_scan_req) {
4278 err = -EINPROGRESS;
4279 goto out;
4280 }
4281
Luciano Coelho807f8a82011-05-11 17:09:35 +03004282 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004283 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004284 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004285 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004286 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004287 if (!request) {
4288 err = -ENOMEM;
4289 goto out;
4290 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004291
4292 if (n_ssids)
4293 request->ssids = (void *)&request->channels[n_channels];
4294 request->n_ssids = n_ssids;
4295 if (ie_len) {
4296 if (request->ssids)
4297 request->ie = (void *)(request->ssids + n_ssids);
4298 else
4299 request->ie = (void *)(request->channels + n_channels);
4300 }
4301
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004302 if (n_match_sets) {
4303 if (request->ie)
4304 request->match_sets = (void *)(request->ie + ie_len);
4305 else if (request->ssids)
4306 request->match_sets =
4307 (void *)(request->ssids + n_ssids);
4308 else
4309 request->match_sets =
4310 (void *)(request->channels + n_channels);
4311 }
4312 request->n_match_sets = n_match_sets;
4313
Luciano Coelho807f8a82011-05-11 17:09:35 +03004314 i = 0;
4315 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4316 /* user specified, bail out if channel not found */
4317 nla_for_each_nested(attr,
4318 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4319 tmp) {
4320 struct ieee80211_channel *chan;
4321
4322 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4323
4324 if (!chan) {
4325 err = -EINVAL;
4326 goto out_free;
4327 }
4328
4329 /* ignore disabled channels */
4330 if (chan->flags & IEEE80211_CHAN_DISABLED)
4331 continue;
4332
4333 request->channels[i] = chan;
4334 i++;
4335 }
4336 } else {
4337 /* all channels */
4338 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4339 int j;
4340 if (!wiphy->bands[band])
4341 continue;
4342 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4343 struct ieee80211_channel *chan;
4344
4345 chan = &wiphy->bands[band]->channels[j];
4346
4347 if (chan->flags & IEEE80211_CHAN_DISABLED)
4348 continue;
4349
4350 request->channels[i] = chan;
4351 i++;
4352 }
4353 }
4354 }
4355
4356 if (!i) {
4357 err = -EINVAL;
4358 goto out_free;
4359 }
4360
4361 request->n_channels = i;
4362
4363 i = 0;
4364 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4365 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4366 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004367 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004368 err = -EINVAL;
4369 goto out_free;
4370 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004371 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004372 memcpy(request->ssids[i].ssid, nla_data(attr),
4373 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004374 i++;
4375 }
4376 }
4377
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004378 i = 0;
4379 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4380 nla_for_each_nested(attr,
4381 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4382 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004383 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004384
4385 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4386 nla_data(attr), nla_len(attr),
4387 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004388 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004389 if (ssid) {
4390 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4391 err = -EINVAL;
4392 goto out_free;
4393 }
4394 memcpy(request->match_sets[i].ssid.ssid,
4395 nla_data(ssid), nla_len(ssid));
4396 request->match_sets[i].ssid.ssid_len =
4397 nla_len(ssid);
4398 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004399 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4400 if (rssi)
4401 request->rssi_thold = nla_get_u32(rssi);
4402 else
4403 request->rssi_thold =
4404 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004405 i++;
4406 }
4407 }
4408
Luciano Coelho807f8a82011-05-11 17:09:35 +03004409 if (info->attrs[NL80211_ATTR_IE]) {
4410 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4411 memcpy((void *)request->ie,
4412 nla_data(info->attrs[NL80211_ATTR_IE]),
4413 request->ie_len);
4414 }
4415
4416 request->dev = dev;
4417 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004418 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004419
4420 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4421 if (!err) {
4422 rdev->sched_scan_req = request;
4423 nl80211_send_sched_scan(rdev, dev,
4424 NL80211_CMD_START_SCHED_SCAN);
4425 goto out;
4426 }
4427
4428out_free:
4429 kfree(request);
4430out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004431 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004432 return err;
4433}
4434
4435static int nl80211_stop_sched_scan(struct sk_buff *skb,
4436 struct genl_info *info)
4437{
4438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004439 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004440
4441 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4442 !rdev->ops->sched_scan_stop)
4443 return -EOPNOTSUPP;
4444
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004445 mutex_lock(&rdev->sched_scan_mtx);
4446 err = __cfg80211_stop_sched_scan(rdev, false);
4447 mutex_unlock(&rdev->sched_scan_mtx);
4448
4449 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004450}
4451
Johannes Berg9720bb32011-06-21 09:45:33 +02004452static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4453 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004454 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004455 struct wireless_dev *wdev,
4456 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004457{
Johannes Berg48ab9052009-07-10 18:42:31 +02004458 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004459 void *hdr;
4460 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004461
4462 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004463
Johannes Berg9720bb32011-06-21 09:45:33 +02004464 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004465 NL80211_CMD_NEW_SCAN_RESULTS);
4466 if (!hdr)
4467 return -1;
4468
Johannes Berg9720bb32011-06-21 09:45:33 +02004469 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4470
David S. Miller9360ffd2012-03-29 04:41:26 -04004471 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4472 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4473 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004474
4475 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4476 if (!bss)
4477 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004478 if ((!is_zero_ether_addr(res->bssid) &&
4479 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4480 (res->information_elements && res->len_information_elements &&
4481 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4482 res->len_information_elements,
4483 res->information_elements)) ||
4484 (res->beacon_ies && res->len_beacon_ies &&
4485 res->beacon_ies != res->information_elements &&
4486 nla_put(msg, NL80211_BSS_BEACON_IES,
4487 res->len_beacon_ies, res->beacon_ies)))
4488 goto nla_put_failure;
4489 if (res->tsf &&
4490 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4491 goto nla_put_failure;
4492 if (res->beacon_interval &&
4493 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4494 goto nla_put_failure;
4495 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4496 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4497 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4498 jiffies_to_msecs(jiffies - intbss->ts)))
4499 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004500
Johannes Berg77965c92009-02-18 18:45:06 +01004501 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004502 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004503 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4504 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004505 break;
4506 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004507 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4508 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004509 break;
4510 default:
4511 break;
4512 }
4513
Johannes Berg48ab9052009-07-10 18:42:31 +02004514 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004515 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004516 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004517 if (intbss == wdev->current_bss &&
4518 nla_put_u32(msg, NL80211_BSS_STATUS,
4519 NL80211_BSS_STATUS_ASSOCIATED))
4520 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004521 break;
4522 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004523 if (intbss == wdev->current_bss &&
4524 nla_put_u32(msg, NL80211_BSS_STATUS,
4525 NL80211_BSS_STATUS_IBSS_JOINED))
4526 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004527 break;
4528 default:
4529 break;
4530 }
4531
Johannes Berg2a519312009-02-10 21:25:55 +01004532 nla_nest_end(msg, bss);
4533
4534 return genlmsg_end(msg, hdr);
4535
4536 nla_put_failure:
4537 genlmsg_cancel(msg, hdr);
4538 return -EMSGSIZE;
4539}
4540
4541static int nl80211_dump_scan(struct sk_buff *skb,
4542 struct netlink_callback *cb)
4543{
Johannes Berg48ab9052009-07-10 18:42:31 +02004544 struct cfg80211_registered_device *rdev;
4545 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004546 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004547 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004548 int start = cb->args[1], idx = 0;
4549 int err;
4550
Johannes Berg67748892010-10-04 21:14:06 +02004551 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4552 if (err)
4553 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004554
Johannes Berg48ab9052009-07-10 18:42:31 +02004555 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004556
Johannes Berg48ab9052009-07-10 18:42:31 +02004557 wdev_lock(wdev);
4558 spin_lock_bh(&rdev->bss_lock);
4559 cfg80211_bss_expire(rdev);
4560
Johannes Berg9720bb32011-06-21 09:45:33 +02004561 cb->seq = rdev->bss_generation;
4562
Johannes Berg48ab9052009-07-10 18:42:31 +02004563 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004564 if (++idx <= start)
4565 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004566 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004567 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004568 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004569 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004570 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004571 }
4572 }
4573
Johannes Berg48ab9052009-07-10 18:42:31 +02004574 spin_unlock_bh(&rdev->bss_lock);
4575 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004576
4577 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004578 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004579
Johannes Berg67748892010-10-04 21:14:06 +02004580 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004581}
4582
Holger Schurig61fa7132009-11-11 12:25:40 +01004583static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4584 int flags, struct net_device *dev,
4585 struct survey_info *survey)
4586{
4587 void *hdr;
4588 struct nlattr *infoattr;
4589
Holger Schurig61fa7132009-11-11 12:25:40 +01004590 hdr = nl80211hdr_put(msg, pid, seq, flags,
4591 NL80211_CMD_NEW_SURVEY_RESULTS);
4592 if (!hdr)
4593 return -ENOMEM;
4594
David S. Miller9360ffd2012-03-29 04:41:26 -04004595 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4596 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004597
4598 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4599 if (!infoattr)
4600 goto nla_put_failure;
4601
David S. Miller9360ffd2012-03-29 04:41:26 -04004602 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4603 survey->channel->center_freq))
4604 goto nla_put_failure;
4605
4606 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4607 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4608 goto nla_put_failure;
4609 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4610 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4611 goto nla_put_failure;
4612 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4613 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4614 survey->channel_time))
4615 goto nla_put_failure;
4616 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4617 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4618 survey->channel_time_busy))
4619 goto nla_put_failure;
4620 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4621 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4622 survey->channel_time_ext_busy))
4623 goto nla_put_failure;
4624 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4625 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4626 survey->channel_time_rx))
4627 goto nla_put_failure;
4628 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4629 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4630 survey->channel_time_tx))
4631 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004632
4633 nla_nest_end(msg, infoattr);
4634
4635 return genlmsg_end(msg, hdr);
4636
4637 nla_put_failure:
4638 genlmsg_cancel(msg, hdr);
4639 return -EMSGSIZE;
4640}
4641
4642static int nl80211_dump_survey(struct sk_buff *skb,
4643 struct netlink_callback *cb)
4644{
4645 struct survey_info survey;
4646 struct cfg80211_registered_device *dev;
4647 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004648 int survey_idx = cb->args[1];
4649 int res;
4650
Johannes Berg67748892010-10-04 21:14:06 +02004651 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4652 if (res)
4653 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004654
4655 if (!dev->ops->dump_survey) {
4656 res = -EOPNOTSUPP;
4657 goto out_err;
4658 }
4659
4660 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004661 struct ieee80211_channel *chan;
4662
Holger Schurig61fa7132009-11-11 12:25:40 +01004663 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4664 &survey);
4665 if (res == -ENOENT)
4666 break;
4667 if (res)
4668 goto out_err;
4669
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004670 /* Survey without a channel doesn't make sense */
4671 if (!survey.channel) {
4672 res = -EINVAL;
4673 goto out;
4674 }
4675
4676 chan = ieee80211_get_channel(&dev->wiphy,
4677 survey.channel->center_freq);
4678 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4679 survey_idx++;
4680 continue;
4681 }
4682
Holger Schurig61fa7132009-11-11 12:25:40 +01004683 if (nl80211_send_survey(skb,
4684 NETLINK_CB(cb->skb).pid,
4685 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4686 netdev,
4687 &survey) < 0)
4688 goto out;
4689 survey_idx++;
4690 }
4691
4692 out:
4693 cb->args[1] = survey_idx;
4694 res = skb->len;
4695 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004696 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004697 return res;
4698}
4699
Jouni Malinen255e7372009-03-20 21:21:17 +02004700static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4701{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004702 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004703}
4704
Samuel Ortizb23aa672009-07-01 21:26:54 +02004705static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4706{
4707 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4708 NL80211_WPA_VERSION_2));
4709}
4710
Jouni Malinen636a5d32009-03-19 13:39:22 +02004711static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4712{
Johannes Berg4c476992010-10-04 21:36:35 +02004713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4714 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004715 struct ieee80211_channel *chan;
4716 const u8 *bssid, *ssid, *ie = NULL;
4717 int err, ssid_len, ie_len = 0;
4718 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004719 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004720 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004721
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004722 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4723 return -EINVAL;
4724
4725 if (!info->attrs[NL80211_ATTR_MAC])
4726 return -EINVAL;
4727
Jouni Malinen17780922009-03-27 20:52:47 +02004728 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4729 return -EINVAL;
4730
Johannes Berg19957bb2009-07-02 17:20:43 +02004731 if (!info->attrs[NL80211_ATTR_SSID])
4732 return -EINVAL;
4733
4734 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4735 return -EINVAL;
4736
Johannes Bergfffd0932009-07-08 14:22:54 +02004737 err = nl80211_parse_key(info, &key);
4738 if (err)
4739 return err;
4740
4741 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004742 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4743 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004744 if (!key.p.key || !key.p.key_len)
4745 return -EINVAL;
4746 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4747 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4748 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4749 key.p.key_len != WLAN_KEY_LEN_WEP104))
4750 return -EINVAL;
4751 if (key.idx > 4)
4752 return -EINVAL;
4753 } else {
4754 key.p.key_len = 0;
4755 key.p.key = NULL;
4756 }
4757
Johannes Bergafea0b72010-08-10 09:46:42 +02004758 if (key.idx >= 0) {
4759 int i;
4760 bool ok = false;
4761 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4762 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4763 ok = true;
4764 break;
4765 }
4766 }
Johannes Berg4c476992010-10-04 21:36:35 +02004767 if (!ok)
4768 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004769 }
4770
Johannes Berg4c476992010-10-04 21:36:35 +02004771 if (!rdev->ops->auth)
4772 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004773
Johannes Berg074ac8d2010-09-16 14:58:22 +02004774 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004775 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4776 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004777
Johannes Berg19957bb2009-07-02 17:20:43 +02004778 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004779 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004780 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004781 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4782 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004783
Johannes Berg19957bb2009-07-02 17:20:43 +02004784 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4785 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4786
4787 if (info->attrs[NL80211_ATTR_IE]) {
4788 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4789 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4790 }
4791
4792 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004793 if (!nl80211_valid_auth_type(auth_type))
4794 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004795
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004796 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4797
Johannes Berg95de8172012-01-20 13:55:25 +01004798 /*
4799 * Since we no longer track auth state, ignore
4800 * requests to only change local state.
4801 */
4802 if (local_state_change)
4803 return 0;
4804
Johannes Berg4c476992010-10-04 21:36:35 +02004805 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4806 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004807 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004808}
4809
Johannes Bergc0692b82010-08-27 14:26:53 +03004810static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4811 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004812 struct cfg80211_crypto_settings *settings,
4813 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004814{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004815 memset(settings, 0, sizeof(*settings));
4816
Samuel Ortizb23aa672009-07-01 21:26:54 +02004817 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4818
Johannes Bergc0692b82010-08-27 14:26:53 +03004819 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4820 u16 proto;
4821 proto = nla_get_u16(
4822 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4823 settings->control_port_ethertype = cpu_to_be16(proto);
4824 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4825 proto != ETH_P_PAE)
4826 return -EINVAL;
4827 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4828 settings->control_port_no_encrypt = true;
4829 } else
4830 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4831
Samuel Ortizb23aa672009-07-01 21:26:54 +02004832 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4833 void *data;
4834 int len, i;
4835
4836 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4837 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4838 settings->n_ciphers_pairwise = len / sizeof(u32);
4839
4840 if (len % sizeof(u32))
4841 return -EINVAL;
4842
Johannes Berg3dc27d22009-07-02 21:36:37 +02004843 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004844 return -EINVAL;
4845
4846 memcpy(settings->ciphers_pairwise, data, len);
4847
4848 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004849 if (!cfg80211_supported_cipher_suite(
4850 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004851 settings->ciphers_pairwise[i]))
4852 return -EINVAL;
4853 }
4854
4855 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4856 settings->cipher_group =
4857 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004858 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4859 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004860 return -EINVAL;
4861 }
4862
4863 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4864 settings->wpa_versions =
4865 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4866 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4867 return -EINVAL;
4868 }
4869
4870 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4871 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004872 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004873
4874 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4875 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4876 settings->n_akm_suites = len / sizeof(u32);
4877
4878 if (len % sizeof(u32))
4879 return -EINVAL;
4880
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004881 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4882 return -EINVAL;
4883
Samuel Ortizb23aa672009-07-01 21:26:54 +02004884 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004885 }
4886
4887 return 0;
4888}
4889
Jouni Malinen636a5d32009-03-19 13:39:22 +02004890static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4891{
Johannes Berg4c476992010-10-04 21:36:35 +02004892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4893 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004894 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004895 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004896 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004897 int err, ssid_len, ie_len = 0;
4898 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004899 u32 flags = 0;
4900 struct ieee80211_ht_cap *ht_capa = NULL;
4901 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004902
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004903 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4904 return -EINVAL;
4905
4906 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004907 !info->attrs[NL80211_ATTR_SSID] ||
4908 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004909 return -EINVAL;
4910
Johannes Berg4c476992010-10-04 21:36:35 +02004911 if (!rdev->ops->assoc)
4912 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004913
Johannes Berg074ac8d2010-09-16 14:58:22 +02004914 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004915 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4916 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004917
Johannes Berg19957bb2009-07-02 17:20:43 +02004918 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004919
Johannes Berg19957bb2009-07-02 17:20:43 +02004920 chan = ieee80211_get_channel(&rdev->wiphy,
4921 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004922 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4923 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004924
Johannes Berg19957bb2009-07-02 17:20:43 +02004925 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4926 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004927
4928 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004929 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4930 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004931 }
4932
Jouni Malinendc6382c2009-05-06 22:09:37 +03004933 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004934 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004935 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004936 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004937 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004938 else if (mfp != NL80211_MFP_NO)
4939 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004940 }
4941
Johannes Berg3e5d7642009-07-07 14:37:26 +02004942 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4943 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4944
Ben Greear7e7c8922011-11-18 11:31:59 -08004945 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4946 flags |= ASSOC_REQ_DISABLE_HT;
4947
4948 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4949 ht_capa_mask =
4950 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4951
4952 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4953 if (!ht_capa_mask)
4954 return -EINVAL;
4955 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4956 }
4957
Johannes Bergc0692b82010-08-27 14:26:53 +03004958 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004959 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004960 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4961 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004962 &crypto, flags, ht_capa,
4963 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004964
Jouni Malinen636a5d32009-03-19 13:39:22 +02004965 return err;
4966}
4967
4968static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4969{
Johannes Berg4c476992010-10-04 21:36:35 +02004970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4971 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004972 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004973 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004974 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004975 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004976
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004977 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4978 return -EINVAL;
4979
4980 if (!info->attrs[NL80211_ATTR_MAC])
4981 return -EINVAL;
4982
4983 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4984 return -EINVAL;
4985
Johannes Berg4c476992010-10-04 21:36:35 +02004986 if (!rdev->ops->deauth)
4987 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004988
Johannes Berg074ac8d2010-09-16 14:58:22 +02004989 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004990 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4991 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004992
Johannes Berg19957bb2009-07-02 17:20:43 +02004993 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004994
Johannes Berg19957bb2009-07-02 17:20:43 +02004995 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4996 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004997 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004998 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004999 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005000
5001 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005002 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5003 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005004 }
5005
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005006 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5007
Johannes Berg4c476992010-10-04 21:36:35 +02005008 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5009 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005010}
5011
5012static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5013{
Johannes Berg4c476992010-10-04 21:36:35 +02005014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5015 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005016 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005017 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005018 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005019 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005020
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005021 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5022 return -EINVAL;
5023
5024 if (!info->attrs[NL80211_ATTR_MAC])
5025 return -EINVAL;
5026
5027 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5028 return -EINVAL;
5029
Johannes Berg4c476992010-10-04 21:36:35 +02005030 if (!rdev->ops->disassoc)
5031 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005032
Johannes Berg074ac8d2010-09-16 14:58:22 +02005033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005034 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5035 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005036
Johannes Berg19957bb2009-07-02 17:20:43 +02005037 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005038
Johannes Berg19957bb2009-07-02 17:20:43 +02005039 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5040 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005041 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005042 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005043 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005044
5045 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005046 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5047 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005048 }
5049
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005050 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5051
Johannes Berg4c476992010-10-04 21:36:35 +02005052 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5053 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005054}
5055
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005056static bool
5057nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5058 int mcast_rate[IEEE80211_NUM_BANDS],
5059 int rateval)
5060{
5061 struct wiphy *wiphy = &rdev->wiphy;
5062 bool found = false;
5063 int band, i;
5064
5065 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5066 struct ieee80211_supported_band *sband;
5067
5068 sband = wiphy->bands[band];
5069 if (!sband)
5070 continue;
5071
5072 for (i = 0; i < sband->n_bitrates; i++) {
5073 if (sband->bitrates[i].bitrate == rateval) {
5074 mcast_rate[band] = i + 1;
5075 found = true;
5076 break;
5077 }
5078 }
5079 }
5080
5081 return found;
5082}
5083
Johannes Berg04a773a2009-04-19 21:24:32 +02005084static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5085{
Johannes Berg4c476992010-10-04 21:36:35 +02005086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5087 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005088 struct cfg80211_ibss_params ibss;
5089 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005090 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005091 int err;
5092
Johannes Berg8e30bc52009-04-22 17:45:38 +02005093 memset(&ibss, 0, sizeof(ibss));
5094
Johannes Berg04a773a2009-04-19 21:24:32 +02005095 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5096 return -EINVAL;
5097
5098 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5099 !info->attrs[NL80211_ATTR_SSID] ||
5100 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5101 return -EINVAL;
5102
Johannes Berg8e30bc52009-04-22 17:45:38 +02005103 ibss.beacon_interval = 100;
5104
5105 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5106 ibss.beacon_interval =
5107 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5108 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5109 return -EINVAL;
5110 }
5111
Johannes Berg4c476992010-10-04 21:36:35 +02005112 if (!rdev->ops->join_ibss)
5113 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005114
Johannes Berg4c476992010-10-04 21:36:35 +02005115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5116 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005117
Johannes Berg79c97e92009-07-07 03:56:12 +02005118 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005119
Johannes Berg39193492011-09-16 13:45:25 +02005120 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005121 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005122
5123 if (!is_valid_ether_addr(ibss.bssid))
5124 return -EINVAL;
5125 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005126 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5127 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5128
5129 if (info->attrs[NL80211_ATTR_IE]) {
5130 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5131 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5132 }
5133
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005134 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5135 enum nl80211_channel_type channel_type;
5136
Johannes Bergcd6c6592012-05-10 21:27:18 +02005137 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005138 return -EINVAL;
5139
5140 if (channel_type != NL80211_CHAN_NO_HT &&
5141 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5142 return -EINVAL;
5143
5144 ibss.channel_type = channel_type;
5145 } else {
5146 ibss.channel_type = NL80211_CHAN_NO_HT;
5147 }
5148
5149 ibss.channel = rdev_freq_to_chan(rdev,
5150 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5151 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005152 if (!ibss.channel ||
5153 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005154 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5155 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005156
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005157 /* Both channels should be able to initiate communication */
5158 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5159 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5160 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5161 ibss.channel_type))
5162 return -EINVAL;
5163
Johannes Berg04a773a2009-04-19 21:24:32 +02005164 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005165 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005166
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005167 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5168 u8 *rates =
5169 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5170 int n_rates =
5171 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5172 struct ieee80211_supported_band *sband =
5173 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005174
Johannes Berg34850ab2011-07-18 18:08:35 +02005175 err = ieee80211_get_ratemask(sband, rates, n_rates,
5176 &ibss.basic_rates);
5177 if (err)
5178 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005179 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005180
5181 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5182 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5183 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5184 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005185
Johannes Berg4c476992010-10-04 21:36:35 +02005186 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5187 connkeys = nl80211_parse_connkeys(rdev,
5188 info->attrs[NL80211_ATTR_KEYS]);
5189 if (IS_ERR(connkeys))
5190 return PTR_ERR(connkeys);
5191 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005192
Antonio Quartulli267335d2012-01-31 20:25:47 +01005193 ibss.control_port =
5194 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5195
Johannes Berg4c476992010-10-04 21:36:35 +02005196 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005197 if (err)
5198 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005199 return err;
5200}
5201
5202static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5203{
Johannes Berg4c476992010-10-04 21:36:35 +02005204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5205 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005206
Johannes Berg4c476992010-10-04 21:36:35 +02005207 if (!rdev->ops->leave_ibss)
5208 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005209
Johannes Berg4c476992010-10-04 21:36:35 +02005210 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5211 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005212
Johannes Berg4c476992010-10-04 21:36:35 +02005213 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005214}
5215
Johannes Bergaff89a92009-07-01 21:26:51 +02005216#ifdef CONFIG_NL80211_TESTMODE
5217static struct genl_multicast_group nl80211_testmode_mcgrp = {
5218 .name = "testmode",
5219};
5220
5221static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5222{
Johannes Berg4c476992010-10-04 21:36:35 +02005223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005224 int err;
5225
5226 if (!info->attrs[NL80211_ATTR_TESTDATA])
5227 return -EINVAL;
5228
Johannes Bergaff89a92009-07-01 21:26:51 +02005229 err = -EOPNOTSUPP;
5230 if (rdev->ops->testmode_cmd) {
5231 rdev->testmode_info = info;
5232 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5233 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5234 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5235 rdev->testmode_info = NULL;
5236 }
5237
Johannes Bergaff89a92009-07-01 21:26:51 +02005238 return err;
5239}
5240
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005241static int nl80211_testmode_dump(struct sk_buff *skb,
5242 struct netlink_callback *cb)
5243{
Johannes Berg00918d32011-12-13 17:22:05 +01005244 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005245 int err;
5246 long phy_idx;
5247 void *data = NULL;
5248 int data_len = 0;
5249
5250 if (cb->args[0]) {
5251 /*
5252 * 0 is a valid index, but not valid for args[0],
5253 * so we need to offset by 1.
5254 */
5255 phy_idx = cb->args[0] - 1;
5256 } else {
5257 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5258 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5259 nl80211_policy);
5260 if (err)
5261 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005262
Johannes Berg2bd7e352012-06-15 14:23:16 +02005263 mutex_lock(&cfg80211_mutex);
5264 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5265 nl80211_fam.attrbuf);
5266 if (IS_ERR(rdev)) {
5267 mutex_unlock(&cfg80211_mutex);
5268 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005269 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005270 phy_idx = rdev->wiphy_idx;
5271 rdev = NULL;
5272 mutex_unlock(&cfg80211_mutex);
5273
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005274 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5275 cb->args[1] =
5276 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5277 }
5278
5279 if (cb->args[1]) {
5280 data = nla_data((void *)cb->args[1]);
5281 data_len = nla_len((void *)cb->args[1]);
5282 }
5283
5284 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005285 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5286 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005287 mutex_unlock(&cfg80211_mutex);
5288 return -ENOENT;
5289 }
Johannes Berg00918d32011-12-13 17:22:05 +01005290 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005291 mutex_unlock(&cfg80211_mutex);
5292
Johannes Berg00918d32011-12-13 17:22:05 +01005293 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005294 err = -EOPNOTSUPP;
5295 goto out_err;
5296 }
5297
5298 while (1) {
5299 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5300 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5301 NL80211_CMD_TESTMODE);
5302 struct nlattr *tmdata;
5303
David S. Miller9360ffd2012-03-29 04:41:26 -04005304 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005305 genlmsg_cancel(skb, hdr);
5306 break;
5307 }
5308
5309 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5310 if (!tmdata) {
5311 genlmsg_cancel(skb, hdr);
5312 break;
5313 }
Johannes Berg00918d32011-12-13 17:22:05 +01005314 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5315 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005316 nla_nest_end(skb, tmdata);
5317
5318 if (err == -ENOBUFS || err == -ENOENT) {
5319 genlmsg_cancel(skb, hdr);
5320 break;
5321 } else if (err) {
5322 genlmsg_cancel(skb, hdr);
5323 goto out_err;
5324 }
5325
5326 genlmsg_end(skb, hdr);
5327 }
5328
5329 err = skb->len;
5330 /* see above */
5331 cb->args[0] = phy_idx + 1;
5332 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005333 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005334 return err;
5335}
5336
Johannes Bergaff89a92009-07-01 21:26:51 +02005337static struct sk_buff *
5338__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5339 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5340{
5341 struct sk_buff *skb;
5342 void *hdr;
5343 struct nlattr *data;
5344
5345 skb = nlmsg_new(approxlen + 100, gfp);
5346 if (!skb)
5347 return NULL;
5348
5349 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5350 if (!hdr) {
5351 kfree_skb(skb);
5352 return NULL;
5353 }
5354
David S. Miller9360ffd2012-03-29 04:41:26 -04005355 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5356 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005357 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5358
5359 ((void **)skb->cb)[0] = rdev;
5360 ((void **)skb->cb)[1] = hdr;
5361 ((void **)skb->cb)[2] = data;
5362
5363 return skb;
5364
5365 nla_put_failure:
5366 kfree_skb(skb);
5367 return NULL;
5368}
5369
5370struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5371 int approxlen)
5372{
5373 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5374
5375 if (WARN_ON(!rdev->testmode_info))
5376 return NULL;
5377
5378 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5379 rdev->testmode_info->snd_pid,
5380 rdev->testmode_info->snd_seq,
5381 GFP_KERNEL);
5382}
5383EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5384
5385int cfg80211_testmode_reply(struct sk_buff *skb)
5386{
5387 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5388 void *hdr = ((void **)skb->cb)[1];
5389 struct nlattr *data = ((void **)skb->cb)[2];
5390
5391 if (WARN_ON(!rdev->testmode_info)) {
5392 kfree_skb(skb);
5393 return -EINVAL;
5394 }
5395
5396 nla_nest_end(skb, data);
5397 genlmsg_end(skb, hdr);
5398 return genlmsg_reply(skb, rdev->testmode_info);
5399}
5400EXPORT_SYMBOL(cfg80211_testmode_reply);
5401
5402struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5403 int approxlen, gfp_t gfp)
5404{
5405 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5406
5407 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5408}
5409EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5410
5411void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5412{
5413 void *hdr = ((void **)skb->cb)[1];
5414 struct nlattr *data = ((void **)skb->cb)[2];
5415
5416 nla_nest_end(skb, data);
5417 genlmsg_end(skb, hdr);
5418 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5419}
5420EXPORT_SYMBOL(cfg80211_testmode_event);
5421#endif
5422
Samuel Ortizb23aa672009-07-01 21:26:54 +02005423static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5424{
Johannes Berg4c476992010-10-04 21:36:35 +02005425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5426 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005427 struct cfg80211_connect_params connect;
5428 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005429 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005430 int err;
5431
5432 memset(&connect, 0, sizeof(connect));
5433
5434 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5435 return -EINVAL;
5436
5437 if (!info->attrs[NL80211_ATTR_SSID] ||
5438 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5439 return -EINVAL;
5440
5441 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5442 connect.auth_type =
5443 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5444 if (!nl80211_valid_auth_type(connect.auth_type))
5445 return -EINVAL;
5446 } else
5447 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5448
5449 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5450
Johannes Bergc0692b82010-08-27 14:26:53 +03005451 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005452 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005453 if (err)
5454 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005455
Johannes Berg074ac8d2010-09-16 14:58:22 +02005456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005457 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5458 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005459
Johannes Berg79c97e92009-07-07 03:56:12 +02005460 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005461
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305462 connect.bg_scan_period = -1;
5463 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5464 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5465 connect.bg_scan_period =
5466 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5467 }
5468
Samuel Ortizb23aa672009-07-01 21:26:54 +02005469 if (info->attrs[NL80211_ATTR_MAC])
5470 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5471 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5472 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5473
5474 if (info->attrs[NL80211_ATTR_IE]) {
5475 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5476 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5477 }
5478
5479 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5480 connect.channel =
5481 ieee80211_get_channel(wiphy,
5482 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5483 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005484 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5485 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005486 }
5487
Johannes Bergfffd0932009-07-08 14:22:54 +02005488 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5489 connkeys = nl80211_parse_connkeys(rdev,
5490 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005491 if (IS_ERR(connkeys))
5492 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005493 }
5494
Ben Greear7e7c8922011-11-18 11:31:59 -08005495 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5496 connect.flags |= ASSOC_REQ_DISABLE_HT;
5497
5498 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5499 memcpy(&connect.ht_capa_mask,
5500 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5501 sizeof(connect.ht_capa_mask));
5502
5503 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5504 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5505 return -EINVAL;
5506 memcpy(&connect.ht_capa,
5507 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5508 sizeof(connect.ht_capa));
5509 }
5510
Johannes Bergfffd0932009-07-08 14:22:54 +02005511 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005512 if (err)
5513 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005514 return err;
5515}
5516
5517static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5518{
Johannes Berg4c476992010-10-04 21:36:35 +02005519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5520 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005521 u16 reason;
5522
5523 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5524 reason = WLAN_REASON_DEAUTH_LEAVING;
5525 else
5526 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5527
5528 if (reason == 0)
5529 return -EINVAL;
5530
Johannes Berg074ac8d2010-09-16 14:58:22 +02005531 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005532 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5533 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005534
Johannes Berg4c476992010-10-04 21:36:35 +02005535 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005536}
5537
Johannes Berg463d0182009-07-14 00:33:35 +02005538static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5539{
Johannes Berg4c476992010-10-04 21:36:35 +02005540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005541 struct net *net;
5542 int err;
5543 u32 pid;
5544
5545 if (!info->attrs[NL80211_ATTR_PID])
5546 return -EINVAL;
5547
5548 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5549
Johannes Berg463d0182009-07-14 00:33:35 +02005550 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005551 if (IS_ERR(net))
5552 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005553
5554 err = 0;
5555
5556 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005557 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5558 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005559
Johannes Berg463d0182009-07-14 00:33:35 +02005560 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005561 return err;
5562}
5563
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005564static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5565{
Johannes Berg4c476992010-10-04 21:36:35 +02005566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005567 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5568 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005569 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005570 struct cfg80211_pmksa pmksa;
5571
5572 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5573
5574 if (!info->attrs[NL80211_ATTR_MAC])
5575 return -EINVAL;
5576
5577 if (!info->attrs[NL80211_ATTR_PMKID])
5578 return -EINVAL;
5579
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005580 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5581 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5582
Johannes Berg074ac8d2010-09-16 14:58:22 +02005583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005584 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5585 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005586
5587 switch (info->genlhdr->cmd) {
5588 case NL80211_CMD_SET_PMKSA:
5589 rdev_ops = rdev->ops->set_pmksa;
5590 break;
5591 case NL80211_CMD_DEL_PMKSA:
5592 rdev_ops = rdev->ops->del_pmksa;
5593 break;
5594 default:
5595 WARN_ON(1);
5596 break;
5597 }
5598
Johannes Berg4c476992010-10-04 21:36:35 +02005599 if (!rdev_ops)
5600 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005601
Johannes Berg4c476992010-10-04 21:36:35 +02005602 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005603}
5604
5605static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5606{
Johannes Berg4c476992010-10-04 21:36:35 +02005607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5608 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005609
Johannes Berg074ac8d2010-09-16 14:58:22 +02005610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005611 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5612 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005613
Johannes Berg4c476992010-10-04 21:36:35 +02005614 if (!rdev->ops->flush_pmksa)
5615 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005616
Johannes Berg4c476992010-10-04 21:36:35 +02005617 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005618}
5619
Arik Nemtsov109086c2011-09-28 14:12:50 +03005620static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5621{
5622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5623 struct net_device *dev = info->user_ptr[1];
5624 u8 action_code, dialog_token;
5625 u16 status_code;
5626 u8 *peer;
5627
5628 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5629 !rdev->ops->tdls_mgmt)
5630 return -EOPNOTSUPP;
5631
5632 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5633 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5634 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5635 !info->attrs[NL80211_ATTR_IE] ||
5636 !info->attrs[NL80211_ATTR_MAC])
5637 return -EINVAL;
5638
5639 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5640 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5641 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5642 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5643
5644 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5645 dialog_token, status_code,
5646 nla_data(info->attrs[NL80211_ATTR_IE]),
5647 nla_len(info->attrs[NL80211_ATTR_IE]));
5648}
5649
5650static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5651{
5652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5653 struct net_device *dev = info->user_ptr[1];
5654 enum nl80211_tdls_operation operation;
5655 u8 *peer;
5656
5657 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5658 !rdev->ops->tdls_oper)
5659 return -EOPNOTSUPP;
5660
5661 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5662 !info->attrs[NL80211_ATTR_MAC])
5663 return -EINVAL;
5664
5665 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5666 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5667
5668 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5669}
5670
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005671static int nl80211_remain_on_channel(struct sk_buff *skb,
5672 struct genl_info *info)
5673{
Johannes Berg4c476992010-10-04 21:36:35 +02005674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5675 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005676 struct ieee80211_channel *chan;
5677 struct sk_buff *msg;
5678 void *hdr;
5679 u64 cookie;
5680 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5681 u32 freq, duration;
5682 int err;
5683
5684 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5685 !info->attrs[NL80211_ATTR_DURATION])
5686 return -EINVAL;
5687
5688 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5689
Johannes Berg7c4ef712011-11-18 15:33:48 +01005690 if (!rdev->ops->remain_on_channel ||
5691 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005692 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005693
Johannes Bergebf348f2012-06-01 12:50:54 +02005694 /*
5695 * We should be on that channel for at least a minimum amount of
5696 * time (10ms) but no longer than the driver supports.
5697 */
5698 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5699 duration > rdev->wiphy.max_remain_on_channel_duration)
5700 return -EINVAL;
5701
Johannes Bergcd6c6592012-05-10 21:27:18 +02005702 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5703 !nl80211_valid_channel_type(info, &channel_type))
5704 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005705
5706 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5707 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005708 if (chan == NULL)
5709 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005710
5711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005712 if (!msg)
5713 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005714
5715 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5716 NL80211_CMD_REMAIN_ON_CHANNEL);
5717
5718 if (IS_ERR(hdr)) {
5719 err = PTR_ERR(hdr);
5720 goto free_msg;
5721 }
5722
5723 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5724 channel_type, duration, &cookie);
5725
5726 if (err)
5727 goto free_msg;
5728
David S. Miller9360ffd2012-03-29 04:41:26 -04005729 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5730 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005731
5732 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005733
5734 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005735
5736 nla_put_failure:
5737 err = -ENOBUFS;
5738 free_msg:
5739 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005740 return err;
5741}
5742
5743static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5744 struct genl_info *info)
5745{
Johannes Berg4c476992010-10-04 21:36:35 +02005746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5747 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005748 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005749
5750 if (!info->attrs[NL80211_ATTR_COOKIE])
5751 return -EINVAL;
5752
Johannes Berg4c476992010-10-04 21:36:35 +02005753 if (!rdev->ops->cancel_remain_on_channel)
5754 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005755
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005756 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5757
Johannes Berg4c476992010-10-04 21:36:35 +02005758 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005759}
5760
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005761static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5762 u8 *rates, u8 rates_len)
5763{
5764 u8 i;
5765 u32 mask = 0;
5766
5767 for (i = 0; i < rates_len; i++) {
5768 int rate = (rates[i] & 0x7f) * 5;
5769 int ridx;
5770 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5771 struct ieee80211_rate *srate =
5772 &sband->bitrates[ridx];
5773 if (rate == srate->bitrate) {
5774 mask |= 1 << ridx;
5775 break;
5776 }
5777 }
5778 if (ridx == sband->n_bitrates)
5779 return 0; /* rate not found */
5780 }
5781
5782 return mask;
5783}
5784
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005785static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5786 u8 *rates, u8 rates_len,
5787 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5788{
5789 u8 i;
5790
5791 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5792
5793 for (i = 0; i < rates_len; i++) {
5794 int ridx, rbit;
5795
5796 ridx = rates[i] / 8;
5797 rbit = BIT(rates[i] % 8);
5798
5799 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005800 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005801 return false;
5802
5803 /* check availability */
5804 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5805 mcs[ridx] |= rbit;
5806 else
5807 return false;
5808 }
5809
5810 return true;
5811}
5812
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005813static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005814 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5815 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005816 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5817 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005818};
5819
5820static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5821 struct genl_info *info)
5822{
5823 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005825 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005826 int rem, i;
5827 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005828 struct nlattr *tx_rates;
5829 struct ieee80211_supported_band *sband;
5830
5831 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5832 return -EINVAL;
5833
Johannes Berg4c476992010-10-04 21:36:35 +02005834 if (!rdev->ops->set_bitrate_mask)
5835 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005836
5837 memset(&mask, 0, sizeof(mask));
5838 /* Default to all rates enabled */
5839 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5840 sband = rdev->wiphy.bands[i];
5841 mask.control[i].legacy =
5842 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005843 if (sband)
5844 memcpy(mask.control[i].mcs,
5845 sband->ht_cap.mcs.rx_mask,
5846 sizeof(mask.control[i].mcs));
5847 else
5848 memset(mask.control[i].mcs, 0,
5849 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005850 }
5851
5852 /*
5853 * The nested attribute uses enum nl80211_band as the index. This maps
5854 * directly to the enum ieee80211_band values used in cfg80211.
5855 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005856 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005857 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5858 {
5859 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005860 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5861 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005862 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005863 if (sband == NULL)
5864 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005865 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5866 nla_len(tx_rates), nl80211_txattr_policy);
5867 if (tb[NL80211_TXRATE_LEGACY]) {
5868 mask.control[band].legacy = rateset_to_mask(
5869 sband,
5870 nla_data(tb[NL80211_TXRATE_LEGACY]),
5871 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305872 if ((mask.control[band].legacy == 0) &&
5873 nla_len(tb[NL80211_TXRATE_LEGACY]))
5874 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005875 }
5876 if (tb[NL80211_TXRATE_MCS]) {
5877 if (!ht_rateset_to_mask(
5878 sband,
5879 nla_data(tb[NL80211_TXRATE_MCS]),
5880 nla_len(tb[NL80211_TXRATE_MCS]),
5881 mask.control[band].mcs))
5882 return -EINVAL;
5883 }
5884
5885 if (mask.control[band].legacy == 0) {
5886 /* don't allow empty legacy rates if HT
5887 * is not even supported. */
5888 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5889 return -EINVAL;
5890
5891 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5892 if (mask.control[band].mcs[i])
5893 break;
5894
5895 /* legacy and mcs rates may not be both empty */
5896 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005897 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005898 }
5899 }
5900
Johannes Berg4c476992010-10-04 21:36:35 +02005901 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005902}
5903
Johannes Berg2e161f72010-08-12 15:38:38 +02005904static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005905{
Johannes Berg4c476992010-10-04 21:36:35 +02005906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5907 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005908 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005909
5910 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5911 return -EINVAL;
5912
Johannes Berg2e161f72010-08-12 15:38:38 +02005913 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5914 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005915
Johannes Berg9d38d852010-06-09 17:20:33 +02005916 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005917 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5919 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5920 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005921 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5923 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005924
5925 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005926 if (!rdev->ops->mgmt_tx)
5927 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005928
Johannes Berg4c476992010-10-04 21:36:35 +02005929 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005930 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005931 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5932 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005933}
5934
Johannes Berg2e161f72010-08-12 15:38:38 +02005935static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005936{
Johannes Berg4c476992010-10-04 21:36:35 +02005937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5938 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005939 struct ieee80211_channel *chan;
5940 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005941 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005942 u32 freq;
5943 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005944 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005945 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005946 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005947 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005948 bool offchan, no_cck, dont_wait_for_ack;
5949
5950 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005951
5952 if (!info->attrs[NL80211_ATTR_FRAME] ||
5953 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5954 return -EINVAL;
5955
Johannes Berg4c476992010-10-04 21:36:35 +02005956 if (!rdev->ops->mgmt_tx)
5957 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005958
Johannes Berg9d38d852010-06-09 17:20:33 +02005959 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005961 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5962 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005965 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5966 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005967
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005968 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005969 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005970 return -EINVAL;
5971 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005972
5973 /*
5974 * We should wait on the channel for at least a minimum amount
5975 * of time (10ms) but no longer than the driver supports.
5976 */
5977 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5978 wait > rdev->wiphy.max_remain_on_channel_duration)
5979 return -EINVAL;
5980
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005981 }
5982
Jouni Malinen026331c2010-02-15 12:53:10 +02005983 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005984 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005985 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005986 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005987 }
5988
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005989 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5990
Johannes Berg7c4ef712011-11-18 15:33:48 +01005991 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5992 return -EINVAL;
5993
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305994 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5995
Jouni Malinen026331c2010-02-15 12:53:10 +02005996 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5997 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005998 if (chan == NULL)
5999 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006000
Johannes Berge247bd902011-11-04 11:18:21 +01006001 if (!dont_wait_for_ack) {
6002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6003 if (!msg)
6004 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006005
Johannes Berge247bd902011-11-04 11:18:21 +01006006 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6007 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006008
Johannes Berge247bd902011-11-04 11:18:21 +01006009 if (IS_ERR(hdr)) {
6010 err = PTR_ERR(hdr);
6011 goto free_msg;
6012 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006013 }
Johannes Berge247bd902011-11-04 11:18:21 +01006014
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006015 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
6016 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006017 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6018 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006019 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006020 if (err)
6021 goto free_msg;
6022
Johannes Berge247bd902011-11-04 11:18:21 +01006023 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006024 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6025 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006026
Johannes Berge247bd902011-11-04 11:18:21 +01006027 genlmsg_end(msg, hdr);
6028 return genlmsg_reply(msg, info);
6029 }
6030
6031 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006032
6033 nla_put_failure:
6034 err = -ENOBUFS;
6035 free_msg:
6036 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006037 return err;
6038}
6039
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006040static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6041{
6042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6043 struct net_device *dev = info->user_ptr[1];
6044 u64 cookie;
6045
6046 if (!info->attrs[NL80211_ATTR_COOKIE])
6047 return -EINVAL;
6048
6049 if (!rdev->ops->mgmt_tx_cancel_wait)
6050 return -EOPNOTSUPP;
6051
6052 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6053 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6054 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6055 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6056 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6057 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6058 return -EOPNOTSUPP;
6059
6060 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6061
6062 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6063}
6064
Kalle Valoffb9eb32010-02-17 17:58:10 +02006065static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6066{
Johannes Berg4c476992010-10-04 21:36:35 +02006067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006068 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006069 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006070 u8 ps_state;
6071 bool state;
6072 int err;
6073
Johannes Berg4c476992010-10-04 21:36:35 +02006074 if (!info->attrs[NL80211_ATTR_PS_STATE])
6075 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006076
6077 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6078
Johannes Berg4c476992010-10-04 21:36:35 +02006079 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6080 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006081
6082 wdev = dev->ieee80211_ptr;
6083
Johannes Berg4c476992010-10-04 21:36:35 +02006084 if (!rdev->ops->set_power_mgmt)
6085 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006086
6087 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6088
6089 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006090 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006091
Johannes Berg4c476992010-10-04 21:36:35 +02006092 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6093 wdev->ps_timeout);
6094 if (!err)
6095 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006096 return err;
6097}
6098
6099static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6100{
Johannes Berg4c476992010-10-04 21:36:35 +02006101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006102 enum nl80211_ps_state ps_state;
6103 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006104 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006105 struct sk_buff *msg;
6106 void *hdr;
6107 int err;
6108
Kalle Valoffb9eb32010-02-17 17:58:10 +02006109 wdev = dev->ieee80211_ptr;
6110
Johannes Berg4c476992010-10-04 21:36:35 +02006111 if (!rdev->ops->set_power_mgmt)
6112 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006113
6114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006115 if (!msg)
6116 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006117
6118 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6119 NL80211_CMD_GET_POWER_SAVE);
6120 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006121 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006122 goto free_msg;
6123 }
6124
6125 if (wdev->ps)
6126 ps_state = NL80211_PS_ENABLED;
6127 else
6128 ps_state = NL80211_PS_DISABLED;
6129
David S. Miller9360ffd2012-03-29 04:41:26 -04006130 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6131 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006132
6133 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006134 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006135
Johannes Berg4c476992010-10-04 21:36:35 +02006136 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006137 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006138 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006139 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006140 return err;
6141}
6142
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006143static struct nla_policy
6144nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6145 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6146 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6147 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6148};
6149
6150static int nl80211_set_cqm_rssi(struct genl_info *info,
6151 s32 threshold, u32 hysteresis)
6152{
Johannes Berg4c476992010-10-04 21:36:35 +02006153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006154 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006155 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006156
6157 if (threshold > 0)
6158 return -EINVAL;
6159
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006160 wdev = dev->ieee80211_ptr;
6161
Johannes Berg4c476992010-10-04 21:36:35 +02006162 if (!rdev->ops->set_cqm_rssi_config)
6163 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006164
Johannes Berg074ac8d2010-09-16 14:58:22 +02006165 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006166 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6167 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006168
Johannes Berg4c476992010-10-04 21:36:35 +02006169 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6170 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006171}
6172
6173static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6174{
6175 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6176 struct nlattr *cqm;
6177 int err;
6178
6179 cqm = info->attrs[NL80211_ATTR_CQM];
6180 if (!cqm) {
6181 err = -EINVAL;
6182 goto out;
6183 }
6184
6185 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6186 nl80211_attr_cqm_policy);
6187 if (err)
6188 goto out;
6189
6190 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6191 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6192 s32 threshold;
6193 u32 hysteresis;
6194 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6195 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6196 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6197 } else
6198 err = -EINVAL;
6199
6200out:
6201 return err;
6202}
6203
Johannes Berg29cbe682010-12-03 09:20:44 +01006204static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6205{
6206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6207 struct net_device *dev = info->user_ptr[1];
6208 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006209 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006210 int err;
6211
6212 /* start with default */
6213 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006214 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006215
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006216 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006217 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006218 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006219 if (err)
6220 return err;
6221 }
6222
6223 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6224 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6225 return -EINVAL;
6226
Javier Cardonac80d5452010-12-16 17:37:49 -08006227 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6228 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6229
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006230 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6231 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6232 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6233 return -EINVAL;
6234
Javier Cardonac80d5452010-12-16 17:37:49 -08006235 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6236 /* parse additional setup parameters if given */
6237 err = nl80211_parse_mesh_setup(info, &setup);
6238 if (err)
6239 return err;
6240 }
6241
Johannes Bergcc1d2802012-05-16 23:50:20 +02006242 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6243 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6244
6245 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6246 !nl80211_valid_channel_type(info, &channel_type))
6247 return -EINVAL;
6248
6249 setup.channel = rdev_freq_to_chan(rdev,
6250 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6251 channel_type);
6252 if (!setup.channel)
6253 return -EINVAL;
6254 setup.channel_type = channel_type;
6255 } else {
6256 /* cfg80211_join_mesh() will sort it out */
6257 setup.channel = NULL;
6258 }
6259
Javier Cardonac80d5452010-12-16 17:37:49 -08006260 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006261}
6262
6263static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6264{
6265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6266 struct net_device *dev = info->user_ptr[1];
6267
6268 return cfg80211_leave_mesh(rdev, dev);
6269}
6270
Johannes Bergdfb89c52012-06-27 09:23:48 +02006271#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006272static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6273{
6274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6275 struct sk_buff *msg;
6276 void *hdr;
6277
6278 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6279 return -EOPNOTSUPP;
6280
6281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6282 if (!msg)
6283 return -ENOMEM;
6284
6285 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6286 NL80211_CMD_GET_WOWLAN);
6287 if (!hdr)
6288 goto nla_put_failure;
6289
6290 if (rdev->wowlan) {
6291 struct nlattr *nl_wowlan;
6292
6293 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6294 if (!nl_wowlan)
6295 goto nla_put_failure;
6296
David S. Miller9360ffd2012-03-29 04:41:26 -04006297 if ((rdev->wowlan->any &&
6298 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6299 (rdev->wowlan->disconnect &&
6300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6301 (rdev->wowlan->magic_pkt &&
6302 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6303 (rdev->wowlan->gtk_rekey_failure &&
6304 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6305 (rdev->wowlan->eap_identity_req &&
6306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6307 (rdev->wowlan->four_way_handshake &&
6308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6309 (rdev->wowlan->rfkill_release &&
6310 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6311 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006312 if (rdev->wowlan->n_patterns) {
6313 struct nlattr *nl_pats, *nl_pat;
6314 int i, pat_len;
6315
6316 nl_pats = nla_nest_start(msg,
6317 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6318 if (!nl_pats)
6319 goto nla_put_failure;
6320
6321 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6322 nl_pat = nla_nest_start(msg, i + 1);
6323 if (!nl_pat)
6324 goto nla_put_failure;
6325 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006326 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6327 DIV_ROUND_UP(pat_len, 8),
6328 rdev->wowlan->patterns[i].mask) ||
6329 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6330 pat_len,
6331 rdev->wowlan->patterns[i].pattern))
6332 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006333 nla_nest_end(msg, nl_pat);
6334 }
6335 nla_nest_end(msg, nl_pats);
6336 }
6337
6338 nla_nest_end(msg, nl_wowlan);
6339 }
6340
6341 genlmsg_end(msg, hdr);
6342 return genlmsg_reply(msg, info);
6343
6344nla_put_failure:
6345 nlmsg_free(msg);
6346 return -ENOBUFS;
6347}
6348
6349static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6350{
6351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6352 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6353 struct cfg80211_wowlan no_triggers = {};
6354 struct cfg80211_wowlan new_triggers = {};
6355 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6356 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006357 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006358
6359 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6360 return -EOPNOTSUPP;
6361
6362 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6363 goto no_triggers;
6364
6365 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6366 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6367 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6368 nl80211_wowlan_policy);
6369 if (err)
6370 return err;
6371
6372 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6373 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6374 return -EINVAL;
6375 new_triggers.any = true;
6376 }
6377
6378 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6379 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6380 return -EINVAL;
6381 new_triggers.disconnect = true;
6382 }
6383
6384 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6385 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6386 return -EINVAL;
6387 new_triggers.magic_pkt = true;
6388 }
6389
Johannes Berg77dbbb12011-07-13 10:48:55 +02006390 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6391 return -EINVAL;
6392
6393 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6394 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6395 return -EINVAL;
6396 new_triggers.gtk_rekey_failure = true;
6397 }
6398
6399 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6400 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6401 return -EINVAL;
6402 new_triggers.eap_identity_req = true;
6403 }
6404
6405 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6406 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6407 return -EINVAL;
6408 new_triggers.four_way_handshake = true;
6409 }
6410
6411 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6412 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6413 return -EINVAL;
6414 new_triggers.rfkill_release = true;
6415 }
6416
Johannes Bergff1b6e62011-05-04 15:37:28 +02006417 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6418 struct nlattr *pat;
6419 int n_patterns = 0;
6420 int rem, pat_len, mask_len;
6421 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6422
6423 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6424 rem)
6425 n_patterns++;
6426 if (n_patterns > wowlan->n_patterns)
6427 return -EINVAL;
6428
6429 new_triggers.patterns = kcalloc(n_patterns,
6430 sizeof(new_triggers.patterns[0]),
6431 GFP_KERNEL);
6432 if (!new_triggers.patterns)
6433 return -ENOMEM;
6434
6435 new_triggers.n_patterns = n_patterns;
6436 i = 0;
6437
6438 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6439 rem) {
6440 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6441 nla_data(pat), nla_len(pat), NULL);
6442 err = -EINVAL;
6443 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6444 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6445 goto error;
6446 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6447 mask_len = DIV_ROUND_UP(pat_len, 8);
6448 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6449 mask_len)
6450 goto error;
6451 if (pat_len > wowlan->pattern_max_len ||
6452 pat_len < wowlan->pattern_min_len)
6453 goto error;
6454
6455 new_triggers.patterns[i].mask =
6456 kmalloc(mask_len + pat_len, GFP_KERNEL);
6457 if (!new_triggers.patterns[i].mask) {
6458 err = -ENOMEM;
6459 goto error;
6460 }
6461 new_triggers.patterns[i].pattern =
6462 new_triggers.patterns[i].mask + mask_len;
6463 memcpy(new_triggers.patterns[i].mask,
6464 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6465 mask_len);
6466 new_triggers.patterns[i].pattern_len = pat_len;
6467 memcpy(new_triggers.patterns[i].pattern,
6468 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6469 pat_len);
6470 i++;
6471 }
6472 }
6473
6474 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6475 struct cfg80211_wowlan *ntrig;
6476 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6477 GFP_KERNEL);
6478 if (!ntrig) {
6479 err = -ENOMEM;
6480 goto error;
6481 }
6482 cfg80211_rdev_free_wowlan(rdev);
6483 rdev->wowlan = ntrig;
6484 } else {
6485 no_triggers:
6486 cfg80211_rdev_free_wowlan(rdev);
6487 rdev->wowlan = NULL;
6488 }
6489
Johannes Berg6d525632012-04-04 15:05:25 +02006490 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6491 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6492
Johannes Bergff1b6e62011-05-04 15:37:28 +02006493 return 0;
6494 error:
6495 for (i = 0; i < new_triggers.n_patterns; i++)
6496 kfree(new_triggers.patterns[i].mask);
6497 kfree(new_triggers.patterns);
6498 return err;
6499}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006500#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006501
Johannes Berge5497d72011-07-05 16:35:40 +02006502static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6503{
6504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6505 struct net_device *dev = info->user_ptr[1];
6506 struct wireless_dev *wdev = dev->ieee80211_ptr;
6507 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6508 struct cfg80211_gtk_rekey_data rekey_data;
6509 int err;
6510
6511 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6512 return -EINVAL;
6513
6514 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6515 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6516 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6517 nl80211_rekey_policy);
6518 if (err)
6519 return err;
6520
6521 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6522 return -ERANGE;
6523 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6524 return -ERANGE;
6525 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6526 return -ERANGE;
6527
6528 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6529 NL80211_KEK_LEN);
6530 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6531 NL80211_KCK_LEN);
6532 memcpy(rekey_data.replay_ctr,
6533 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6534 NL80211_REPLAY_CTR_LEN);
6535
6536 wdev_lock(wdev);
6537 if (!wdev->current_bss) {
6538 err = -ENOTCONN;
6539 goto out;
6540 }
6541
6542 if (!rdev->ops->set_rekey_data) {
6543 err = -EOPNOTSUPP;
6544 goto out;
6545 }
6546
6547 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6548 out:
6549 wdev_unlock(wdev);
6550 return err;
6551}
6552
Johannes Berg28946da2011-11-04 11:18:12 +01006553static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6554 struct genl_info *info)
6555{
6556 struct net_device *dev = info->user_ptr[1];
6557 struct wireless_dev *wdev = dev->ieee80211_ptr;
6558
6559 if (wdev->iftype != NL80211_IFTYPE_AP &&
6560 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6561 return -EINVAL;
6562
6563 if (wdev->ap_unexpected_nlpid)
6564 return -EBUSY;
6565
6566 wdev->ap_unexpected_nlpid = info->snd_pid;
6567 return 0;
6568}
6569
Johannes Berg7f6cf312011-11-04 11:18:15 +01006570static int nl80211_probe_client(struct sk_buff *skb,
6571 struct genl_info *info)
6572{
6573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6574 struct net_device *dev = info->user_ptr[1];
6575 struct wireless_dev *wdev = dev->ieee80211_ptr;
6576 struct sk_buff *msg;
6577 void *hdr;
6578 const u8 *addr;
6579 u64 cookie;
6580 int err;
6581
6582 if (wdev->iftype != NL80211_IFTYPE_AP &&
6583 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6584 return -EOPNOTSUPP;
6585
6586 if (!info->attrs[NL80211_ATTR_MAC])
6587 return -EINVAL;
6588
6589 if (!rdev->ops->probe_client)
6590 return -EOPNOTSUPP;
6591
6592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6593 if (!msg)
6594 return -ENOMEM;
6595
6596 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6597 NL80211_CMD_PROBE_CLIENT);
6598
6599 if (IS_ERR(hdr)) {
6600 err = PTR_ERR(hdr);
6601 goto free_msg;
6602 }
6603
6604 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6605
6606 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6607 if (err)
6608 goto free_msg;
6609
David S. Miller9360ffd2012-03-29 04:41:26 -04006610 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6611 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006612
6613 genlmsg_end(msg, hdr);
6614
6615 return genlmsg_reply(msg, info);
6616
6617 nla_put_failure:
6618 err = -ENOBUFS;
6619 free_msg:
6620 nlmsg_free(msg);
6621 return err;
6622}
6623
Johannes Berg5e7602302011-11-04 11:18:17 +01006624static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6625{
6626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6627
6628 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6629 return -EOPNOTSUPP;
6630
6631 if (rdev->ap_beacons_nlpid)
6632 return -EBUSY;
6633
6634 rdev->ap_beacons_nlpid = info->snd_pid;
6635
6636 return 0;
6637}
6638
Johannes Berg4c476992010-10-04 21:36:35 +02006639#define NL80211_FLAG_NEED_WIPHY 0x01
6640#define NL80211_FLAG_NEED_NETDEV 0x02
6641#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006642#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6643#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6644 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006645
6646static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6647 struct genl_info *info)
6648{
6649 struct cfg80211_registered_device *rdev;
6650 struct net_device *dev;
6651 int err;
6652 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6653
6654 if (rtnl)
6655 rtnl_lock();
6656
6657 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006658 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006659 if (IS_ERR(rdev)) {
6660 if (rtnl)
6661 rtnl_unlock();
6662 return PTR_ERR(rdev);
6663 }
6664 info->user_ptr[0] = rdev;
6665 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006666 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6667 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006668 if (err) {
6669 if (rtnl)
6670 rtnl_unlock();
6671 return err;
6672 }
Johannes Berg41265712010-10-04 21:14:05 +02006673 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6674 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006675 cfg80211_unlock_rdev(rdev);
6676 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006677 if (rtnl)
6678 rtnl_unlock();
6679 return -ENETDOWN;
6680 }
Johannes Berg4c476992010-10-04 21:36:35 +02006681 info->user_ptr[0] = rdev;
6682 info->user_ptr[1] = dev;
6683 }
6684
6685 return 0;
6686}
6687
6688static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6689 struct genl_info *info)
6690{
6691 if (info->user_ptr[0])
6692 cfg80211_unlock_rdev(info->user_ptr[0]);
6693 if (info->user_ptr[1])
6694 dev_put(info->user_ptr[1]);
6695 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6696 rtnl_unlock();
6697}
6698
Johannes Berg55682962007-09-20 13:09:35 -04006699static struct genl_ops nl80211_ops[] = {
6700 {
6701 .cmd = NL80211_CMD_GET_WIPHY,
6702 .doit = nl80211_get_wiphy,
6703 .dumpit = nl80211_dump_wiphy,
6704 .policy = nl80211_policy,
6705 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006706 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006707 },
6708 {
6709 .cmd = NL80211_CMD_SET_WIPHY,
6710 .doit = nl80211_set_wiphy,
6711 .policy = nl80211_policy,
6712 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006713 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006714 },
6715 {
6716 .cmd = NL80211_CMD_GET_INTERFACE,
6717 .doit = nl80211_get_interface,
6718 .dumpit = nl80211_dump_interface,
6719 .policy = nl80211_policy,
6720 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006721 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006722 },
6723 {
6724 .cmd = NL80211_CMD_SET_INTERFACE,
6725 .doit = nl80211_set_interface,
6726 .policy = nl80211_policy,
6727 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6729 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006730 },
6731 {
6732 .cmd = NL80211_CMD_NEW_INTERFACE,
6733 .doit = nl80211_new_interface,
6734 .policy = nl80211_policy,
6735 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006736 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6737 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006738 },
6739 {
6740 .cmd = NL80211_CMD_DEL_INTERFACE,
6741 .doit = nl80211_del_interface,
6742 .policy = nl80211_policy,
6743 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006744 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6745 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006746 },
Johannes Berg41ade002007-12-19 02:03:29 +01006747 {
6748 .cmd = NL80211_CMD_GET_KEY,
6749 .doit = nl80211_get_key,
6750 .policy = nl80211_policy,
6751 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006753 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006754 },
6755 {
6756 .cmd = NL80211_CMD_SET_KEY,
6757 .doit = nl80211_set_key,
6758 .policy = nl80211_policy,
6759 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006760 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006761 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006762 },
6763 {
6764 .cmd = NL80211_CMD_NEW_KEY,
6765 .doit = nl80211_new_key,
6766 .policy = nl80211_policy,
6767 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006769 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006770 },
6771 {
6772 .cmd = NL80211_CMD_DEL_KEY,
6773 .doit = nl80211_del_key,
6774 .policy = nl80211_policy,
6775 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006777 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006778 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006779 {
6780 .cmd = NL80211_CMD_SET_BEACON,
6781 .policy = nl80211_policy,
6782 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006783 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006785 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006786 },
6787 {
Johannes Berg88600202012-02-13 15:17:18 +01006788 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006789 .policy = nl80211_policy,
6790 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006791 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006793 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006794 },
6795 {
Johannes Berg88600202012-02-13 15:17:18 +01006796 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006797 .policy = nl80211_policy,
6798 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006799 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006801 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006802 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006803 {
6804 .cmd = NL80211_CMD_GET_STATION,
6805 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006806 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006807 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006808 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6809 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006810 },
6811 {
6812 .cmd = NL80211_CMD_SET_STATION,
6813 .doit = nl80211_set_station,
6814 .policy = nl80211_policy,
6815 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006817 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006818 },
6819 {
6820 .cmd = NL80211_CMD_NEW_STATION,
6821 .doit = nl80211_new_station,
6822 .policy = nl80211_policy,
6823 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006825 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006826 },
6827 {
6828 .cmd = NL80211_CMD_DEL_STATION,
6829 .doit = nl80211_del_station,
6830 .policy = nl80211_policy,
6831 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006832 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006833 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006834 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006835 {
6836 .cmd = NL80211_CMD_GET_MPATH,
6837 .doit = nl80211_get_mpath,
6838 .dumpit = nl80211_dump_mpath,
6839 .policy = nl80211_policy,
6840 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006841 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006842 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006843 },
6844 {
6845 .cmd = NL80211_CMD_SET_MPATH,
6846 .doit = nl80211_set_mpath,
6847 .policy = nl80211_policy,
6848 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006849 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006850 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006851 },
6852 {
6853 .cmd = NL80211_CMD_NEW_MPATH,
6854 .doit = nl80211_new_mpath,
6855 .policy = nl80211_policy,
6856 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006858 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006859 },
6860 {
6861 .cmd = NL80211_CMD_DEL_MPATH,
6862 .doit = nl80211_del_mpath,
6863 .policy = nl80211_policy,
6864 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006866 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006867 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006868 {
6869 .cmd = NL80211_CMD_SET_BSS,
6870 .doit = nl80211_set_bss,
6871 .policy = nl80211_policy,
6872 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006874 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006875 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006876 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006877 .cmd = NL80211_CMD_GET_REG,
6878 .doit = nl80211_get_reg,
6879 .policy = nl80211_policy,
6880 /* can be retrieved by unprivileged users */
6881 },
6882 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006883 .cmd = NL80211_CMD_SET_REG,
6884 .doit = nl80211_set_reg,
6885 .policy = nl80211_policy,
6886 .flags = GENL_ADMIN_PERM,
6887 },
6888 {
6889 .cmd = NL80211_CMD_REQ_SET_REG,
6890 .doit = nl80211_req_set_reg,
6891 .policy = nl80211_policy,
6892 .flags = GENL_ADMIN_PERM,
6893 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006894 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006895 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6896 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006897 .policy = nl80211_policy,
6898 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006900 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006901 },
6902 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006903 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6904 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006905 .policy = nl80211_policy,
6906 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006908 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006909 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006910 {
Johannes Berg2a519312009-02-10 21:25:55 +01006911 .cmd = NL80211_CMD_TRIGGER_SCAN,
6912 .doit = nl80211_trigger_scan,
6913 .policy = nl80211_policy,
6914 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006916 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006917 },
6918 {
6919 .cmd = NL80211_CMD_GET_SCAN,
6920 .policy = nl80211_policy,
6921 .dumpit = nl80211_dump_scan,
6922 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006923 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006924 .cmd = NL80211_CMD_START_SCHED_SCAN,
6925 .doit = nl80211_start_sched_scan,
6926 .policy = nl80211_policy,
6927 .flags = GENL_ADMIN_PERM,
6928 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6929 NL80211_FLAG_NEED_RTNL,
6930 },
6931 {
6932 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6933 .doit = nl80211_stop_sched_scan,
6934 .policy = nl80211_policy,
6935 .flags = GENL_ADMIN_PERM,
6936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6937 NL80211_FLAG_NEED_RTNL,
6938 },
6939 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006940 .cmd = NL80211_CMD_AUTHENTICATE,
6941 .doit = nl80211_authenticate,
6942 .policy = nl80211_policy,
6943 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006945 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006946 },
6947 {
6948 .cmd = NL80211_CMD_ASSOCIATE,
6949 .doit = nl80211_associate,
6950 .policy = nl80211_policy,
6951 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006953 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006954 },
6955 {
6956 .cmd = NL80211_CMD_DEAUTHENTICATE,
6957 .doit = nl80211_deauthenticate,
6958 .policy = nl80211_policy,
6959 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006961 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006962 },
6963 {
6964 .cmd = NL80211_CMD_DISASSOCIATE,
6965 .doit = nl80211_disassociate,
6966 .policy = nl80211_policy,
6967 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006968 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006969 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006970 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006971 {
6972 .cmd = NL80211_CMD_JOIN_IBSS,
6973 .doit = nl80211_join_ibss,
6974 .policy = nl80211_policy,
6975 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006977 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006978 },
6979 {
6980 .cmd = NL80211_CMD_LEAVE_IBSS,
6981 .doit = nl80211_leave_ibss,
6982 .policy = nl80211_policy,
6983 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006985 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006986 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006987#ifdef CONFIG_NL80211_TESTMODE
6988 {
6989 .cmd = NL80211_CMD_TESTMODE,
6990 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006991 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006992 .policy = nl80211_policy,
6993 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006994 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6995 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006996 },
6997#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006998 {
6999 .cmd = NL80211_CMD_CONNECT,
7000 .doit = nl80211_connect,
7001 .policy = nl80211_policy,
7002 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007004 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007005 },
7006 {
7007 .cmd = NL80211_CMD_DISCONNECT,
7008 .doit = nl80211_disconnect,
7009 .policy = nl80211_policy,
7010 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007012 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007013 },
Johannes Berg463d0182009-07-14 00:33:35 +02007014 {
7015 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7016 .doit = nl80211_wiphy_netns,
7017 .policy = nl80211_policy,
7018 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007019 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7020 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007021 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007022 {
7023 .cmd = NL80211_CMD_GET_SURVEY,
7024 .policy = nl80211_policy,
7025 .dumpit = nl80211_dump_survey,
7026 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007027 {
7028 .cmd = NL80211_CMD_SET_PMKSA,
7029 .doit = nl80211_setdel_pmksa,
7030 .policy = nl80211_policy,
7031 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007033 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007034 },
7035 {
7036 .cmd = NL80211_CMD_DEL_PMKSA,
7037 .doit = nl80211_setdel_pmksa,
7038 .policy = nl80211_policy,
7039 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007041 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007042 },
7043 {
7044 .cmd = NL80211_CMD_FLUSH_PMKSA,
7045 .doit = nl80211_flush_pmksa,
7046 .policy = nl80211_policy,
7047 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007049 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007050 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007051 {
7052 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7053 .doit = nl80211_remain_on_channel,
7054 .policy = nl80211_policy,
7055 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007057 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007058 },
7059 {
7060 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7061 .doit = nl80211_cancel_remain_on_channel,
7062 .policy = nl80211_policy,
7063 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007065 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007066 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007067 {
7068 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7069 .doit = nl80211_set_tx_bitrate_mask,
7070 .policy = nl80211_policy,
7071 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007072 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7073 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007074 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007075 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007076 .cmd = NL80211_CMD_REGISTER_FRAME,
7077 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007078 .policy = nl80211_policy,
7079 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007080 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7081 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007082 },
7083 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007084 .cmd = NL80211_CMD_FRAME,
7085 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007086 .policy = nl80211_policy,
7087 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007089 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007090 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007091 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007092 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7093 .doit = nl80211_tx_mgmt_cancel_wait,
7094 .policy = nl80211_policy,
7095 .flags = GENL_ADMIN_PERM,
7096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7097 NL80211_FLAG_NEED_RTNL,
7098 },
7099 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007100 .cmd = NL80211_CMD_SET_POWER_SAVE,
7101 .doit = nl80211_set_power_save,
7102 .policy = nl80211_policy,
7103 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007104 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7105 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007106 },
7107 {
7108 .cmd = NL80211_CMD_GET_POWER_SAVE,
7109 .doit = nl80211_get_power_save,
7110 .policy = nl80211_policy,
7111 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007112 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7113 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007114 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007115 {
7116 .cmd = NL80211_CMD_SET_CQM,
7117 .doit = nl80211_set_cqm,
7118 .policy = nl80211_policy,
7119 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007120 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7121 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007122 },
Johannes Bergf444de02010-05-05 15:25:02 +02007123 {
7124 .cmd = NL80211_CMD_SET_CHANNEL,
7125 .doit = nl80211_set_channel,
7126 .policy = nl80211_policy,
7127 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007128 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7129 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007130 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007131 {
7132 .cmd = NL80211_CMD_SET_WDS_PEER,
7133 .doit = nl80211_set_wds_peer,
7134 .policy = nl80211_policy,
7135 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007136 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7137 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007138 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007139 {
7140 .cmd = NL80211_CMD_JOIN_MESH,
7141 .doit = nl80211_join_mesh,
7142 .policy = nl80211_policy,
7143 .flags = GENL_ADMIN_PERM,
7144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7145 NL80211_FLAG_NEED_RTNL,
7146 },
7147 {
7148 .cmd = NL80211_CMD_LEAVE_MESH,
7149 .doit = nl80211_leave_mesh,
7150 .policy = nl80211_policy,
7151 .flags = GENL_ADMIN_PERM,
7152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7153 NL80211_FLAG_NEED_RTNL,
7154 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007155#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007156 {
7157 .cmd = NL80211_CMD_GET_WOWLAN,
7158 .doit = nl80211_get_wowlan,
7159 .policy = nl80211_policy,
7160 /* can be retrieved by unprivileged users */
7161 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7162 NL80211_FLAG_NEED_RTNL,
7163 },
7164 {
7165 .cmd = NL80211_CMD_SET_WOWLAN,
7166 .doit = nl80211_set_wowlan,
7167 .policy = nl80211_policy,
7168 .flags = GENL_ADMIN_PERM,
7169 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7170 NL80211_FLAG_NEED_RTNL,
7171 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007172#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007173 {
7174 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7175 .doit = nl80211_set_rekey_data,
7176 .policy = nl80211_policy,
7177 .flags = GENL_ADMIN_PERM,
7178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7179 NL80211_FLAG_NEED_RTNL,
7180 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007181 {
7182 .cmd = NL80211_CMD_TDLS_MGMT,
7183 .doit = nl80211_tdls_mgmt,
7184 .policy = nl80211_policy,
7185 .flags = GENL_ADMIN_PERM,
7186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7187 NL80211_FLAG_NEED_RTNL,
7188 },
7189 {
7190 .cmd = NL80211_CMD_TDLS_OPER,
7191 .doit = nl80211_tdls_oper,
7192 .policy = nl80211_policy,
7193 .flags = GENL_ADMIN_PERM,
7194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7195 NL80211_FLAG_NEED_RTNL,
7196 },
Johannes Berg28946da2011-11-04 11:18:12 +01007197 {
7198 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7199 .doit = nl80211_register_unexpected_frame,
7200 .policy = nl80211_policy,
7201 .flags = GENL_ADMIN_PERM,
7202 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7203 NL80211_FLAG_NEED_RTNL,
7204 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007205 {
7206 .cmd = NL80211_CMD_PROBE_CLIENT,
7207 .doit = nl80211_probe_client,
7208 .policy = nl80211_policy,
7209 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007210 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007211 NL80211_FLAG_NEED_RTNL,
7212 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007213 {
7214 .cmd = NL80211_CMD_REGISTER_BEACONS,
7215 .doit = nl80211_register_beacons,
7216 .policy = nl80211_policy,
7217 .flags = GENL_ADMIN_PERM,
7218 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7219 NL80211_FLAG_NEED_RTNL,
7220 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007221 {
7222 .cmd = NL80211_CMD_SET_NOACK_MAP,
7223 .doit = nl80211_set_noack_map,
7224 .policy = nl80211_policy,
7225 .flags = GENL_ADMIN_PERM,
7226 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7227 NL80211_FLAG_NEED_RTNL,
7228 },
7229
Johannes Berg55682962007-09-20 13:09:35 -04007230};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007231
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007232static struct genl_multicast_group nl80211_mlme_mcgrp = {
7233 .name = "mlme",
7234};
Johannes Berg55682962007-09-20 13:09:35 -04007235
7236/* multicast groups */
7237static struct genl_multicast_group nl80211_config_mcgrp = {
7238 .name = "config",
7239};
Johannes Berg2a519312009-02-10 21:25:55 +01007240static struct genl_multicast_group nl80211_scan_mcgrp = {
7241 .name = "scan",
7242};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007243static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7244 .name = "regulatory",
7245};
Johannes Berg55682962007-09-20 13:09:35 -04007246
7247/* notification functions */
7248
7249void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7250{
7251 struct sk_buff *msg;
7252
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007254 if (!msg)
7255 return;
7256
7257 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7258 nlmsg_free(msg);
7259 return;
7260 }
7261
Johannes Berg463d0182009-07-14 00:33:35 +02007262 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7263 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007264}
7265
Johannes Berg362a4152009-05-24 16:43:15 +02007266static int nl80211_add_scan_req(struct sk_buff *msg,
7267 struct cfg80211_registered_device *rdev)
7268{
7269 struct cfg80211_scan_request *req = rdev->scan_req;
7270 struct nlattr *nest;
7271 int i;
7272
Johannes Berg667503dd2009-07-07 03:56:11 +02007273 ASSERT_RDEV_LOCK(rdev);
7274
Johannes Berg362a4152009-05-24 16:43:15 +02007275 if (WARN_ON(!req))
7276 return 0;
7277
7278 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7279 if (!nest)
7280 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007281 for (i = 0; i < req->n_ssids; i++) {
7282 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7283 goto nla_put_failure;
7284 }
Johannes Berg362a4152009-05-24 16:43:15 +02007285 nla_nest_end(msg, nest);
7286
7287 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7288 if (!nest)
7289 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007290 for (i = 0; i < req->n_channels; i++) {
7291 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7292 goto nla_put_failure;
7293 }
Johannes Berg362a4152009-05-24 16:43:15 +02007294 nla_nest_end(msg, nest);
7295
David S. Miller9360ffd2012-03-29 04:41:26 -04007296 if (req->ie &&
7297 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7298 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007299
7300 return 0;
7301 nla_put_failure:
7302 return -ENOBUFS;
7303}
7304
Johannes Berga538e2d2009-06-16 19:56:42 +02007305static int nl80211_send_scan_msg(struct sk_buff *msg,
7306 struct cfg80211_registered_device *rdev,
7307 struct net_device *netdev,
7308 u32 pid, u32 seq, int flags,
7309 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007310{
7311 void *hdr;
7312
7313 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7314 if (!hdr)
7315 return -1;
7316
David S. Miller9360ffd2012-03-29 04:41:26 -04007317 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7318 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7319 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007320
Johannes Berg362a4152009-05-24 16:43:15 +02007321 /* ignore errors and send incomplete event anyway */
7322 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007323
7324 return genlmsg_end(msg, hdr);
7325
7326 nla_put_failure:
7327 genlmsg_cancel(msg, hdr);
7328 return -EMSGSIZE;
7329}
7330
Luciano Coelho807f8a82011-05-11 17:09:35 +03007331static int
7332nl80211_send_sched_scan_msg(struct sk_buff *msg,
7333 struct cfg80211_registered_device *rdev,
7334 struct net_device *netdev,
7335 u32 pid, u32 seq, int flags, u32 cmd)
7336{
7337 void *hdr;
7338
7339 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7340 if (!hdr)
7341 return -1;
7342
David S. Miller9360ffd2012-03-29 04:41:26 -04007343 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7344 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7345 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007346
7347 return genlmsg_end(msg, hdr);
7348
7349 nla_put_failure:
7350 genlmsg_cancel(msg, hdr);
7351 return -EMSGSIZE;
7352}
7353
Johannes Berga538e2d2009-06-16 19:56:42 +02007354void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7355 struct net_device *netdev)
7356{
7357 struct sk_buff *msg;
7358
7359 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7360 if (!msg)
7361 return;
7362
7363 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7364 NL80211_CMD_TRIGGER_SCAN) < 0) {
7365 nlmsg_free(msg);
7366 return;
7367 }
7368
Johannes Berg463d0182009-07-14 00:33:35 +02007369 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7370 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007371}
7372
Johannes Berg2a519312009-02-10 21:25:55 +01007373void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7374 struct net_device *netdev)
7375{
7376 struct sk_buff *msg;
7377
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007378 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007379 if (!msg)
7380 return;
7381
Johannes Berga538e2d2009-06-16 19:56:42 +02007382 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7383 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007384 nlmsg_free(msg);
7385 return;
7386 }
7387
Johannes Berg463d0182009-07-14 00:33:35 +02007388 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7389 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007390}
7391
7392void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7393 struct net_device *netdev)
7394{
7395 struct sk_buff *msg;
7396
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007397 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007398 if (!msg)
7399 return;
7400
Johannes Berga538e2d2009-06-16 19:56:42 +02007401 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7402 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007403 nlmsg_free(msg);
7404 return;
7405 }
7406
Johannes Berg463d0182009-07-14 00:33:35 +02007407 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7408 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007409}
7410
Luciano Coelho807f8a82011-05-11 17:09:35 +03007411void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7412 struct net_device *netdev)
7413{
7414 struct sk_buff *msg;
7415
7416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7417 if (!msg)
7418 return;
7419
7420 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7421 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7422 nlmsg_free(msg);
7423 return;
7424 }
7425
7426 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7427 nl80211_scan_mcgrp.id, GFP_KERNEL);
7428}
7429
7430void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7431 struct net_device *netdev, u32 cmd)
7432{
7433 struct sk_buff *msg;
7434
7435 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7436 if (!msg)
7437 return;
7438
7439 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7440 nlmsg_free(msg);
7441 return;
7442 }
7443
7444 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7445 nl80211_scan_mcgrp.id, GFP_KERNEL);
7446}
7447
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007448/*
7449 * This can happen on global regulatory changes or device specific settings
7450 * based on custom world regulatory domains.
7451 */
7452void nl80211_send_reg_change_event(struct regulatory_request *request)
7453{
7454 struct sk_buff *msg;
7455 void *hdr;
7456
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007458 if (!msg)
7459 return;
7460
7461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7462 if (!hdr) {
7463 nlmsg_free(msg);
7464 return;
7465 }
7466
7467 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007468 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7469 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007470
David S. Miller9360ffd2012-03-29 04:41:26 -04007471 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7472 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7473 NL80211_REGDOM_TYPE_WORLD))
7474 goto nla_put_failure;
7475 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7476 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7477 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7478 goto nla_put_failure;
7479 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7480 request->intersect) {
7481 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7482 NL80211_REGDOM_TYPE_INTERSECTION))
7483 goto nla_put_failure;
7484 } else {
7485 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7486 NL80211_REGDOM_TYPE_COUNTRY) ||
7487 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7488 request->alpha2))
7489 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007490 }
7491
David S. Miller9360ffd2012-03-29 04:41:26 -04007492 if (wiphy_idx_valid(request->wiphy_idx) &&
7493 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7494 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007495
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007496 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007497
Johannes Bergbc43b282009-07-25 10:54:13 +02007498 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007499 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007500 GFP_ATOMIC);
7501 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007502
7503 return;
7504
7505nla_put_failure:
7506 genlmsg_cancel(msg, hdr);
7507 nlmsg_free(msg);
7508}
7509
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007510static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7511 struct net_device *netdev,
7512 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007513 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007514{
7515 struct sk_buff *msg;
7516 void *hdr;
7517
Johannes Berge6d6e342009-07-01 21:26:47 +02007518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007519 if (!msg)
7520 return;
7521
7522 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7523 if (!hdr) {
7524 nlmsg_free(msg);
7525 return;
7526 }
7527
David S. Miller9360ffd2012-03-29 04:41:26 -04007528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7530 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7531 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007532
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007533 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007534
Johannes Berg463d0182009-07-14 00:33:35 +02007535 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7536 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007537 return;
7538
7539 nla_put_failure:
7540 genlmsg_cancel(msg, hdr);
7541 nlmsg_free(msg);
7542}
7543
7544void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007545 struct net_device *netdev, const u8 *buf,
7546 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007547{
7548 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007549 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007550}
7551
7552void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7553 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007554 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007555{
Johannes Berge6d6e342009-07-01 21:26:47 +02007556 nl80211_send_mlme_event(rdev, netdev, buf, len,
7557 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007558}
7559
Jouni Malinen53b46b82009-03-27 20:53:56 +02007560void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007561 struct net_device *netdev, const u8 *buf,
7562 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007563{
7564 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007565 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007566}
7567
Jouni Malinen53b46b82009-03-27 20:53:56 +02007568void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7569 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007570 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007571{
7572 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007573 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007574}
7575
Jouni Malinencf4e5942010-12-16 00:52:40 +02007576void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7577 struct net_device *netdev, const u8 *buf,
7578 size_t len, gfp_t gfp)
7579{
7580 nl80211_send_mlme_event(rdev, netdev, buf, len,
7581 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7582}
7583
7584void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7585 struct net_device *netdev, const u8 *buf,
7586 size_t len, gfp_t gfp)
7587{
7588 nl80211_send_mlme_event(rdev, netdev, buf, len,
7589 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7590}
7591
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007592static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7593 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007594 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007595{
7596 struct sk_buff *msg;
7597 void *hdr;
7598
Johannes Berge6d6e342009-07-01 21:26:47 +02007599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007600 if (!msg)
7601 return;
7602
7603 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7604 if (!hdr) {
7605 nlmsg_free(msg);
7606 return;
7607 }
7608
David S. Miller9360ffd2012-03-29 04:41:26 -04007609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7610 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7611 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7612 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7613 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007614
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007615 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007616
Johannes Berg463d0182009-07-14 00:33:35 +02007617 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7618 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007619 return;
7620
7621 nla_put_failure:
7622 genlmsg_cancel(msg, hdr);
7623 nlmsg_free(msg);
7624}
7625
7626void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007627 struct net_device *netdev, const u8 *addr,
7628 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007629{
7630 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007631 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007632}
7633
7634void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007635 struct net_device *netdev, const u8 *addr,
7636 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007637{
Johannes Berge6d6e342009-07-01 21:26:47 +02007638 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7639 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007640}
7641
Samuel Ortizb23aa672009-07-01 21:26:54 +02007642void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7643 struct net_device *netdev, const u8 *bssid,
7644 const u8 *req_ie, size_t req_ie_len,
7645 const u8 *resp_ie, size_t resp_ie_len,
7646 u16 status, gfp_t gfp)
7647{
7648 struct sk_buff *msg;
7649 void *hdr;
7650
7651 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7652 if (!msg)
7653 return;
7654
7655 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7656 if (!hdr) {
7657 nlmsg_free(msg);
7658 return;
7659 }
7660
David S. Miller9360ffd2012-03-29 04:41:26 -04007661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7662 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7663 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7664 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7665 (req_ie &&
7666 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7667 (resp_ie &&
7668 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7669 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007670
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007671 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007672
Johannes Berg463d0182009-07-14 00:33:35 +02007673 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7674 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007675 return;
7676
7677 nla_put_failure:
7678 genlmsg_cancel(msg, hdr);
7679 nlmsg_free(msg);
7680
7681}
7682
7683void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7684 struct net_device *netdev, const u8 *bssid,
7685 const u8 *req_ie, size_t req_ie_len,
7686 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7687{
7688 struct sk_buff *msg;
7689 void *hdr;
7690
7691 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7692 if (!msg)
7693 return;
7694
7695 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7696 if (!hdr) {
7697 nlmsg_free(msg);
7698 return;
7699 }
7700
David S. Miller9360ffd2012-03-29 04:41:26 -04007701 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7702 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7703 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7704 (req_ie &&
7705 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7706 (resp_ie &&
7707 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7708 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007709
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007710 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007711
Johannes Berg463d0182009-07-14 00:33:35 +02007712 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7713 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007714 return;
7715
7716 nla_put_failure:
7717 genlmsg_cancel(msg, hdr);
7718 nlmsg_free(msg);
7719
7720}
7721
7722void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7723 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007724 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007725{
7726 struct sk_buff *msg;
7727 void *hdr;
7728
Johannes Berg667503dd2009-07-07 03:56:11 +02007729 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007730 if (!msg)
7731 return;
7732
7733 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7734 if (!hdr) {
7735 nlmsg_free(msg);
7736 return;
7737 }
7738
David S. Miller9360ffd2012-03-29 04:41:26 -04007739 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7740 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7741 (from_ap && reason &&
7742 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7743 (from_ap &&
7744 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7745 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7746 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007747
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007748 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007749
Johannes Berg463d0182009-07-14 00:33:35 +02007750 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7751 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007752 return;
7753
7754 nla_put_failure:
7755 genlmsg_cancel(msg, hdr);
7756 nlmsg_free(msg);
7757
7758}
7759
Johannes Berg04a773a2009-04-19 21:24:32 +02007760void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7761 struct net_device *netdev, const u8 *bssid,
7762 gfp_t gfp)
7763{
7764 struct sk_buff *msg;
7765 void *hdr;
7766
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007768 if (!msg)
7769 return;
7770
7771 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7772 if (!hdr) {
7773 nlmsg_free(msg);
7774 return;
7775 }
7776
David S. Miller9360ffd2012-03-29 04:41:26 -04007777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7778 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7779 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7780 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007781
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007782 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007783
Johannes Berg463d0182009-07-14 00:33:35 +02007784 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7785 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007786 return;
7787
7788 nla_put_failure:
7789 genlmsg_cancel(msg, hdr);
7790 nlmsg_free(msg);
7791}
7792
Javier Cardonac93b5e72011-04-07 15:08:34 -07007793void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7794 struct net_device *netdev,
7795 const u8 *macaddr, const u8* ie, u8 ie_len,
7796 gfp_t gfp)
7797{
7798 struct sk_buff *msg;
7799 void *hdr;
7800
7801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7802 if (!msg)
7803 return;
7804
7805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7806 if (!hdr) {
7807 nlmsg_free(msg);
7808 return;
7809 }
7810
David S. Miller9360ffd2012-03-29 04:41:26 -04007811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7813 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7814 (ie_len && ie &&
7815 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7816 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007817
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007818 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007819
7820 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7821 nl80211_mlme_mcgrp.id, gfp);
7822 return;
7823
7824 nla_put_failure:
7825 genlmsg_cancel(msg, hdr);
7826 nlmsg_free(msg);
7827}
7828
Jouni Malinena3b8b052009-03-27 21:59:49 +02007829void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7830 struct net_device *netdev, const u8 *addr,
7831 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007832 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007833{
7834 struct sk_buff *msg;
7835 void *hdr;
7836
Johannes Berge6d6e342009-07-01 21:26:47 +02007837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007838 if (!msg)
7839 return;
7840
7841 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7842 if (!hdr) {
7843 nlmsg_free(msg);
7844 return;
7845 }
7846
David S. Miller9360ffd2012-03-29 04:41:26 -04007847 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7848 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7849 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7850 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7851 (key_id != -1 &&
7852 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7853 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7854 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007855
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007856 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007857
Johannes Berg463d0182009-07-14 00:33:35 +02007858 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7859 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007860 return;
7861
7862 nla_put_failure:
7863 genlmsg_cancel(msg, hdr);
7864 nlmsg_free(msg);
7865}
7866
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007867void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7868 struct ieee80211_channel *channel_before,
7869 struct ieee80211_channel *channel_after)
7870{
7871 struct sk_buff *msg;
7872 void *hdr;
7873 struct nlattr *nl_freq;
7874
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007876 if (!msg)
7877 return;
7878
7879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7880 if (!hdr) {
7881 nlmsg_free(msg);
7882 return;
7883 }
7884
7885 /*
7886 * Since we are applying the beacon hint to a wiphy we know its
7887 * wiphy_idx is valid
7888 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007889 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7890 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007891
7892 /* Before */
7893 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7894 if (!nl_freq)
7895 goto nla_put_failure;
7896 if (nl80211_msg_put_channel(msg, channel_before))
7897 goto nla_put_failure;
7898 nla_nest_end(msg, nl_freq);
7899
7900 /* After */
7901 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7902 if (!nl_freq)
7903 goto nla_put_failure;
7904 if (nl80211_msg_put_channel(msg, channel_after))
7905 goto nla_put_failure;
7906 nla_nest_end(msg, nl_freq);
7907
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007908 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007909
Johannes Berg463d0182009-07-14 00:33:35 +02007910 rcu_read_lock();
7911 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7912 GFP_ATOMIC);
7913 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007914
7915 return;
7916
7917nla_put_failure:
7918 genlmsg_cancel(msg, hdr);
7919 nlmsg_free(msg);
7920}
7921
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007922static void nl80211_send_remain_on_chan_event(
7923 int cmd, struct cfg80211_registered_device *rdev,
7924 struct net_device *netdev, u64 cookie,
7925 struct ieee80211_channel *chan,
7926 enum nl80211_channel_type channel_type,
7927 unsigned int duration, gfp_t gfp)
7928{
7929 struct sk_buff *msg;
7930 void *hdr;
7931
7932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7933 if (!msg)
7934 return;
7935
7936 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7937 if (!hdr) {
7938 nlmsg_free(msg);
7939 return;
7940 }
7941
David S. Miller9360ffd2012-03-29 04:41:26 -04007942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7944 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7945 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7946 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7947 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007948
David S. Miller9360ffd2012-03-29 04:41:26 -04007949 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7950 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7951 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007952
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007953 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007954
7955 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7956 nl80211_mlme_mcgrp.id, gfp);
7957 return;
7958
7959 nla_put_failure:
7960 genlmsg_cancel(msg, hdr);
7961 nlmsg_free(msg);
7962}
7963
7964void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7965 struct net_device *netdev, u64 cookie,
7966 struct ieee80211_channel *chan,
7967 enum nl80211_channel_type channel_type,
7968 unsigned int duration, gfp_t gfp)
7969{
7970 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7971 rdev, netdev, cookie, chan,
7972 channel_type, duration, gfp);
7973}
7974
7975void nl80211_send_remain_on_channel_cancel(
7976 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7977 u64 cookie, struct ieee80211_channel *chan,
7978 enum nl80211_channel_type channel_type, gfp_t gfp)
7979{
7980 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7981 rdev, netdev, cookie, chan,
7982 channel_type, 0, gfp);
7983}
7984
Johannes Berg98b62182009-12-23 13:15:44 +01007985void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7986 struct net_device *dev, const u8 *mac_addr,
7987 struct station_info *sinfo, gfp_t gfp)
7988{
7989 struct sk_buff *msg;
7990
7991 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7992 if (!msg)
7993 return;
7994
John W. Linville66266b32012-03-15 13:25:41 -04007995 if (nl80211_send_station(msg, 0, 0, 0,
7996 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007997 nlmsg_free(msg);
7998 return;
7999 }
8000
8001 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8002 nl80211_mlme_mcgrp.id, gfp);
8003}
8004
Jouni Malinenec15e682011-03-23 15:29:52 +02008005void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8006 struct net_device *dev, const u8 *mac_addr,
8007 gfp_t gfp)
8008{
8009 struct sk_buff *msg;
8010 void *hdr;
8011
8012 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8013 if (!msg)
8014 return;
8015
8016 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8017 if (!hdr) {
8018 nlmsg_free(msg);
8019 return;
8020 }
8021
David S. Miller9360ffd2012-03-29 04:41:26 -04008022 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8023 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8024 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008025
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008026 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008027
8028 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8029 nl80211_mlme_mcgrp.id, gfp);
8030 return;
8031
8032 nla_put_failure:
8033 genlmsg_cancel(msg, hdr);
8034 nlmsg_free(msg);
8035}
8036
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008037static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8038 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008039{
8040 struct wireless_dev *wdev = dev->ieee80211_ptr;
8041 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8042 struct sk_buff *msg;
8043 void *hdr;
8044 int err;
8045 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8046
8047 if (!nlpid)
8048 return false;
8049
8050 msg = nlmsg_new(100, gfp);
8051 if (!msg)
8052 return true;
8053
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008054 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008055 if (!hdr) {
8056 nlmsg_free(msg);
8057 return true;
8058 }
8059
David S. Miller9360ffd2012-03-29 04:41:26 -04008060 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8061 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8062 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8063 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008064
8065 err = genlmsg_end(msg, hdr);
8066 if (err < 0) {
8067 nlmsg_free(msg);
8068 return true;
8069 }
8070
8071 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8072 return true;
8073
8074 nla_put_failure:
8075 genlmsg_cancel(msg, hdr);
8076 nlmsg_free(msg);
8077 return true;
8078}
8079
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008080bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8081{
8082 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8083 addr, gfp);
8084}
8085
8086bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8087 const u8 *addr, gfp_t gfp)
8088{
8089 return __nl80211_unexpected_frame(dev,
8090 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8091 addr, gfp);
8092}
8093
Johannes Berg2e161f72010-08-12 15:38:38 +02008094int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8095 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008096 int freq, int sig_dbm,
8097 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008098{
8099 struct sk_buff *msg;
8100 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008101
8102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8103 if (!msg)
8104 return -ENOMEM;
8105
Johannes Berg2e161f72010-08-12 15:38:38 +02008106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008107 if (!hdr) {
8108 nlmsg_free(msg);
8109 return -ENOMEM;
8110 }
8111
David S. Miller9360ffd2012-03-29 04:41:26 -04008112 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8113 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8114 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8115 (sig_dbm &&
8116 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8117 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8118 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008119
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008120 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008121
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008122 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008123
8124 nla_put_failure:
8125 genlmsg_cancel(msg, hdr);
8126 nlmsg_free(msg);
8127 return -ENOBUFS;
8128}
8129
Johannes Berg2e161f72010-08-12 15:38:38 +02008130void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8131 struct net_device *netdev, u64 cookie,
8132 const u8 *buf, size_t len, bool ack,
8133 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008134{
8135 struct sk_buff *msg;
8136 void *hdr;
8137
8138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8139 if (!msg)
8140 return;
8141
Johannes Berg2e161f72010-08-12 15:38:38 +02008142 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008143 if (!hdr) {
8144 nlmsg_free(msg);
8145 return;
8146 }
8147
David S. Miller9360ffd2012-03-29 04:41:26 -04008148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8150 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8151 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8152 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8153 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008154
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008155 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008156
8157 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8158 return;
8159
8160 nla_put_failure:
8161 genlmsg_cancel(msg, hdr);
8162 nlmsg_free(msg);
8163}
8164
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008165void
8166nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8167 struct net_device *netdev,
8168 enum nl80211_cqm_rssi_threshold_event rssi_event,
8169 gfp_t gfp)
8170{
8171 struct sk_buff *msg;
8172 struct nlattr *pinfoattr;
8173 void *hdr;
8174
8175 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8176 if (!msg)
8177 return;
8178
8179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8180 if (!hdr) {
8181 nlmsg_free(msg);
8182 return;
8183 }
8184
David S. Miller9360ffd2012-03-29 04:41:26 -04008185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8187 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008188
8189 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8190 if (!pinfoattr)
8191 goto nla_put_failure;
8192
David S. Miller9360ffd2012-03-29 04:41:26 -04008193 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8194 rssi_event))
8195 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008196
8197 nla_nest_end(msg, pinfoattr);
8198
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008199 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008200
8201 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8202 nl80211_mlme_mcgrp.id, gfp);
8203 return;
8204
8205 nla_put_failure:
8206 genlmsg_cancel(msg, hdr);
8207 nlmsg_free(msg);
8208}
8209
Johannes Berge5497d72011-07-05 16:35:40 +02008210void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8211 struct net_device *netdev, const u8 *bssid,
8212 const u8 *replay_ctr, gfp_t gfp)
8213{
8214 struct sk_buff *msg;
8215 struct nlattr *rekey_attr;
8216 void *hdr;
8217
8218 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8219 if (!msg)
8220 return;
8221
8222 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8223 if (!hdr) {
8224 nlmsg_free(msg);
8225 return;
8226 }
8227
David S. Miller9360ffd2012-03-29 04:41:26 -04008228 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8229 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8230 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8231 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008232
8233 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8234 if (!rekey_attr)
8235 goto nla_put_failure;
8236
David S. Miller9360ffd2012-03-29 04:41:26 -04008237 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8238 NL80211_REPLAY_CTR_LEN, replay_ctr))
8239 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008240
8241 nla_nest_end(msg, rekey_attr);
8242
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008243 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008244
8245 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8246 nl80211_mlme_mcgrp.id, gfp);
8247 return;
8248
8249 nla_put_failure:
8250 genlmsg_cancel(msg, hdr);
8251 nlmsg_free(msg);
8252}
8253
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008254void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8255 struct net_device *netdev, int index,
8256 const u8 *bssid, bool preauth, gfp_t gfp)
8257{
8258 struct sk_buff *msg;
8259 struct nlattr *attr;
8260 void *hdr;
8261
8262 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8263 if (!msg)
8264 return;
8265
8266 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8267 if (!hdr) {
8268 nlmsg_free(msg);
8269 return;
8270 }
8271
David S. Miller9360ffd2012-03-29 04:41:26 -04008272 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8273 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8274 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008275
8276 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8277 if (!attr)
8278 goto nla_put_failure;
8279
David S. Miller9360ffd2012-03-29 04:41:26 -04008280 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8281 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8282 (preauth &&
8283 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8284 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008285
8286 nla_nest_end(msg, attr);
8287
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008288 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008289
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
Thomas Pedersen53145262012-04-06 13:35:47 -07008299void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8300 struct net_device *netdev, int freq,
8301 enum nl80211_channel_type type, gfp_t gfp)
8302{
8303 struct sk_buff *msg;
8304 void *hdr;
8305
8306 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8307 if (!msg)
8308 return;
8309
8310 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8311 if (!hdr) {
8312 nlmsg_free(msg);
8313 return;
8314 }
8315
John W. Linville7eab0f62012-04-12 14:25:14 -04008316 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8317 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8318 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8319 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008320
8321 genlmsg_end(msg, hdr);
8322
8323 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8324 nl80211_mlme_mcgrp.id, gfp);
8325 return;
8326
8327 nla_put_failure:
8328 genlmsg_cancel(msg, hdr);
8329 nlmsg_free(msg);
8330}
8331
Johannes Bergc063dbf2010-11-24 08:10:05 +01008332void
8333nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8334 struct net_device *netdev, const u8 *peer,
8335 u32 num_packets, gfp_t gfp)
8336{
8337 struct sk_buff *msg;
8338 struct nlattr *pinfoattr;
8339 void *hdr;
8340
8341 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8342 if (!msg)
8343 return;
8344
8345 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8346 if (!hdr) {
8347 nlmsg_free(msg);
8348 return;
8349 }
8350
David S. Miller9360ffd2012-03-29 04:41:26 -04008351 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8352 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8353 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8354 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008355
8356 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8357 if (!pinfoattr)
8358 goto nla_put_failure;
8359
David S. Miller9360ffd2012-03-29 04:41:26 -04008360 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8361 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008362
8363 nla_nest_end(msg, pinfoattr);
8364
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008365 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008366
8367 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8368 nl80211_mlme_mcgrp.id, gfp);
8369 return;
8370
8371 nla_put_failure:
8372 genlmsg_cancel(msg, hdr);
8373 nlmsg_free(msg);
8374}
8375
Johannes Berg7f6cf312011-11-04 11:18:15 +01008376void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8377 u64 cookie, bool acked, gfp_t gfp)
8378{
8379 struct wireless_dev *wdev = dev->ieee80211_ptr;
8380 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8381 struct sk_buff *msg;
8382 void *hdr;
8383 int err;
8384
8385 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8386 if (!msg)
8387 return;
8388
8389 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8390 if (!hdr) {
8391 nlmsg_free(msg);
8392 return;
8393 }
8394
David S. Miller9360ffd2012-03-29 04:41:26 -04008395 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8396 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8397 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8398 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8399 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8400 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008401
8402 err = genlmsg_end(msg, hdr);
8403 if (err < 0) {
8404 nlmsg_free(msg);
8405 return;
8406 }
8407
8408 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8409 nl80211_mlme_mcgrp.id, gfp);
8410 return;
8411
8412 nla_put_failure:
8413 genlmsg_cancel(msg, hdr);
8414 nlmsg_free(msg);
8415}
8416EXPORT_SYMBOL(cfg80211_probe_status);
8417
Johannes Berg5e7602302011-11-04 11:18:17 +01008418void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8419 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008420 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008421{
8422 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8423 struct sk_buff *msg;
8424 void *hdr;
8425 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8426
8427 if (!nlpid)
8428 return;
8429
8430 msg = nlmsg_new(len + 100, gfp);
8431 if (!msg)
8432 return;
8433
8434 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8435 if (!hdr) {
8436 nlmsg_free(msg);
8437 return;
8438 }
8439
David S. Miller9360ffd2012-03-29 04:41:26 -04008440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8441 (freq &&
8442 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8443 (sig_dbm &&
8444 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8445 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8446 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008447
8448 genlmsg_end(msg, hdr);
8449
8450 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8451 return;
8452
8453 nla_put_failure:
8454 genlmsg_cancel(msg, hdr);
8455 nlmsg_free(msg);
8456}
8457EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8458
Jouni Malinen026331c2010-02-15 12:53:10 +02008459static int nl80211_netlink_notify(struct notifier_block * nb,
8460 unsigned long state,
8461 void *_notify)
8462{
8463 struct netlink_notify *notify = _notify;
8464 struct cfg80211_registered_device *rdev;
8465 struct wireless_dev *wdev;
8466
8467 if (state != NETLINK_URELEASE)
8468 return NOTIFY_DONE;
8469
8470 rcu_read_lock();
8471
Johannes Berg5e7602302011-11-04 11:18:17 +01008472 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008473 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008474 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008475 if (rdev->ap_beacons_nlpid == notify->pid)
8476 rdev->ap_beacons_nlpid = 0;
8477 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008478
8479 rcu_read_unlock();
8480
8481 return NOTIFY_DONE;
8482}
8483
8484static struct notifier_block nl80211_netlink_notifier = {
8485 .notifier_call = nl80211_netlink_notify,
8486};
8487
Johannes Berg55682962007-09-20 13:09:35 -04008488/* initialisation/exit functions */
8489
8490int nl80211_init(void)
8491{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008492 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008493
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008494 err = genl_register_family_with_ops(&nl80211_fam,
8495 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008496 if (err)
8497 return err;
8498
Johannes Berg55682962007-09-20 13:09:35 -04008499 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8500 if (err)
8501 goto err_out;
8502
Johannes Berg2a519312009-02-10 21:25:55 +01008503 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8504 if (err)
8505 goto err_out;
8506
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008507 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8508 if (err)
8509 goto err_out;
8510
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008511 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8512 if (err)
8513 goto err_out;
8514
Johannes Bergaff89a92009-07-01 21:26:51 +02008515#ifdef CONFIG_NL80211_TESTMODE
8516 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8517 if (err)
8518 goto err_out;
8519#endif
8520
Jouni Malinen026331c2010-02-15 12:53:10 +02008521 err = netlink_register_notifier(&nl80211_netlink_notifier);
8522 if (err)
8523 goto err_out;
8524
Johannes Berg55682962007-09-20 13:09:35 -04008525 return 0;
8526 err_out:
8527 genl_unregister_family(&nl80211_fam);
8528 return err;
8529}
8530
8531void nl80211_exit(void)
8532{
Jouni Malinen026331c2010-02-15 12:53:10 +02008533 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008534 genl_unregister_family(&nl80211_fam);
8535}