blob: af232912fff814ab4b686982c414344d9cc4742c [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 Berg4f7eff12012-06-15 14:14:22 +020074__cfg80211_rdev_from_info(struct net *netns, struct genl_info *info)
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 Berg7fee4772012-06-15 14:09:58 +020081 if (!info->attrs[NL80211_ATTR_WIPHY] &&
82 !info->attrs[NL80211_ATTR_IFINDEX])
83 return ERR_PTR(-EINVAL);
84
85 if (info->attrs[NL80211_ATTR_WIPHY])
86 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berga9455402012-06-15 13:32:49 +020087 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +020088
89 if (info->attrs[NL80211_ATTR_IFINDEX]) {
Johannes Berg7fee4772012-06-15 14:09:58 +020090 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
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 Berg4f7eff12012-06-15 14:14:22 +0200148 rdev = __cfg80211_rdev_from_info(netns, info);
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 Malinen36aedc92008-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 Berg77dbbb132011-07-13 10:48:55 +0200325 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
326 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
327 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
328 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200329};
330
Johannes Berge5497d72011-07-05 16:35:40 +0200331/* policy for GTK rekey offload attributes */
332static const struct nla_policy
333nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
334 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
335 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
336 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
337};
338
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339static const struct nla_policy
340nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200341 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300342 .len = IEEE80211_MAX_SSID_LEN },
343};
344
Holger Schuriga0438972009-11-11 11:30:02 +0100345/* ifidx get helper */
346static int nl80211_get_ifidx(struct netlink_callback *cb)
347{
348 int res;
349
350 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
351 nl80211_fam.attrbuf, nl80211_fam.maxattr,
352 nl80211_policy);
353 if (res)
354 return res;
355
356 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
357 return -EINVAL;
358
359 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
360 if (!res)
361 return -EINVAL;
362 return res;
363}
364
Johannes Berg67748892010-10-04 21:14:06 +0200365static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
366 struct netlink_callback *cb,
367 struct cfg80211_registered_device **rdev,
368 struct net_device **dev)
369{
370 int ifidx = cb->args[0];
371 int err;
372
373 if (!ifidx)
374 ifidx = nl80211_get_ifidx(cb);
375 if (ifidx < 0)
376 return ifidx;
377
378 cb->args[0] = ifidx;
379
380 rtnl_lock();
381
382 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
383 if (!*dev) {
384 err = -ENODEV;
385 goto out_rtnl;
386 }
387
388 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100389 if (IS_ERR(*rdev)) {
390 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200391 goto out_rtnl;
392 }
393
394 return 0;
395 out_rtnl:
396 rtnl_unlock();
397 return err;
398}
399
400static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
401{
402 cfg80211_unlock_rdev(rdev);
403 rtnl_unlock();
404}
405
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100406/* IE validation */
407static bool is_valid_ie_attr(const struct nlattr *attr)
408{
409 const u8 *pos;
410 int len;
411
412 if (!attr)
413 return true;
414
415 pos = nla_data(attr);
416 len = nla_len(attr);
417
418 while (len) {
419 u8 elemlen;
420
421 if (len < 2)
422 return false;
423 len -= 2;
424
425 elemlen = pos[1];
426 if (elemlen > len)
427 return false;
428
429 len -= elemlen;
430 pos += 2 + elemlen;
431 }
432
433 return true;
434}
435
Johannes Berg55682962007-09-20 13:09:35 -0400436/* message building helper */
437static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
438 int flags, u8 cmd)
439{
440 /* since there is no private header just add the generic one */
441 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
442}
443
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400444static int nl80211_msg_put_channel(struct sk_buff *msg,
445 struct ieee80211_channel *chan)
446{
David S. Miller9360ffd2012-03-29 04:41:26 -0400447 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
448 chan->center_freq))
449 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400450
David S. Miller9360ffd2012-03-29 04:41:26 -0400451 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
452 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
453 goto nla_put_failure;
454 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
455 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
456 goto nla_put_failure;
457 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
458 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
459 goto nla_put_failure;
460 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
461 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
462 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400463
David S. Miller9360ffd2012-03-29 04:41:26 -0400464 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
465 DBM_TO_MBM(chan->max_power)))
466 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400467
468 return 0;
469
470 nla_put_failure:
471 return -ENOBUFS;
472}
473
Johannes Berg55682962007-09-20 13:09:35 -0400474/* netlink command implementations */
475
Johannes Bergb9454e82009-07-08 13:29:08 +0200476struct key_parse {
477 struct key_params p;
478 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200479 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200480 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100481 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200482};
483
484static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
485{
486 struct nlattr *tb[NL80211_KEY_MAX + 1];
487 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
488 nl80211_key_policy);
489 if (err)
490 return err;
491
492 k->def = !!tb[NL80211_KEY_DEFAULT];
493 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
494
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100495 if (k->def) {
496 k->def_uni = true;
497 k->def_multi = true;
498 }
499 if (k->defmgmt)
500 k->def_multi = true;
501
Johannes Bergb9454e82009-07-08 13:29:08 +0200502 if (tb[NL80211_KEY_IDX])
503 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
504
505 if (tb[NL80211_KEY_DATA]) {
506 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
507 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
508 }
509
510 if (tb[NL80211_KEY_SEQ]) {
511 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
512 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
513 }
514
515 if (tb[NL80211_KEY_CIPHER])
516 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
517
Johannes Berge31b8212010-10-05 19:39:30 +0200518 if (tb[NL80211_KEY_TYPE]) {
519 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
520 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
521 return -EINVAL;
522 }
523
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100524 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
525 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100526 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
527 tb[NL80211_KEY_DEFAULT_TYPES],
528 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100529 if (err)
530 return err;
531
532 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
533 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
534 }
535
Johannes Bergb9454e82009-07-08 13:29:08 +0200536 return 0;
537}
538
539static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
540{
541 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
542 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
543 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
544 }
545
546 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
547 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
548 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 }
550
551 if (info->attrs[NL80211_ATTR_KEY_IDX])
552 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
553
554 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
555 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
556
557 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
558 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
559
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100560 if (k->def) {
561 k->def_uni = true;
562 k->def_multi = true;
563 }
564 if (k->defmgmt)
565 k->def_multi = true;
566
Johannes Berge31b8212010-10-05 19:39:30 +0200567 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
568 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
569 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
570 return -EINVAL;
571 }
572
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100573 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
574 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
575 int err = nla_parse_nested(
576 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
577 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
578 nl80211_key_default_policy);
579 if (err)
580 return err;
581
582 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
583 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
584 }
585
Johannes Bergb9454e82009-07-08 13:29:08 +0200586 return 0;
587}
588
589static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
590{
591 int err;
592
593 memset(k, 0, sizeof(*k));
594 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200595 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200596
597 if (info->attrs[NL80211_ATTR_KEY])
598 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
599 else
600 err = nl80211_parse_key_old(info, k);
601
602 if (err)
603 return err;
604
605 if (k->def && k->defmgmt)
606 return -EINVAL;
607
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100608 if (k->defmgmt) {
609 if (k->def_uni || !k->def_multi)
610 return -EINVAL;
611 }
612
Johannes Bergb9454e82009-07-08 13:29:08 +0200613 if (k->idx != -1) {
614 if (k->defmgmt) {
615 if (k->idx < 4 || k->idx > 5)
616 return -EINVAL;
617 } else if (k->def) {
618 if (k->idx < 0 || k->idx > 3)
619 return -EINVAL;
620 } else {
621 if (k->idx < 0 || k->idx > 5)
622 return -EINVAL;
623 }
624 }
625
626 return 0;
627}
628
Johannes Bergfffd0932009-07-08 14:22:54 +0200629static struct cfg80211_cached_keys *
630nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
631 struct nlattr *keys)
632{
633 struct key_parse parse;
634 struct nlattr *key;
635 struct cfg80211_cached_keys *result;
636 int rem, err, def = 0;
637
638 result = kzalloc(sizeof(*result), GFP_KERNEL);
639 if (!result)
640 return ERR_PTR(-ENOMEM);
641
642 result->def = -1;
643 result->defmgmt = -1;
644
645 nla_for_each_nested(key, keys, rem) {
646 memset(&parse, 0, sizeof(parse));
647 parse.idx = -1;
648
649 err = nl80211_parse_key_new(key, &parse);
650 if (err)
651 goto error;
652 err = -EINVAL;
653 if (!parse.p.key)
654 goto error;
655 if (parse.idx < 0 || parse.idx > 4)
656 goto error;
657 if (parse.def) {
658 if (def)
659 goto error;
660 def = 1;
661 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100662 if (!parse.def_uni || !parse.def_multi)
663 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200664 } else if (parse.defmgmt)
665 goto error;
666 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200667 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200668 if (err)
669 goto error;
670 result->params[parse.idx].cipher = parse.p.cipher;
671 result->params[parse.idx].key_len = parse.p.key_len;
672 result->params[parse.idx].key = result->data[parse.idx];
673 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
674 }
675
676 return result;
677 error:
678 kfree(result);
679 return ERR_PTR(err);
680}
681
682static int nl80211_key_allowed(struct wireless_dev *wdev)
683{
684 ASSERT_WDEV_LOCK(wdev);
685
Johannes Bergfffd0932009-07-08 14:22:54 +0200686 switch (wdev->iftype) {
687 case NL80211_IFTYPE_AP:
688 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200689 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700690 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200691 break;
692 case NL80211_IFTYPE_ADHOC:
693 if (!wdev->current_bss)
694 return -ENOLINK;
695 break;
696 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200697 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200698 if (wdev->sme_state != CFG80211_SME_CONNECTED)
699 return -ENOLINK;
700 break;
701 default:
702 return -EINVAL;
703 }
704
705 return 0;
706}
707
Johannes Berg7527a782011-05-13 10:58:57 +0200708static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
709{
710 struct nlattr *nl_modes = nla_nest_start(msg, attr);
711 int i;
712
713 if (!nl_modes)
714 goto nla_put_failure;
715
716 i = 0;
717 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400718 if ((ifmodes & 1) && nla_put_flag(msg, i))
719 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200720 ifmodes >>= 1;
721 i++;
722 }
723
724 nla_nest_end(msg, nl_modes);
725 return 0;
726
727nla_put_failure:
728 return -ENOBUFS;
729}
730
731static int nl80211_put_iface_combinations(struct wiphy *wiphy,
732 struct sk_buff *msg)
733{
734 struct nlattr *nl_combis;
735 int i, j;
736
737 nl_combis = nla_nest_start(msg,
738 NL80211_ATTR_INTERFACE_COMBINATIONS);
739 if (!nl_combis)
740 goto nla_put_failure;
741
742 for (i = 0; i < wiphy->n_iface_combinations; i++) {
743 const struct ieee80211_iface_combination *c;
744 struct nlattr *nl_combi, *nl_limits;
745
746 c = &wiphy->iface_combinations[i];
747
748 nl_combi = nla_nest_start(msg, i + 1);
749 if (!nl_combi)
750 goto nla_put_failure;
751
752 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
753 if (!nl_limits)
754 goto nla_put_failure;
755
756 for (j = 0; j < c->n_limits; j++) {
757 struct nlattr *nl_limit;
758
759 nl_limit = nla_nest_start(msg, j + 1);
760 if (!nl_limit)
761 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400762 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
763 c->limits[j].max))
764 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200765 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
766 c->limits[j].types))
767 goto nla_put_failure;
768 nla_nest_end(msg, nl_limit);
769 }
770
771 nla_nest_end(msg, nl_limits);
772
David S. Miller9360ffd2012-03-29 04:41:26 -0400773 if (c->beacon_int_infra_match &&
774 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
775 goto nla_put_failure;
776 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
777 c->num_different_channels) ||
778 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
779 c->max_interfaces))
780 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200781
782 nla_nest_end(msg, nl_combi);
783 }
784
785 nla_nest_end(msg, nl_combis);
786
787 return 0;
788nla_put_failure:
789 return -ENOBUFS;
790}
791
Johannes Berg55682962007-09-20 13:09:35 -0400792static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
793 struct cfg80211_registered_device *dev)
794{
795 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100796 struct nlattr *nl_bands, *nl_band;
797 struct nlattr *nl_freqs, *nl_freq;
798 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100799 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100800 enum ieee80211_band band;
801 struct ieee80211_channel *chan;
802 struct ieee80211_rate *rate;
803 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200804 const struct ieee80211_txrx_stypes *mgmt_stypes =
805 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400806
807 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
808 if (!hdr)
809 return -1;
810
David S. Miller9360ffd2012-03-29 04:41:26 -0400811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
812 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
813 nla_put_u32(msg, NL80211_ATTR_GENERATION,
814 cfg80211_rdev_list_generation) ||
815 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
816 dev->wiphy.retry_short) ||
817 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
818 dev->wiphy.retry_long) ||
819 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
820 dev->wiphy.frag_threshold) ||
821 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
822 dev->wiphy.rts_threshold) ||
823 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
824 dev->wiphy.coverage_class) ||
825 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
826 dev->wiphy.max_scan_ssids) ||
827 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
828 dev->wiphy.max_sched_scan_ssids) ||
829 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
830 dev->wiphy.max_scan_ie_len) ||
831 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
832 dev->wiphy.max_sched_scan_ie_len) ||
833 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
834 dev->wiphy.max_match_sets))
835 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200836
David S. Miller9360ffd2012-03-29 04:41:26 -0400837 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
838 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
839 goto nla_put_failure;
840 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
841 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
842 goto nla_put_failure;
843 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
844 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
845 goto nla_put_failure;
846 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
847 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
848 goto nla_put_failure;
849 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
850 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
851 goto nla_put_failure;
852 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
853 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
854 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200855
David S. Miller9360ffd2012-03-29 04:41:26 -0400856 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
857 sizeof(u32) * dev->wiphy.n_cipher_suites,
858 dev->wiphy.cipher_suites))
859 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100860
David S. Miller9360ffd2012-03-29 04:41:26 -0400861 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
862 dev->wiphy.max_num_pmkids))
863 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530864
David S. Miller9360ffd2012-03-29 04:41:26 -0400865 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
866 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
867 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200868
David S. Miller9360ffd2012-03-29 04:41:26 -0400869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
870 dev->wiphy.available_antennas_tx) ||
871 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
872 dev->wiphy.available_antennas_rx))
873 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100874
David S. Miller9360ffd2012-03-29 04:41:26 -0400875 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
876 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
877 dev->wiphy.probe_resp_offload))
878 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200879
Bruno Randolf7f531e02010-12-16 11:30:22 +0900880 if ((dev->wiphy.available_antennas_tx ||
881 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900882 u32 tx_ant = 0, rx_ant = 0;
883 int res;
884 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
885 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
887 tx_ant) ||
888 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
889 rx_ant))
890 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900891 }
892 }
893
Johannes Berg7527a782011-05-13 10:58:57 +0200894 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
895 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700896 goto nla_put_failure;
897
Johannes Bergee688b002008-01-24 19:38:39 +0100898 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
899 if (!nl_bands)
900 goto nla_put_failure;
901
902 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
903 if (!dev->wiphy.bands[band])
904 continue;
905
906 nl_band = nla_nest_start(msg, band);
907 if (!nl_band)
908 goto nla_put_failure;
909
Johannes Bergd51626d2008-10-09 12:20:13 +0200910 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
912 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
913 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
914 &dev->wiphy.bands[band]->ht_cap.mcs) ||
915 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
916 dev->wiphy.bands[band]->ht_cap.cap) ||
917 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
918 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
919 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
920 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
921 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200922
Johannes Bergee688b002008-01-24 19:38:39 +0100923 /* add frequencies */
924 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
925 if (!nl_freqs)
926 goto nla_put_failure;
927
928 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
929 nl_freq = nla_nest_start(msg, i);
930 if (!nl_freq)
931 goto nla_put_failure;
932
933 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100934
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400935 if (nl80211_msg_put_channel(msg, chan))
936 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200937
Johannes Bergee688b002008-01-24 19:38:39 +0100938 nla_nest_end(msg, nl_freq);
939 }
940
941 nla_nest_end(msg, nl_freqs);
942
943 /* add bitrates */
944 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
945 if (!nl_rates)
946 goto nla_put_failure;
947
948 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
949 nl_rate = nla_nest_start(msg, i);
950 if (!nl_rate)
951 goto nla_put_failure;
952
953 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400954 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
955 rate->bitrate))
956 goto nla_put_failure;
957 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
958 nla_put_flag(msg,
959 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
960 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100961
962 nla_nest_end(msg, nl_rate);
963 }
964
965 nla_nest_end(msg, nl_rates);
966
967 nla_nest_end(msg, nl_band);
968 }
969 nla_nest_end(msg, nl_bands);
970
Johannes Berg8fdc6212009-03-14 09:34:01 +0100971 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
972 if (!nl_cmds)
973 goto nla_put_failure;
974
975 i = 0;
976#define CMD(op, n) \
977 do { \
978 if (dev->ops->op) { \
979 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
981 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100982 } \
983 } while (0)
984
985 CMD(add_virtual_intf, NEW_INTERFACE);
986 CMD(change_virtual_intf, SET_INTERFACE);
987 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100988 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100989 CMD(add_station, NEW_STATION);
990 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800991 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200993 CMD(auth, AUTHENTICATE);
994 CMD(assoc, ASSOCIATE);
995 CMD(deauth, DEAUTHENTICATE);
996 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200997 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100998 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100999 CMD(set_pmksa, SET_PMKSA);
1000 CMD(del_pmksa, DEL_PMKSA);
1001 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001002 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1003 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001004 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001005 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001006 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001007 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001008 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1010 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001011 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001012 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001013 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001014 i++;
1015 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1016 goto nla_put_failure;
1017 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001018 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001019 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1020 CMD(tdls_mgmt, TDLS_MGMT);
1021 CMD(tdls_oper, TDLS_OPER);
1022 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001023 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1024 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001025 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001026 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001027 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1028 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001029 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1030 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001031 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001032
Kalle Valo4745fc02011-11-17 19:06:10 +02001033#ifdef CONFIG_NL80211_TESTMODE
1034 CMD(testmode_cmd, TESTMODE);
1035#endif
1036
Johannes Berg8fdc6212009-03-14 09:34:01 +01001037#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001038
Johannes Berg6829c872009-07-02 09:13:27 +02001039 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001041 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1042 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001043 }
1044
Johannes Berg6829c872009-07-02 09:13:27 +02001045 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001046 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001047 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1048 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001049 }
1050
Johannes Berg8fdc6212009-03-14 09:34:01 +01001051 nla_nest_end(msg, nl_cmds);
1052
Johannes Berg7c4ef712011-11-18 15:33:48 +01001053 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001054 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1055 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1056 dev->wiphy.max_remain_on_channel_duration))
1057 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001058
David S. Miller9360ffd2012-03-29 04:41:26 -04001059 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1060 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1061 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001062
Johannes Berg2e161f72010-08-12 15:38:38 +02001063 if (mgmt_stypes) {
1064 u16 stypes;
1065 struct nlattr *nl_ftypes, *nl_ifs;
1066 enum nl80211_iftype ift;
1067
1068 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1069 if (!nl_ifs)
1070 goto nla_put_failure;
1071
1072 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1073 nl_ftypes = nla_nest_start(msg, ift);
1074 if (!nl_ftypes)
1075 goto nla_put_failure;
1076 i = 0;
1077 stypes = mgmt_stypes[ift].tx;
1078 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001079 if ((stypes & 1) &&
1080 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1081 (i << 4) | IEEE80211_FTYPE_MGMT))
1082 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001083 stypes >>= 1;
1084 i++;
1085 }
1086 nla_nest_end(msg, nl_ftypes);
1087 }
1088
Johannes Berg74b70a42010-08-24 12:15:53 +02001089 nla_nest_end(msg, nl_ifs);
1090
Johannes Berg2e161f72010-08-12 15:38:38 +02001091 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1092 if (!nl_ifs)
1093 goto nla_put_failure;
1094
1095 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1096 nl_ftypes = nla_nest_start(msg, ift);
1097 if (!nl_ftypes)
1098 goto nla_put_failure;
1099 i = 0;
1100 stypes = mgmt_stypes[ift].rx;
1101 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001102 if ((stypes & 1) &&
1103 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1104 (i << 4) | IEEE80211_FTYPE_MGMT))
1105 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001106 stypes >>= 1;
1107 i++;
1108 }
1109 nla_nest_end(msg, nl_ftypes);
1110 }
1111 nla_nest_end(msg, nl_ifs);
1112 }
1113
Johannes Bergff1b6e62011-05-04 15:37:28 +02001114 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1115 struct nlattr *nl_wowlan;
1116
1117 nl_wowlan = nla_nest_start(msg,
1118 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1119 if (!nl_wowlan)
1120 goto nla_put_failure;
1121
David S. Miller9360ffd2012-03-29 04:41:26 -04001122 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1123 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1124 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1125 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1126 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1127 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1128 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1129 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1130 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1131 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1132 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1134 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1136 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1138 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001139 if (dev->wiphy.wowlan.n_patterns) {
1140 struct nl80211_wowlan_pattern_support pat = {
1141 .max_patterns = dev->wiphy.wowlan.n_patterns,
1142 .min_pattern_len =
1143 dev->wiphy.wowlan.pattern_min_len,
1144 .max_pattern_len =
1145 dev->wiphy.wowlan.pattern_max_len,
1146 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1148 sizeof(pat), &pat))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 }
1151
1152 nla_nest_end(msg, nl_wowlan);
1153 }
1154
Johannes Berg7527a782011-05-13 10:58:57 +02001155 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1156 dev->wiphy.software_iftypes))
1157 goto nla_put_failure;
1158
1159 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1160 goto nla_put_failure;
1161
David S. Miller9360ffd2012-03-29 04:41:26 -04001162 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1163 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1164 dev->wiphy.ap_sme_capa))
1165 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001166
David S. Miller9360ffd2012-03-29 04:41:26 -04001167 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1168 dev->wiphy.features))
1169 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001170
David S. Miller9360ffd2012-03-29 04:41:26 -04001171 if (dev->wiphy.ht_capa_mod_mask &&
1172 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1173 sizeof(*dev->wiphy.ht_capa_mod_mask),
1174 dev->wiphy.ht_capa_mod_mask))
1175 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001176
Johannes Berg55682962007-09-20 13:09:35 -04001177 return genlmsg_end(msg, hdr);
1178
1179 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001180 genlmsg_cancel(msg, hdr);
1181 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001182}
1183
1184static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1185{
1186 int idx = 0;
1187 int start = cb->args[0];
1188 struct cfg80211_registered_device *dev;
1189
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001190 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001191 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001192 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1193 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001194 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001195 continue;
1196 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1197 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001198 dev) < 0) {
1199 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001200 break;
Julius Volzb4637272008-07-08 14:02:19 +02001201 }
Johannes Berg55682962007-09-20 13:09:35 -04001202 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001203 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001204
1205 cb->args[0] = idx;
1206
1207 return skb->len;
1208}
1209
1210static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1211{
1212 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001213 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001214
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001215 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001216 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001217 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001218
Johannes Berg4c476992010-10-04 21:36:35 +02001219 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1220 nlmsg_free(msg);
1221 return -ENOBUFS;
1222 }
Johannes Berg55682962007-09-20 13:09:35 -04001223
Johannes Berg134e6372009-07-10 09:51:34 +00001224 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001225}
1226
Jouni Malinen31888482008-10-30 16:59:24 +02001227static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1228 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1229 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1230 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1231 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1232 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1233};
1234
1235static int parse_txq_params(struct nlattr *tb[],
1236 struct ieee80211_txq_params *txq_params)
1237{
Johannes Berga3304b02012-03-28 11:04:24 +02001238 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001239 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1240 !tb[NL80211_TXQ_ATTR_AIFS])
1241 return -EINVAL;
1242
Johannes Berga3304b02012-03-28 11:04:24 +02001243 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001244 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1245 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1246 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1247 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1248
Johannes Berga3304b02012-03-28 11:04:24 +02001249 if (txq_params->ac >= NL80211_NUM_ACS)
1250 return -EINVAL;
1251
Jouni Malinen31888482008-10-30 16:59:24 +02001252 return 0;
1253}
1254
Johannes Bergf444de02010-05-05 15:25:02 +02001255static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1256{
1257 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001258 * You can only set the channel explicitly for WDS interfaces,
1259 * all others have their channel managed via their respective
1260 * "establish a connection" command (connect, join, ...)
1261 *
1262 * For AP/GO and mesh mode, the channel can be set with the
1263 * channel userspace API, but is only stored and passed to the
1264 * low-level driver when the AP starts or the mesh is joined.
1265 * This is for backward compatibility, userspace can also give
1266 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001267 *
1268 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001269 * whatever else is going on, so they have their own special
1270 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001271 */
1272 return !wdev ||
1273 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001274 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001275 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1276 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001277}
1278
Johannes Bergcd6c6592012-05-10 21:27:18 +02001279static bool nl80211_valid_channel_type(struct genl_info *info,
1280 enum nl80211_channel_type *channel_type)
1281{
1282 enum nl80211_channel_type tmp;
1283
1284 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1285 return false;
1286
1287 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1288 if (tmp != NL80211_CHAN_NO_HT &&
1289 tmp != NL80211_CHAN_HT20 &&
1290 tmp != NL80211_CHAN_HT40PLUS &&
1291 tmp != NL80211_CHAN_HT40MINUS)
1292 return false;
1293
1294 if (channel_type)
1295 *channel_type = tmp;
1296
1297 return true;
1298}
1299
Johannes Bergf444de02010-05-05 15:25:02 +02001300static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1301 struct wireless_dev *wdev,
1302 struct genl_info *info)
1303{
Johannes Bergaa430da2012-05-16 23:50:18 +02001304 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001305 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1306 u32 freq;
1307 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001308 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1309
1310 if (wdev)
1311 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001312
1313 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1314 return -EINVAL;
1315
1316 if (!nl80211_can_set_dev_channel(wdev))
1317 return -EOPNOTSUPP;
1318
Johannes Bergcd6c6592012-05-10 21:27:18 +02001319 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1320 !nl80211_valid_channel_type(info, &channel_type))
1321 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001322
1323 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1324
1325 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001326 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001327 case NL80211_IFTYPE_AP:
1328 case NL80211_IFTYPE_P2P_GO:
1329 if (wdev->beacon_interval) {
1330 result = -EBUSY;
1331 break;
1332 }
1333 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1334 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1335 channel,
1336 channel_type)) {
1337 result = -EINVAL;
1338 break;
1339 }
1340 wdev->preset_chan = channel;
1341 wdev->preset_chantype = channel_type;
1342 result = 0;
1343 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001344 case NL80211_IFTYPE_MESH_POINT:
1345 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1346 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001347 case NL80211_IFTYPE_MONITOR:
1348 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1349 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001350 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001351 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001352 }
1353 mutex_unlock(&rdev->devlist_mtx);
1354
1355 return result;
1356}
1357
1358static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1359{
Johannes Berg4c476992010-10-04 21:36:35 +02001360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1361 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001362
Johannes Berg4c476992010-10-04 21:36:35 +02001363 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001364}
1365
Bill Jordane8347eb2010-10-01 13:54:28 -04001366static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1367{
Johannes Berg43b19952010-10-07 13:10:30 +02001368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1369 struct net_device *dev = info->user_ptr[1];
1370 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001371 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001372
1373 if (!info->attrs[NL80211_ATTR_MAC])
1374 return -EINVAL;
1375
Johannes Berg43b19952010-10-07 13:10:30 +02001376 if (netif_running(dev))
1377 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001378
Johannes Berg43b19952010-10-07 13:10:30 +02001379 if (!rdev->ops->set_wds_peer)
1380 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001381
Johannes Berg43b19952010-10-07 13:10:30 +02001382 if (wdev->iftype != NL80211_IFTYPE_WDS)
1383 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001386 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001387}
1388
1389
Johannes Berg55682962007-09-20 13:09:35 -04001390static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1391{
1392 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001393 struct net_device *netdev = NULL;
1394 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001395 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001396 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001397 u32 changed;
1398 u8 retry_short = 0, retry_long = 0;
1399 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001400 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001401
Johannes Bergf444de02010-05-05 15:25:02 +02001402 /*
1403 * Try to find the wiphy and netdev. Normally this
1404 * function shouldn't need the netdev, but this is
1405 * done for backward compatibility -- previously
1406 * setting the channel was done per wiphy, but now
1407 * it is per netdev. Previous userland like hostapd
1408 * also passed a netdev to set_wiphy, so that it is
1409 * possible to let that go to the right netdev!
1410 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001411 mutex_lock(&cfg80211_mutex);
1412
Johannes Bergf444de02010-05-05 15:25:02 +02001413 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1414 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1415
1416 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1417 if (netdev && netdev->ieee80211_ptr) {
1418 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1419 mutex_lock(&rdev->mtx);
1420 } else
1421 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001422 }
1423
Johannes Bergf444de02010-05-05 15:25:02 +02001424 if (!netdev) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02001425 rdev = __cfg80211_rdev_from_info(genl_info_net(info), info);
Johannes Bergf444de02010-05-05 15:25:02 +02001426 if (IS_ERR(rdev)) {
1427 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001428 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001429 }
1430 wdev = NULL;
1431 netdev = NULL;
1432 result = 0;
1433
1434 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001435 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001436 wdev = netdev->ieee80211_ptr;
1437 else
1438 wdev = NULL;
1439
1440 /*
1441 * end workaround code, by now the rdev is available
1442 * and locked, and wdev may or may not be NULL.
1443 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001444
1445 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001446 result = cfg80211_dev_rename(
1447 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001448
1449 mutex_unlock(&cfg80211_mutex);
1450
1451 if (result)
1452 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001453
Jouni Malinen31888482008-10-30 16:59:24 +02001454 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1455 struct ieee80211_txq_params txq_params;
1456 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1457
1458 if (!rdev->ops->set_txq_params) {
1459 result = -EOPNOTSUPP;
1460 goto bad_res;
1461 }
1462
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001463 if (!netdev) {
1464 result = -EINVAL;
1465 goto bad_res;
1466 }
1467
Johannes Berg133a3ff2011-11-03 14:50:13 +01001468 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1469 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1470 result = -EINVAL;
1471 goto bad_res;
1472 }
1473
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001474 if (!netif_running(netdev)) {
1475 result = -ENETDOWN;
1476 goto bad_res;
1477 }
1478
Jouni Malinen31888482008-10-30 16:59:24 +02001479 nla_for_each_nested(nl_txq_params,
1480 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1481 rem_txq_params) {
1482 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1483 nla_data(nl_txq_params),
1484 nla_len(nl_txq_params),
1485 txq_params_policy);
1486 result = parse_txq_params(tb, &txq_params);
1487 if (result)
1488 goto bad_res;
1489
1490 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001491 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001492 &txq_params);
1493 if (result)
1494 goto bad_res;
1495 }
1496 }
1497
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001498 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001499 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001500 if (result)
1501 goto bad_res;
1502 }
1503
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001504 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1505 enum nl80211_tx_power_setting type;
1506 int idx, mbm = 0;
1507
1508 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001509 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001510 goto bad_res;
1511 }
1512
1513 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1514 type = nla_get_u32(info->attrs[idx]);
1515
1516 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1517 (type != NL80211_TX_POWER_AUTOMATIC)) {
1518 result = -EINVAL;
1519 goto bad_res;
1520 }
1521
1522 if (type != NL80211_TX_POWER_AUTOMATIC) {
1523 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1524 mbm = nla_get_u32(info->attrs[idx]);
1525 }
1526
1527 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1528 if (result)
1529 goto bad_res;
1530 }
1531
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001532 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1533 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1534 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001535 if ((!rdev->wiphy.available_antennas_tx &&
1536 !rdev->wiphy.available_antennas_rx) ||
1537 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001538 result = -EOPNOTSUPP;
1539 goto bad_res;
1540 }
1541
1542 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1543 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1544
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001545 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001546 * available antenna masks, except for the "all" mask */
1547 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1548 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001549 result = -EINVAL;
1550 goto bad_res;
1551 }
1552
Bruno Randolf7f531e02010-12-16 11:30:22 +09001553 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1554 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001555
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001556 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1557 if (result)
1558 goto bad_res;
1559 }
1560
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001561 changed = 0;
1562
1563 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1564 retry_short = nla_get_u8(
1565 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1566 if (retry_short == 0) {
1567 result = -EINVAL;
1568 goto bad_res;
1569 }
1570 changed |= WIPHY_PARAM_RETRY_SHORT;
1571 }
1572
1573 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1574 retry_long = nla_get_u8(
1575 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1576 if (retry_long == 0) {
1577 result = -EINVAL;
1578 goto bad_res;
1579 }
1580 changed |= WIPHY_PARAM_RETRY_LONG;
1581 }
1582
1583 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1584 frag_threshold = nla_get_u32(
1585 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1586 if (frag_threshold < 256) {
1587 result = -EINVAL;
1588 goto bad_res;
1589 }
1590 if (frag_threshold != (u32) -1) {
1591 /*
1592 * Fragments (apart from the last one) are required to
1593 * have even length. Make the fragmentation code
1594 * simpler by stripping LSB should someone try to use
1595 * odd threshold value.
1596 */
1597 frag_threshold &= ~0x1;
1598 }
1599 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1600 }
1601
1602 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1603 rts_threshold = nla_get_u32(
1604 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1605 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1606 }
1607
Lukáš Turek81077e82009-12-21 22:50:47 +01001608 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1609 coverage_class = nla_get_u8(
1610 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1611 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1612 }
1613
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001614 if (changed) {
1615 u8 old_retry_short, old_retry_long;
1616 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001617 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001618
1619 if (!rdev->ops->set_wiphy_params) {
1620 result = -EOPNOTSUPP;
1621 goto bad_res;
1622 }
1623
1624 old_retry_short = rdev->wiphy.retry_short;
1625 old_retry_long = rdev->wiphy.retry_long;
1626 old_frag_threshold = rdev->wiphy.frag_threshold;
1627 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001628 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001629
1630 if (changed & WIPHY_PARAM_RETRY_SHORT)
1631 rdev->wiphy.retry_short = retry_short;
1632 if (changed & WIPHY_PARAM_RETRY_LONG)
1633 rdev->wiphy.retry_long = retry_long;
1634 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1635 rdev->wiphy.frag_threshold = frag_threshold;
1636 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1637 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001638 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1639 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001640
1641 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1642 if (result) {
1643 rdev->wiphy.retry_short = old_retry_short;
1644 rdev->wiphy.retry_long = old_retry_long;
1645 rdev->wiphy.frag_threshold = old_frag_threshold;
1646 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001647 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001648 }
1649 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001650
Johannes Berg306d6112008-12-08 12:39:04 +01001651 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001652 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001653 if (netdev)
1654 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001655 return result;
1656}
1657
1658
1659static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001660 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001661 struct net_device *dev)
1662{
1663 void *hdr;
1664
1665 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1666 if (!hdr)
1667 return -1;
1668
David S. Miller9360ffd2012-03-29 04:41:26 -04001669 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1670 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1671 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1672 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1673 dev->ieee80211_ptr->iftype) ||
1674 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1675 rdev->devlist_generation ^
1676 (cfg80211_rdev_list_generation << 2)))
1677 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001678
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001679 if (rdev->ops->get_channel) {
1680 struct ieee80211_channel *chan;
1681 enum nl80211_channel_type channel_type;
1682
1683 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001684 if (chan &&
1685 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1686 chan->center_freq) ||
1687 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1688 channel_type)))
1689 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001690 }
1691
Johannes Berg55682962007-09-20 13:09:35 -04001692 return genlmsg_end(msg, hdr);
1693
1694 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001695 genlmsg_cancel(msg, hdr);
1696 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001697}
1698
1699static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1700{
1701 int wp_idx = 0;
1702 int if_idx = 0;
1703 int wp_start = cb->args[0];
1704 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001705 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001706 struct wireless_dev *wdev;
1707
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001708 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001709 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1710 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001711 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001712 if (wp_idx < wp_start) {
1713 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001714 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001715 }
Johannes Berg55682962007-09-20 13:09:35 -04001716 if_idx = 0;
1717
Johannes Bergf5ea9122009-08-07 16:17:38 +02001718 mutex_lock(&rdev->devlist_mtx);
1719 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001720 if (if_idx < if_start) {
1721 if_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 (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1725 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001726 rdev, wdev->netdev) < 0) {
1727 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001728 goto out;
1729 }
1730 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001731 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001732 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001733
1734 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001735 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001736 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001737 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001738
1739 cb->args[0] = wp_idx;
1740 cb->args[1] = if_idx;
1741
1742 return skb->len;
1743}
1744
1745static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1746{
1747 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001748 struct cfg80211_registered_device *dev = info->user_ptr[0];
1749 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001750
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001752 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001753 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001754
Johannes Bergd7264052009-04-19 16:23:20 +02001755 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001756 dev, netdev) < 0) {
1757 nlmsg_free(msg);
1758 return -ENOBUFS;
1759 }
Johannes Berg55682962007-09-20 13:09:35 -04001760
Johannes Berg134e6372009-07-10 09:51:34 +00001761 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001762}
1763
Michael Wu66f7ac52008-01-31 19:48:22 +01001764static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1765 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1766 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1767 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1768 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1769 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1770};
1771
1772static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1773{
1774 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1775 int flag;
1776
1777 *mntrflags = 0;
1778
1779 if (!nla)
1780 return -EINVAL;
1781
1782 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1783 nla, mntr_flags_policy))
1784 return -EINVAL;
1785
1786 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1787 if (flags[flag])
1788 *mntrflags |= (1<<flag);
1789
1790 return 0;
1791}
1792
Johannes Berg9bc383d2009-11-19 11:55:19 +01001793static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001794 struct net_device *netdev, u8 use_4addr,
1795 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001796{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001797 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001798 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001799 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001800 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001801 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001802
1803 switch (iftype) {
1804 case NL80211_IFTYPE_AP_VLAN:
1805 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1806 return 0;
1807 break;
1808 case NL80211_IFTYPE_STATION:
1809 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1810 return 0;
1811 break;
1812 default:
1813 break;
1814 }
1815
1816 return -EOPNOTSUPP;
1817}
1818
Johannes Berg55682962007-09-20 13:09:35 -04001819static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1820{
Johannes Berg4c476992010-10-04 21:36:35 +02001821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001822 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001823 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001824 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001825 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001826 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001827 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001828
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001829 memset(&params, 0, sizeof(params));
1830
Johannes Berg04a773a2009-04-19 21:24:32 +02001831 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001832
Johannes Berg723b0382008-09-16 20:22:09 +02001833 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001834 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001835 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001836 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001837 if (ntype > NL80211_IFTYPE_MAX)
1838 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001839 }
1840
Johannes Berg92ffe052008-09-16 20:39:36 +02001841 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001842 struct wireless_dev *wdev = dev->ieee80211_ptr;
1843
Johannes Berg4c476992010-10-04 21:36:35 +02001844 if (ntype != NL80211_IFTYPE_MESH_POINT)
1845 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001846 if (netif_running(dev))
1847 return -EBUSY;
1848
1849 wdev_lock(wdev);
1850 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1851 IEEE80211_MAX_MESH_ID_LEN);
1852 wdev->mesh_id_up_len =
1853 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1854 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1855 wdev->mesh_id_up_len);
1856 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001857 }
1858
Felix Fietkau8b787642009-11-10 18:53:10 +01001859 if (info->attrs[NL80211_ATTR_4ADDR]) {
1860 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1861 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001862 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001863 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001864 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001865 } else {
1866 params.use_4addr = -1;
1867 }
1868
Johannes Berg92ffe052008-09-16 20:39:36 +02001869 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001870 if (ntype != NL80211_IFTYPE_MONITOR)
1871 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001872 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1873 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001874 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001875 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001876
1877 flags = &_flags;
1878 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001879 }
Johannes Berg3b858752009-03-12 09:55:09 +01001880
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001881 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001882 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001883 else
1884 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001885
Johannes Berg9bc383d2009-11-19 11:55:19 +01001886 if (!err && params.use_4addr != -1)
1887 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1888
Johannes Berg55682962007-09-20 13:09:35 -04001889 return err;
1890}
1891
1892static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1893{
Johannes Berg4c476992010-10-04 21:36:35 +02001894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001895 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001896 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001897 int err;
1898 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001899 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001900
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001901 memset(&params, 0, sizeof(params));
1902
Johannes Berg55682962007-09-20 13:09:35 -04001903 if (!info->attrs[NL80211_ATTR_IFNAME])
1904 return -EINVAL;
1905
1906 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1907 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1908 if (type > NL80211_IFTYPE_MAX)
1909 return -EINVAL;
1910 }
1911
Johannes Berg79c97e92009-07-07 03:56:12 +02001912 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001913 !(rdev->wiphy.interface_modes & (1 << type)))
1914 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001915
Johannes Berg9bc383d2009-11-19 11:55:19 +01001916 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001917 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001918 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001919 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001920 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001921 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001922
Michael Wu66f7ac52008-01-31 19:48:22 +01001923 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1924 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1925 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001926 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001927 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001928 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001929 if (IS_ERR(dev))
1930 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001931
Johannes Berg29cbe682010-12-03 09:20:44 +01001932 if (type == NL80211_IFTYPE_MESH_POINT &&
1933 info->attrs[NL80211_ATTR_MESH_ID]) {
1934 struct wireless_dev *wdev = dev->ieee80211_ptr;
1935
1936 wdev_lock(wdev);
1937 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1938 IEEE80211_MAX_MESH_ID_LEN);
1939 wdev->mesh_id_up_len =
1940 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1941 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1942 wdev->mesh_id_up_len);
1943 wdev_unlock(wdev);
1944 }
1945
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001946 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001947}
1948
1949static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1950{
Johannes Berg4c476992010-10-04 21:36:35 +02001951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1952 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001953
Johannes Berg4c476992010-10-04 21:36:35 +02001954 if (!rdev->ops->del_virtual_intf)
1955 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001956
Johannes Berg4c476992010-10-04 21:36:35 +02001957 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001958}
1959
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001960static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1961{
1962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1963 struct net_device *dev = info->user_ptr[1];
1964 u16 noack_map;
1965
1966 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1967 return -EINVAL;
1968
1969 if (!rdev->ops->set_noack_map)
1970 return -EOPNOTSUPP;
1971
1972 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1973
1974 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1975}
1976
Johannes Berg41ade002007-12-19 02:03:29 +01001977struct get_key_cookie {
1978 struct sk_buff *msg;
1979 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001980 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001981};
1982
1983static void get_key_callback(void *c, struct key_params *params)
1984{
Johannes Bergb9454e82009-07-08 13:29:08 +02001985 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001986 struct get_key_cookie *cookie = c;
1987
David S. Miller9360ffd2012-03-29 04:41:26 -04001988 if ((params->key &&
1989 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1990 params->key_len, params->key)) ||
1991 (params->seq &&
1992 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
1993 params->seq_len, params->seq)) ||
1994 (params->cipher &&
1995 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1996 params->cipher)))
1997 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01001998
Johannes Bergb9454e82009-07-08 13:29:08 +02001999 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2000 if (!key)
2001 goto nla_put_failure;
2002
David S. Miller9360ffd2012-03-29 04:41:26 -04002003 if ((params->key &&
2004 nla_put(cookie->msg, NL80211_KEY_DATA,
2005 params->key_len, params->key)) ||
2006 (params->seq &&
2007 nla_put(cookie->msg, NL80211_KEY_SEQ,
2008 params->seq_len, params->seq)) ||
2009 (params->cipher &&
2010 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2011 params->cipher)))
2012 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002013
David S. Miller9360ffd2012-03-29 04:41:26 -04002014 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2015 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002016
2017 nla_nest_end(cookie->msg, key);
2018
Johannes Berg41ade002007-12-19 02:03:29 +01002019 return;
2020 nla_put_failure:
2021 cookie->error = 1;
2022}
2023
2024static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2025{
Johannes Berg4c476992010-10-04 21:36:35 +02002026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002027 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002028 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002029 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002030 const u8 *mac_addr = NULL;
2031 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002032 struct get_key_cookie cookie = {
2033 .error = 0,
2034 };
2035 void *hdr;
2036 struct sk_buff *msg;
2037
2038 if (info->attrs[NL80211_ATTR_KEY_IDX])
2039 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2040
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002041 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002042 return -EINVAL;
2043
2044 if (info->attrs[NL80211_ATTR_MAC])
2045 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2046
Johannes Berge31b8212010-10-05 19:39:30 +02002047 pairwise = !!mac_addr;
2048 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2049 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2050 if (kt >= NUM_NL80211_KEYTYPES)
2051 return -EINVAL;
2052 if (kt != NL80211_KEYTYPE_GROUP &&
2053 kt != NL80211_KEYTYPE_PAIRWISE)
2054 return -EINVAL;
2055 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2056 }
2057
Johannes Berg4c476992010-10-04 21:36:35 +02002058 if (!rdev->ops->get_key)
2059 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002060
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002061 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002062 if (!msg)
2063 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002064
2065 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2066 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002067 if (IS_ERR(hdr))
2068 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002069
2070 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002071 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002072
David S. Miller9360ffd2012-03-29 04:41:26 -04002073 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2074 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2075 goto nla_put_failure;
2076 if (mac_addr &&
2077 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2078 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002079
Johannes Berge31b8212010-10-05 19:39:30 +02002080 if (pairwise && mac_addr &&
2081 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2082 return -ENOENT;
2083
2084 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2085 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002086
2087 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002088 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002089
2090 if (cookie.error)
2091 goto nla_put_failure;
2092
2093 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002094 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002095
2096 nla_put_failure:
2097 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002098 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002099 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002100 return err;
2101}
2102
2103static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2104{
Johannes Berg4c476992010-10-04 21:36:35 +02002105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002106 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002107 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002108 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002109
Johannes Bergb9454e82009-07-08 13:29:08 +02002110 err = nl80211_parse_key(info, &key);
2111 if (err)
2112 return err;
2113
2114 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002115 return -EINVAL;
2116
Johannes Bergb9454e82009-07-08 13:29:08 +02002117 /* only support setting default key */
2118 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002119 return -EINVAL;
2120
Johannes Bergfffd0932009-07-08 14:22:54 +02002121 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002122
2123 if (key.def) {
2124 if (!rdev->ops->set_default_key) {
2125 err = -EOPNOTSUPP;
2126 goto out;
2127 }
2128
2129 err = nl80211_key_allowed(dev->ieee80211_ptr);
2130 if (err)
2131 goto out;
2132
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002133 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2134 key.def_uni, key.def_multi);
2135
2136 if (err)
2137 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002138
Johannes Berg3d23e342009-09-29 23:27:28 +02002139#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002140 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002141#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002142 } else {
2143 if (key.def_uni || !key.def_multi) {
2144 err = -EINVAL;
2145 goto out;
2146 }
2147
2148 if (!rdev->ops->set_default_mgmt_key) {
2149 err = -EOPNOTSUPP;
2150 goto out;
2151 }
2152
2153 err = nl80211_key_allowed(dev->ieee80211_ptr);
2154 if (err)
2155 goto out;
2156
2157 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2158 dev, key.idx);
2159 if (err)
2160 goto out;
2161
2162#ifdef CONFIG_CFG80211_WEXT
2163 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2164#endif
2165 }
2166
2167 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002168 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002169
Johannes Berg41ade002007-12-19 02:03:29 +01002170 return err;
2171}
2172
2173static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2174{
Johannes Berg4c476992010-10-04 21:36:35 +02002175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002176 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002177 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002178 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002179 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002180
Johannes Bergb9454e82009-07-08 13:29:08 +02002181 err = nl80211_parse_key(info, &key);
2182 if (err)
2183 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002184
Johannes Bergb9454e82009-07-08 13:29:08 +02002185 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002186 return -EINVAL;
2187
Johannes Berg41ade002007-12-19 02:03:29 +01002188 if (info->attrs[NL80211_ATTR_MAC])
2189 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2190
Johannes Berge31b8212010-10-05 19:39:30 +02002191 if (key.type == -1) {
2192 if (mac_addr)
2193 key.type = NL80211_KEYTYPE_PAIRWISE;
2194 else
2195 key.type = NL80211_KEYTYPE_GROUP;
2196 }
2197
2198 /* for now */
2199 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2200 key.type != NL80211_KEYTYPE_GROUP)
2201 return -EINVAL;
2202
Johannes Berg4c476992010-10-04 21:36:35 +02002203 if (!rdev->ops->add_key)
2204 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002205
Johannes Berge31b8212010-10-05 19:39:30 +02002206 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2207 key.type == NL80211_KEYTYPE_PAIRWISE,
2208 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002209 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002210
2211 wdev_lock(dev->ieee80211_ptr);
2212 err = nl80211_key_allowed(dev->ieee80211_ptr);
2213 if (!err)
2214 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002215 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002216 mac_addr, &key.p);
2217 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002218
Johannes Berg41ade002007-12-19 02:03:29 +01002219 return err;
2220}
2221
2222static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2223{
Johannes Berg4c476992010-10-04 21:36:35 +02002224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002225 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002226 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002227 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002228 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002229
Johannes Bergb9454e82009-07-08 13:29:08 +02002230 err = nl80211_parse_key(info, &key);
2231 if (err)
2232 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002233
2234 if (info->attrs[NL80211_ATTR_MAC])
2235 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2236
Johannes Berge31b8212010-10-05 19:39:30 +02002237 if (key.type == -1) {
2238 if (mac_addr)
2239 key.type = NL80211_KEYTYPE_PAIRWISE;
2240 else
2241 key.type = NL80211_KEYTYPE_GROUP;
2242 }
2243
2244 /* for now */
2245 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2246 key.type != NL80211_KEYTYPE_GROUP)
2247 return -EINVAL;
2248
Johannes Berg4c476992010-10-04 21:36:35 +02002249 if (!rdev->ops->del_key)
2250 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002251
Johannes Bergfffd0932009-07-08 14:22:54 +02002252 wdev_lock(dev->ieee80211_ptr);
2253 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002254
2255 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2256 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2257 err = -ENOENT;
2258
Johannes Bergfffd0932009-07-08 14:22:54 +02002259 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002260 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2261 key.type == NL80211_KEYTYPE_PAIRWISE,
2262 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002263
Johannes Berg3d23e342009-09-29 23:27:28 +02002264#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002265 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002266 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002267 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002268 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002269 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2270 }
2271#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002272 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002273
Johannes Berg41ade002007-12-19 02:03:29 +01002274 return err;
2275}
2276
Johannes Berg88600202012-02-13 15:17:18 +01002277static int nl80211_parse_beacon(struct genl_info *info,
2278 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002279{
Johannes Berg88600202012-02-13 15:17:18 +01002280 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002281
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002282 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2283 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2284 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2285 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002286 return -EINVAL;
2287
Johannes Berg88600202012-02-13 15:17:18 +01002288 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002289
Johannes Berged1b6cc2007-12-19 02:03:32 +01002290 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002291 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2292 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2293 if (!bcn->head_len)
2294 return -EINVAL;
2295 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002296 }
2297
2298 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002299 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2300 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002301 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002302 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002303 }
2304
Johannes Berg4c476992010-10-04 21:36:35 +02002305 if (!haveinfo)
2306 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002307
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002308 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002309 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2310 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002311 }
2312
2313 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002314 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002315 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002316 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002317 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2318 }
2319
2320 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002321 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002322 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002323 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002324 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2325 }
2326
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002327 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002328 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002329 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002330 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002331 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2332 }
2333
Johannes Berg88600202012-02-13 15:17:18 +01002334 return 0;
2335}
2336
2337static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2338{
2339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2340 struct net_device *dev = info->user_ptr[1];
2341 struct wireless_dev *wdev = dev->ieee80211_ptr;
2342 struct cfg80211_ap_settings params;
2343 int err;
2344
2345 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2346 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2347 return -EOPNOTSUPP;
2348
2349 if (!rdev->ops->start_ap)
2350 return -EOPNOTSUPP;
2351
2352 if (wdev->beacon_interval)
2353 return -EALREADY;
2354
2355 memset(&params, 0, sizeof(params));
2356
2357 /* these are required for START_AP */
2358 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2359 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2360 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2361 return -EINVAL;
2362
2363 err = nl80211_parse_beacon(info, &params.beacon);
2364 if (err)
2365 return err;
2366
2367 params.beacon_interval =
2368 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2369 params.dtim_period =
2370 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2371
2372 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2373 if (err)
2374 return err;
2375
2376 /*
2377 * In theory, some of these attributes should be required here
2378 * but since they were not used when the command was originally
2379 * added, keep them optional for old user space programs to let
2380 * them continue to work with drivers that do not need the
2381 * additional information -- drivers must check!
2382 */
2383 if (info->attrs[NL80211_ATTR_SSID]) {
2384 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2385 params.ssid_len =
2386 nla_len(info->attrs[NL80211_ATTR_SSID]);
2387 if (params.ssid_len == 0 ||
2388 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2389 return -EINVAL;
2390 }
2391
2392 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2393 params.hidden_ssid = nla_get_u32(
2394 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2395 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2396 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2397 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2398 return -EINVAL;
2399 }
2400
2401 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2402
2403 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2404 params.auth_type = nla_get_u32(
2405 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2406 if (!nl80211_valid_auth_type(params.auth_type))
2407 return -EINVAL;
2408 } else
2409 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2410
2411 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2412 NL80211_MAX_NR_CIPHER_SUITES);
2413 if (err)
2414 return err;
2415
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302416 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2417 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2418 return -EOPNOTSUPP;
2419 params.inactivity_timeout = nla_get_u16(
2420 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2421 }
2422
Johannes Bergaa430da2012-05-16 23:50:18 +02002423 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2424 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2425
2426 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2427 !nl80211_valid_channel_type(info, &channel_type))
2428 return -EINVAL;
2429
2430 params.channel = rdev_freq_to_chan(rdev,
2431 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2432 channel_type);
2433 if (!params.channel)
2434 return -EINVAL;
2435 params.channel_type = channel_type;
2436 } else if (wdev->preset_chan) {
2437 params.channel = wdev->preset_chan;
2438 params.channel_type = wdev->preset_chantype;
2439 } else
2440 return -EINVAL;
2441
2442 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2443 params.channel_type))
2444 return -EINVAL;
2445
Johannes Berg88600202012-02-13 15:17:18 +01002446 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2447 if (!err)
2448 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002449 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002450}
2451
Johannes Berg88600202012-02-13 15:17:18 +01002452static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2453{
2454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2455 struct net_device *dev = info->user_ptr[1];
2456 struct wireless_dev *wdev = dev->ieee80211_ptr;
2457 struct cfg80211_beacon_data params;
2458 int err;
2459
2460 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2461 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2462 return -EOPNOTSUPP;
2463
2464 if (!rdev->ops->change_beacon)
2465 return -EOPNOTSUPP;
2466
2467 if (!wdev->beacon_interval)
2468 return -EINVAL;
2469
2470 err = nl80211_parse_beacon(info, &params);
2471 if (err)
2472 return err;
2473
2474 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2475}
2476
2477static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002478{
Johannes Berg4c476992010-10-04 21:36:35 +02002479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2480 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002481 struct wireless_dev *wdev = dev->ieee80211_ptr;
2482 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002483
Johannes Berg88600202012-02-13 15:17:18 +01002484 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002485 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002486
Johannes Berg074ac8d2010-09-16 14:58:22 +02002487 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002488 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2489 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002490
Johannes Berg88600202012-02-13 15:17:18 +01002491 if (!wdev->beacon_interval)
2492 return -ENOENT;
2493
2494 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002495 if (!err)
2496 wdev->beacon_interval = 0;
2497 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002498}
2499
Johannes Berg5727ef12007-12-19 02:03:34 +01002500static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2501 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2502 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2503 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002504 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002505 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002506 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002507};
2508
Johannes Bergeccb8e82009-05-11 21:57:56 +03002509static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002510 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002511 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002512{
2513 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002514 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002515 int flag;
2516
Johannes Bergeccb8e82009-05-11 21:57:56 +03002517 /*
2518 * Try parsing the new attribute first so userspace
2519 * can specify both for older kernels.
2520 */
2521 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2522 if (nla) {
2523 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002524
Johannes Bergeccb8e82009-05-11 21:57:56 +03002525 sta_flags = nla_data(nla);
2526 params->sta_flags_mask = sta_flags->mask;
2527 params->sta_flags_set = sta_flags->set;
2528 if ((params->sta_flags_mask |
2529 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2530 return -EINVAL;
2531 return 0;
2532 }
2533
2534 /* if present, parse the old attribute */
2535
2536 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002537 if (!nla)
2538 return 0;
2539
2540 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2541 nla, sta_flags_policy))
2542 return -EINVAL;
2543
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002544 /*
2545 * Only allow certain flags for interface types so that
2546 * other attributes are silently ignored. Remember that
2547 * this is backward compatibility code with old userspace
2548 * and shouldn't be hit in other cases anyway.
2549 */
2550 switch (iftype) {
2551 case NL80211_IFTYPE_AP:
2552 case NL80211_IFTYPE_AP_VLAN:
2553 case NL80211_IFTYPE_P2P_GO:
2554 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2555 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2556 BIT(NL80211_STA_FLAG_WME) |
2557 BIT(NL80211_STA_FLAG_MFP);
2558 break;
2559 case NL80211_IFTYPE_P2P_CLIENT:
2560 case NL80211_IFTYPE_STATION:
2561 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2562 BIT(NL80211_STA_FLAG_TDLS_PEER);
2563 break;
2564 case NL80211_IFTYPE_MESH_POINT:
2565 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2566 BIT(NL80211_STA_FLAG_MFP) |
2567 BIT(NL80211_STA_FLAG_AUTHORIZED);
2568 default:
2569 return -EINVAL;
2570 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002571
Johannes Berg3383b5a2012-05-10 20:14:43 +02002572 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2573 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002574 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002575
Johannes Berg3383b5a2012-05-10 20:14:43 +02002576 /* no longer support new API additions in old API */
2577 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2578 return -EINVAL;
2579 }
2580 }
2581
Johannes Berg5727ef12007-12-19 02:03:34 +01002582 return 0;
2583}
2584
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002585static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2586 int attr)
2587{
2588 struct nlattr *rate;
2589 u16 bitrate;
2590
2591 rate = nla_nest_start(msg, attr);
2592 if (!rate)
2593 goto nla_put_failure;
2594
2595 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2596 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002597 if ((bitrate > 0 &&
2598 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2599 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2600 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2601 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2602 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2603 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2604 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2605 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002606
2607 nla_nest_end(msg, rate);
2608 return true;
2609
2610nla_put_failure:
2611 return false;
2612}
2613
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002614static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002615 int flags,
2616 struct cfg80211_registered_device *rdev,
2617 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002618 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002619{
2620 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002621 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002622
2623 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2624 if (!hdr)
2625 return -1;
2626
David S. Miller9360ffd2012-03-29 04:41:26 -04002627 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2629 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2630 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002631
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002632 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2633 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002634 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002635 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2636 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2637 sinfo->connected_time))
2638 goto nla_put_failure;
2639 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2640 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2641 sinfo->inactive_time))
2642 goto nla_put_failure;
2643 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2644 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2645 sinfo->rx_bytes))
2646 goto nla_put_failure;
2647 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2648 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2649 sinfo->tx_bytes))
2650 goto nla_put_failure;
2651 if ((sinfo->filled & STATION_INFO_LLID) &&
2652 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2653 goto nla_put_failure;
2654 if ((sinfo->filled & STATION_INFO_PLID) &&
2655 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2656 goto nla_put_failure;
2657 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2658 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2659 sinfo->plink_state))
2660 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002661 switch (rdev->wiphy.signal_type) {
2662 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002663 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2664 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2665 sinfo->signal))
2666 goto nla_put_failure;
2667 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2668 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2669 sinfo->signal_avg))
2670 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002671 break;
2672 default:
2673 break;
2674 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002675 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002676 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2677 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002678 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002679 }
2680 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2681 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2682 NL80211_STA_INFO_RX_BITRATE))
2683 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002684 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002685 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2686 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2687 sinfo->rx_packets))
2688 goto nla_put_failure;
2689 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2690 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2691 sinfo->tx_packets))
2692 goto nla_put_failure;
2693 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2694 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2695 sinfo->tx_retries))
2696 goto nla_put_failure;
2697 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2698 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2699 sinfo->tx_failed))
2700 goto nla_put_failure;
2701 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2702 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2703 sinfo->beacon_loss_count))
2704 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002705 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2706 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2707 if (!bss_param)
2708 goto nla_put_failure;
2709
David S. Miller9360ffd2012-03-29 04:41:26 -04002710 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2711 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2712 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2713 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2714 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2715 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2716 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2717 sinfo->bss_param.dtim_period) ||
2718 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2719 sinfo->bss_param.beacon_interval))
2720 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002721
2722 nla_nest_end(msg, bss_param);
2723 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002724 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2725 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2726 sizeof(struct nl80211_sta_flag_update),
2727 &sinfo->sta_flags))
2728 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002729 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2730 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2731 sinfo->t_offset))
2732 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002733 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002734
David S. Miller9360ffd2012-03-29 04:41:26 -04002735 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2736 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2737 sinfo->assoc_req_ies))
2738 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002739
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002740 return genlmsg_end(msg, hdr);
2741
2742 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002743 genlmsg_cancel(msg, hdr);
2744 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002745}
2746
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002747static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002748 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002749{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002750 struct station_info sinfo;
2751 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002752 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002753 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002754 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002755 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002756
Johannes Berg67748892010-10-04 21:14:06 +02002757 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2758 if (err)
2759 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002760
2761 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002762 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002763 goto out_err;
2764 }
2765
Johannes Bergbba95fe2008-07-29 13:22:51 +02002766 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002767 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002768 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2769 mac_addr, &sinfo);
2770 if (err == -ENOENT)
2771 break;
2772 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002773 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002774
2775 if (nl80211_send_station(skb,
2776 NETLINK_CB(cb->skb).pid,
2777 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002778 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002779 &sinfo) < 0)
2780 goto out;
2781
2782 sta_idx++;
2783 }
2784
2785
2786 out:
2787 cb->args[1] = sta_idx;
2788 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002789 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002790 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002791
2792 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002793}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002794
Johannes Berg5727ef12007-12-19 02:03:34 +01002795static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2796{
Johannes Berg4c476992010-10-04 21:36:35 +02002797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2798 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002799 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002800 struct sk_buff *msg;
2801 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002802 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002803
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002804 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002805
2806 if (!info->attrs[NL80211_ATTR_MAC])
2807 return -EINVAL;
2808
2809 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2810
Johannes Berg4c476992010-10-04 21:36:35 +02002811 if (!rdev->ops->get_station)
2812 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002813
Johannes Berg79c97e92009-07-07 03:56:12 +02002814 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002815 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002816 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002817
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002819 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002820 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002821
2822 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002823 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002824 nlmsg_free(msg);
2825 return -ENOBUFS;
2826 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002827
Johannes Berg4c476992010-10-04 21:36:35 +02002828 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002829}
2830
2831/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002832 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002833 */
Johannes Berg80b99892011-11-18 16:23:01 +01002834static struct net_device *get_vlan(struct genl_info *info,
2835 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002836{
Johannes Berg463d0182009-07-14 00:33:35 +02002837 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002838 struct net_device *v;
2839 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002840
Johannes Berg80b99892011-11-18 16:23:01 +01002841 if (!vlanattr)
2842 return NULL;
2843
2844 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2845 if (!v)
2846 return ERR_PTR(-ENODEV);
2847
2848 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2849 ret = -EINVAL;
2850 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002851 }
Johannes Berg80b99892011-11-18 16:23:01 +01002852
2853 if (!netif_running(v)) {
2854 ret = -ENETDOWN;
2855 goto error;
2856 }
2857
2858 return v;
2859 error:
2860 dev_put(v);
2861 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002862}
2863
2864static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2865{
Johannes Berg4c476992010-10-04 21:36:35 +02002866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002867 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002868 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002869 struct station_parameters params;
2870 u8 *mac_addr = NULL;
2871
2872 memset(&params, 0, sizeof(params));
2873
2874 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002875 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002876
2877 if (info->attrs[NL80211_ATTR_STA_AID])
2878 return -EINVAL;
2879
2880 if (!info->attrs[NL80211_ATTR_MAC])
2881 return -EINVAL;
2882
2883 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2884
2885 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2886 params.supported_rates =
2887 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2888 params.supported_rates_len =
2889 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2890 }
2891
2892 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2893 params.listen_interval =
2894 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2895
Jouni Malinen36aedc92008-08-25 11:58:58 +03002896 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2897 params.ht_capa =
2898 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2899
Johannes Bergbdd90d52011-12-14 12:20:27 +01002900 if (!rdev->ops->change_station)
2901 return -EOPNOTSUPP;
2902
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002903 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002904 return -EINVAL;
2905
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002906 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2907 params.plink_action =
2908 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2909
Javier Cardona9c3990a2011-05-03 16:57:11 -07002910 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2911 params.plink_state =
2912 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2913
Johannes Berga97f4422009-06-18 17:23:43 +02002914 switch (dev->ieee80211_ptr->iftype) {
2915 case NL80211_IFTYPE_AP:
2916 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002917 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002918 /* disallow mesh-specific things */
2919 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002920 return -EINVAL;
2921
2922 /* TDLS can't be set, ... */
2923 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2924 return -EINVAL;
2925 /*
2926 * ... but don't bother the driver with it. This works around
2927 * a hostapd/wpa_supplicant issue -- it always includes the
2928 * TLDS_PEER flag in the mask even for AP mode.
2929 */
2930 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2931
2932 /* accept only the listed bits */
2933 if (params.sta_flags_mask &
2934 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2935 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2936 BIT(NL80211_STA_FLAG_WME) |
2937 BIT(NL80211_STA_FLAG_MFP)))
2938 return -EINVAL;
2939
2940 /* must be last in here for error handling */
2941 params.vlan = get_vlan(info, rdev);
2942 if (IS_ERR(params.vlan))
2943 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002944 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002945 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002946 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002947 /*
2948 * Don't allow userspace to change the TDLS_PEER flag,
2949 * but silently ignore attempts to change it since we
2950 * don't have state here to verify that it doesn't try
2951 * to change the flag.
2952 */
2953 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002954 /* fall through */
2955 case NL80211_IFTYPE_ADHOC:
2956 /* disallow things sta doesn't support */
2957 if (params.plink_action)
2958 return -EINVAL;
2959 if (params.ht_capa)
2960 return -EINVAL;
2961 if (params.listen_interval >= 0)
2962 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002963 /* reject any changes other than AUTHORIZED */
2964 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2965 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002966 break;
2967 case NL80211_IFTYPE_MESH_POINT:
2968 /* disallow things mesh doesn't support */
2969 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002970 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002971 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002972 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002973 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002974 return -EINVAL;
2975 /*
2976 * No special handling for TDLS here -- the userspace
2977 * mesh code doesn't have this bug.
2978 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002979 if (params.sta_flags_mask &
2980 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002981 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002982 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002983 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002984 break;
2985 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002986 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002987 }
2988
Johannes Bergbdd90d52011-12-14 12:20:27 +01002989 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002990
Johannes Berg79c97e92009-07-07 03:56:12 +02002991 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002992
Johannes Berg5727ef12007-12-19 02:03:34 +01002993 if (params.vlan)
2994 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002995
Johannes Berg5727ef12007-12-19 02:03:34 +01002996 return err;
2997}
2998
Eliad Pellerc75786c2011-08-23 14:37:46 +03002999static struct nla_policy
3000nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3001 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3002 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3003};
3004
Johannes Berg5727ef12007-12-19 02:03:34 +01003005static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3006{
Johannes Berg4c476992010-10-04 21:36:35 +02003007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003008 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003009 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003010 struct station_parameters params;
3011 u8 *mac_addr = NULL;
3012
3013 memset(&params, 0, sizeof(params));
3014
3015 if (!info->attrs[NL80211_ATTR_MAC])
3016 return -EINVAL;
3017
Johannes Berg5727ef12007-12-19 02:03:34 +01003018 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3019 return -EINVAL;
3020
3021 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3022 return -EINVAL;
3023
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003024 if (!info->attrs[NL80211_ATTR_STA_AID])
3025 return -EINVAL;
3026
Johannes Berg5727ef12007-12-19 02:03:34 +01003027 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3028 params.supported_rates =
3029 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3030 params.supported_rates_len =
3031 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3032 params.listen_interval =
3033 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003034
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003035 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3036 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3037 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003038
Jouni Malinen36aedc92008-08-25 11:58:58 +03003039 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3040 params.ht_capa =
3041 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003042
Javier Cardona96b78df2011-04-07 15:08:33 -07003043 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3044 params.plink_action =
3045 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3046
Johannes Bergbdd90d52011-12-14 12:20:27 +01003047 if (!rdev->ops->add_station)
3048 return -EOPNOTSUPP;
3049
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003050 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003051 return -EINVAL;
3052
Johannes Bergbdd90d52011-12-14 12:20:27 +01003053 switch (dev->ieee80211_ptr->iftype) {
3054 case NL80211_IFTYPE_AP:
3055 case NL80211_IFTYPE_AP_VLAN:
3056 case NL80211_IFTYPE_P2P_GO:
3057 /* parse WME attributes if sta is WME capable */
3058 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3059 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3060 info->attrs[NL80211_ATTR_STA_WME]) {
3061 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3062 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003063
Johannes Bergbdd90d52011-12-14 12:20:27 +01003064 nla = info->attrs[NL80211_ATTR_STA_WME];
3065 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3066 nl80211_sta_wme_policy);
3067 if (err)
3068 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003069
Johannes Bergbdd90d52011-12-14 12:20:27 +01003070 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3071 params.uapsd_queues =
3072 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3073 if (params.uapsd_queues &
3074 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3075 return -EINVAL;
3076
3077 if (tb[NL80211_STA_WME_MAX_SP])
3078 params.max_sp =
3079 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3080
3081 if (params.max_sp &
3082 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3083 return -EINVAL;
3084
3085 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3086 }
3087 /* TDLS peers cannot be added */
3088 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003089 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003090 /* but don't bother the driver with it */
3091 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003092
Johannes Bergbdd90d52011-12-14 12:20:27 +01003093 /* must be last in here for error handling */
3094 params.vlan = get_vlan(info, rdev);
3095 if (IS_ERR(params.vlan))
3096 return PTR_ERR(params.vlan);
3097 break;
3098 case NL80211_IFTYPE_MESH_POINT:
3099 /* TDLS peers cannot be added */
3100 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003101 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003102 break;
3103 case NL80211_IFTYPE_STATION:
3104 /* Only TDLS peers can be added */
3105 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3106 return -EINVAL;
3107 /* Can only add if TDLS ... */
3108 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3109 return -EOPNOTSUPP;
3110 /* ... with external setup is supported */
3111 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3112 return -EOPNOTSUPP;
3113 break;
3114 default:
3115 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003116 }
3117
Johannes Bergbdd90d52011-12-14 12:20:27 +01003118 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003119
Johannes Berg79c97e92009-07-07 03:56:12 +02003120 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003121
Johannes Berg5727ef12007-12-19 02:03:34 +01003122 if (params.vlan)
3123 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003124 return err;
3125}
3126
3127static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3128{
Johannes Berg4c476992010-10-04 21:36:35 +02003129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3130 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003131 u8 *mac_addr = NULL;
3132
3133 if (info->attrs[NL80211_ATTR_MAC])
3134 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3135
Johannes Berge80cf852009-05-11 14:43:13 +02003136 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003137 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003138 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003139 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3140 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003141
Johannes Berg4c476992010-10-04 21:36:35 +02003142 if (!rdev->ops->del_station)
3143 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003144
Johannes Berg4c476992010-10-04 21:36:35 +02003145 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003146}
3147
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003148static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3149 int flags, struct net_device *dev,
3150 u8 *dst, u8 *next_hop,
3151 struct mpath_info *pinfo)
3152{
3153 void *hdr;
3154 struct nlattr *pinfoattr;
3155
3156 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3157 if (!hdr)
3158 return -1;
3159
David S. Miller9360ffd2012-03-29 04:41:26 -04003160 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3161 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3162 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3163 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3164 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003165
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003166 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3167 if (!pinfoattr)
3168 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003169 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3170 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3171 pinfo->frame_qlen))
3172 goto nla_put_failure;
3173 if (((pinfo->filled & MPATH_INFO_SN) &&
3174 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3175 ((pinfo->filled & MPATH_INFO_METRIC) &&
3176 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3177 pinfo->metric)) ||
3178 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3179 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3180 pinfo->exptime)) ||
3181 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3182 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3183 pinfo->flags)) ||
3184 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3185 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3186 pinfo->discovery_timeout)) ||
3187 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3188 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3189 pinfo->discovery_retries)))
3190 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003191
3192 nla_nest_end(msg, pinfoattr);
3193
3194 return genlmsg_end(msg, hdr);
3195
3196 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003197 genlmsg_cancel(msg, hdr);
3198 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003199}
3200
3201static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003202 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003203{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003204 struct mpath_info pinfo;
3205 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003206 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003207 u8 dst[ETH_ALEN];
3208 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003209 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003210 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003211
Johannes Berg67748892010-10-04 21:14:06 +02003212 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3213 if (err)
3214 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003215
3216 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003217 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003218 goto out_err;
3219 }
3220
Jouni Malineneec60b02009-03-20 21:21:19 +02003221 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3222 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003223 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003224 }
3225
Johannes Bergbba95fe2008-07-29 13:22:51 +02003226 while (1) {
3227 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3228 dst, next_hop, &pinfo);
3229 if (err == -ENOENT)
3230 break;
3231 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003232 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003233
3234 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3235 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3236 netdev, dst, next_hop,
3237 &pinfo) < 0)
3238 goto out;
3239
3240 path_idx++;
3241 }
3242
3243
3244 out:
3245 cb->args[1] = path_idx;
3246 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003247 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003248 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003249 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003250}
3251
3252static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3253{
Johannes Berg4c476992010-10-04 21:36:35 +02003254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003255 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003256 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003257 struct mpath_info pinfo;
3258 struct sk_buff *msg;
3259 u8 *dst = NULL;
3260 u8 next_hop[ETH_ALEN];
3261
3262 memset(&pinfo, 0, sizeof(pinfo));
3263
3264 if (!info->attrs[NL80211_ATTR_MAC])
3265 return -EINVAL;
3266
3267 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3268
Johannes Berg4c476992010-10-04 21:36:35 +02003269 if (!rdev->ops->get_mpath)
3270 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003271
Johannes Berg4c476992010-10-04 21:36:35 +02003272 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3273 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003274
Johannes Berg79c97e92009-07-07 03:56:12 +02003275 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003276 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003277 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003278
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003280 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003281 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003282
3283 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003284 dev, dst, next_hop, &pinfo) < 0) {
3285 nlmsg_free(msg);
3286 return -ENOBUFS;
3287 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003288
Johannes Berg4c476992010-10-04 21:36:35 +02003289 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003290}
3291
3292static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3293{
Johannes Berg4c476992010-10-04 21:36:35 +02003294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3295 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003296 u8 *dst = NULL;
3297 u8 *next_hop = NULL;
3298
3299 if (!info->attrs[NL80211_ATTR_MAC])
3300 return -EINVAL;
3301
3302 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3303 return -EINVAL;
3304
3305 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3306 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3307
Johannes Berg4c476992010-10-04 21:36:35 +02003308 if (!rdev->ops->change_mpath)
3309 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003310
Johannes Berg4c476992010-10-04 21:36:35 +02003311 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3312 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003313
Johannes Berg4c476992010-10-04 21:36:35 +02003314 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003315}
Johannes Berg4c476992010-10-04 21:36:35 +02003316
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003317static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3318{
Johannes Berg4c476992010-10-04 21:36:35 +02003319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3320 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003321 u8 *dst = NULL;
3322 u8 *next_hop = NULL;
3323
3324 if (!info->attrs[NL80211_ATTR_MAC])
3325 return -EINVAL;
3326
3327 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3328 return -EINVAL;
3329
3330 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3331 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3332
Johannes Berg4c476992010-10-04 21:36:35 +02003333 if (!rdev->ops->add_mpath)
3334 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003335
Johannes Berg4c476992010-10-04 21:36:35 +02003336 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3337 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003338
Johannes Berg4c476992010-10-04 21:36:35 +02003339 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003340}
3341
3342static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3343{
Johannes Berg4c476992010-10-04 21:36:35 +02003344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3345 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003346 u8 *dst = NULL;
3347
3348 if (info->attrs[NL80211_ATTR_MAC])
3349 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3350
Johannes Berg4c476992010-10-04 21:36:35 +02003351 if (!rdev->ops->del_mpath)
3352 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003353
Johannes Berg4c476992010-10-04 21:36:35 +02003354 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003355}
3356
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003357static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3358{
Johannes Berg4c476992010-10-04 21:36:35 +02003359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3360 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003361 struct bss_parameters params;
3362
3363 memset(&params, 0, sizeof(params));
3364 /* default to not changing parameters */
3365 params.use_cts_prot = -1;
3366 params.use_short_preamble = -1;
3367 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003368 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003369 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003370
3371 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3372 params.use_cts_prot =
3373 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3374 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3375 params.use_short_preamble =
3376 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3377 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3378 params.use_short_slot_time =
3379 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003380 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3381 params.basic_rates =
3382 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3383 params.basic_rates_len =
3384 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3385 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003386 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3387 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003388 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3389 params.ht_opmode =
3390 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003391
Johannes Berg4c476992010-10-04 21:36:35 +02003392 if (!rdev->ops->change_bss)
3393 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003394
Johannes Berg074ac8d2010-09-16 14:58:22 +02003395 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003396 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3397 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003398
Johannes Berg4c476992010-10-04 21:36:35 +02003399 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003400}
3401
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003402static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003403 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3404 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3405 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3406 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3407 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3408 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3409};
3410
3411static int parse_reg_rule(struct nlattr *tb[],
3412 struct ieee80211_reg_rule *reg_rule)
3413{
3414 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3415 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3416
3417 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3418 return -EINVAL;
3419 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3420 return -EINVAL;
3421 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3422 return -EINVAL;
3423 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3424 return -EINVAL;
3425 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3426 return -EINVAL;
3427
3428 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3429
3430 freq_range->start_freq_khz =
3431 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3432 freq_range->end_freq_khz =
3433 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3434 freq_range->max_bandwidth_khz =
3435 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3436
3437 power_rule->max_eirp =
3438 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3439
3440 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3441 power_rule->max_antenna_gain =
3442 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3443
3444 return 0;
3445}
3446
3447static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3448{
3449 int r;
3450 char *data = NULL;
3451
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003452 /*
3453 * You should only get this when cfg80211 hasn't yet initialized
3454 * completely when built-in to the kernel right between the time
3455 * window between nl80211_init() and regulatory_init(), if that is
3456 * even possible.
3457 */
3458 mutex_lock(&cfg80211_mutex);
3459 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003460 mutex_unlock(&cfg80211_mutex);
3461 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003462 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003463 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003464
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003465 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3466 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003467
3468 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3469
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003470 r = regulatory_hint_user(data);
3471
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003472 return r;
3473}
3474
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003475static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003476 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003477{
Johannes Berg4c476992010-10-04 21:36:35 +02003478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003479 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003480 struct wireless_dev *wdev = dev->ieee80211_ptr;
3481 struct mesh_config cur_params;
3482 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003483 void *hdr;
3484 struct nlattr *pinfoattr;
3485 struct sk_buff *msg;
3486
Johannes Berg29cbe682010-12-03 09:20:44 +01003487 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3488 return -EOPNOTSUPP;
3489
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003490 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003491 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003492
Johannes Berg29cbe682010-12-03 09:20:44 +01003493 wdev_lock(wdev);
3494 /* If not connected, get default parameters */
3495 if (!wdev->mesh_id_len)
3496 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3497 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003498 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003499 &cur_params);
3500 wdev_unlock(wdev);
3501
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003502 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003503 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003504
3505 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003507 if (!msg)
3508 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003509 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003510 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003511 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003512 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003513 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003514 if (!pinfoattr)
3515 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003516 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3517 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3518 cur_params.dot11MeshRetryTimeout) ||
3519 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3520 cur_params.dot11MeshConfirmTimeout) ||
3521 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3522 cur_params.dot11MeshHoldingTimeout) ||
3523 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3524 cur_params.dot11MeshMaxPeerLinks) ||
3525 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3526 cur_params.dot11MeshMaxRetries) ||
3527 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3528 cur_params.dot11MeshTTL) ||
3529 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3530 cur_params.element_ttl) ||
3531 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3532 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003533 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3534 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003535 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3536 cur_params.dot11MeshHWMPmaxPREQretries) ||
3537 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3538 cur_params.path_refresh_time) ||
3539 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3540 cur_params.min_discovery_timeout) ||
3541 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3542 cur_params.dot11MeshHWMPactivePathTimeout) ||
3543 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3544 cur_params.dot11MeshHWMPpreqMinInterval) ||
3545 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3546 cur_params.dot11MeshHWMPperrMinInterval) ||
3547 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3548 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3549 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3550 cur_params.dot11MeshHWMPRootMode) ||
3551 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3552 cur_params.dot11MeshHWMPRannInterval) ||
3553 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3554 cur_params.dot11MeshGateAnnouncementProtocol) ||
3555 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3556 cur_params.dot11MeshForwarding) ||
3557 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003558 cur_params.rssi_threshold) ||
3559 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003560 cur_params.ht_opmode) ||
3561 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3562 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3563 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003564 cur_params.dot11MeshHWMProotInterval) ||
3565 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3566 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003567 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003568 nla_nest_end(msg, pinfoattr);
3569 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003570 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003571
Johannes Berg3b858752009-03-12 09:55:09 +01003572 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003573 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003574 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003575 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003576 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003577}
3578
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003579static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003580 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3581 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3582 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3583 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3584 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3585 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003586 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003587 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003588 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003589 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3590 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3591 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3592 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3593 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003594 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003595 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003596 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003597 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003598 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003599 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003600 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3601 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003602 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3603 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003604 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003605};
3606
Javier Cardonac80d5452010-12-16 17:37:49 -08003607static const struct nla_policy
3608 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003609 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003610 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3611 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003612 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003613 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003614 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003615 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003616};
3617
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003618static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003619 struct mesh_config *cfg,
3620 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003621{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003622 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003623 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003624
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003625#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3626do {\
3627 if (table[attr_num]) {\
3628 cfg->param = nla_fn(table[attr_num]); \
3629 mask |= (1 << (attr_num - 1)); \
3630 } \
3631} while (0);\
3632
3633
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003634 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003635 return -EINVAL;
3636 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003637 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003638 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003639 return -EINVAL;
3640
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003641 /* This makes sure that there aren't more than 32 mesh config
3642 * parameters (otherwise our bitfield scheme would not work.) */
3643 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3644
3645 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003646 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003647 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3648 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003649 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003650 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3651 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003652 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003653 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3654 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003656 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3657 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003658 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003659 mask, NL80211_MESHCONF_MAX_RETRIES,
3660 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003662 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003664 mask, NL80211_MESHCONF_ELEMENT_TTL,
3665 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003666 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003667 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3668 nla_get_u8);
3669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3670 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3671 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003673 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3674 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003676 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3677 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003679 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3680 nla_get_u16);
3681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3682 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3683 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003685 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3686 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003688 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3689 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003691 dot11MeshHWMPnetDiameterTraversalTime, mask,
3692 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3693 nla_get_u16);
3694 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3695 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3697 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3698 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003700 dot11MeshGateAnnouncementProtocol, mask,
3701 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3702 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003704 mask, NL80211_MESHCONF_FORWARDING,
3705 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003706 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003707 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3708 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003710 mask, NL80211_MESHCONF_HT_OPMODE,
3711 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3713 mask,
3714 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3715 nla_get_u32);
3716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3717 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3718 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003719 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3720 dot11MeshHWMPconfirmationInterval, mask,
3721 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3722 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003723 if (mask_out)
3724 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003725
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003726 return 0;
3727
3728#undef FILL_IN_MESH_PARAM_IF_SET
3729}
3730
Javier Cardonac80d5452010-12-16 17:37:49 -08003731static int nl80211_parse_mesh_setup(struct genl_info *info,
3732 struct mesh_setup *setup)
3733{
3734 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3735
3736 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3737 return -EINVAL;
3738 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3739 info->attrs[NL80211_ATTR_MESH_SETUP],
3740 nl80211_mesh_setup_params_policy))
3741 return -EINVAL;
3742
Javier Cardonad299a1f2012-03-31 11:31:33 -07003743 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3744 setup->sync_method =
3745 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3746 IEEE80211_SYNC_METHOD_VENDOR :
3747 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3748
Javier Cardonac80d5452010-12-16 17:37:49 -08003749 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3750 setup->path_sel_proto =
3751 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3752 IEEE80211_PATH_PROTOCOL_VENDOR :
3753 IEEE80211_PATH_PROTOCOL_HWMP;
3754
3755 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3756 setup->path_metric =
3757 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3758 IEEE80211_PATH_METRIC_VENDOR :
3759 IEEE80211_PATH_METRIC_AIRTIME;
3760
Javier Cardona581a8b02011-04-07 15:08:27 -07003761
3762 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003763 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003764 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003765 if (!is_valid_ie_attr(ieattr))
3766 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003767 setup->ie = nla_data(ieattr);
3768 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003769 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003770 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3771 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003772
3773 return 0;
3774}
3775
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003776static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003777 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003778{
3779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3780 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003781 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003782 struct mesh_config cfg;
3783 u32 mask;
3784 int err;
3785
Johannes Berg29cbe682010-12-03 09:20:44 +01003786 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3787 return -EOPNOTSUPP;
3788
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003789 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003790 return -EOPNOTSUPP;
3791
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003792 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003793 if (err)
3794 return err;
3795
Johannes Berg29cbe682010-12-03 09:20:44 +01003796 wdev_lock(wdev);
3797 if (!wdev->mesh_id_len)
3798 err = -ENOLINK;
3799
3800 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003801 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003802 mask, &cfg);
3803
3804 wdev_unlock(wdev);
3805
3806 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003807}
3808
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003809static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3810{
3811 struct sk_buff *msg;
3812 void *hdr = NULL;
3813 struct nlattr *nl_reg_rules;
3814 unsigned int i;
3815 int err = -EINVAL;
3816
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003817 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003818
3819 if (!cfg80211_regdomain)
3820 goto out;
3821
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003822 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003823 if (!msg) {
3824 err = -ENOBUFS;
3825 goto out;
3826 }
3827
3828 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3829 NL80211_CMD_GET_REG);
3830 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003831 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003832
David S. Miller9360ffd2012-03-29 04:41:26 -04003833 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3834 cfg80211_regdomain->alpha2) ||
3835 (cfg80211_regdomain->dfs_region &&
3836 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3837 cfg80211_regdomain->dfs_region)))
3838 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003839
3840 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3841 if (!nl_reg_rules)
3842 goto nla_put_failure;
3843
3844 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3845 struct nlattr *nl_reg_rule;
3846 const struct ieee80211_reg_rule *reg_rule;
3847 const struct ieee80211_freq_range *freq_range;
3848 const struct ieee80211_power_rule *power_rule;
3849
3850 reg_rule = &cfg80211_regdomain->reg_rules[i];
3851 freq_range = &reg_rule->freq_range;
3852 power_rule = &reg_rule->power_rule;
3853
3854 nl_reg_rule = nla_nest_start(msg, i);
3855 if (!nl_reg_rule)
3856 goto nla_put_failure;
3857
David S. Miller9360ffd2012-03-29 04:41:26 -04003858 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3859 reg_rule->flags) ||
3860 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3861 freq_range->start_freq_khz) ||
3862 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3863 freq_range->end_freq_khz) ||
3864 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3865 freq_range->max_bandwidth_khz) ||
3866 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3867 power_rule->max_antenna_gain) ||
3868 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3869 power_rule->max_eirp))
3870 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003871
3872 nla_nest_end(msg, nl_reg_rule);
3873 }
3874
3875 nla_nest_end(msg, nl_reg_rules);
3876
3877 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003878 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003879 goto out;
3880
3881nla_put_failure:
3882 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003883put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003884 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003885 err = -EMSGSIZE;
3886out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003887 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003888 return err;
3889}
3890
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003891static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3892{
3893 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3894 struct nlattr *nl_reg_rule;
3895 char *alpha2 = NULL;
3896 int rem_reg_rules = 0, r = 0;
3897 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003898 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003899 struct ieee80211_regdomain *rd = NULL;
3900
3901 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3902 return -EINVAL;
3903
3904 if (!info->attrs[NL80211_ATTR_REG_RULES])
3905 return -EINVAL;
3906
3907 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3908
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003909 if (info->attrs[NL80211_ATTR_DFS_REGION])
3910 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3911
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003912 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3913 rem_reg_rules) {
3914 num_rules++;
3915 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003916 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003917 }
3918
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003919 mutex_lock(&cfg80211_mutex);
3920
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003921 if (!reg_is_valid_request(alpha2)) {
3922 r = -EINVAL;
3923 goto bad_reg;
3924 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003925
3926 size_of_regd = sizeof(struct ieee80211_regdomain) +
3927 (num_rules * sizeof(struct ieee80211_reg_rule));
3928
3929 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003930 if (!rd) {
3931 r = -ENOMEM;
3932 goto bad_reg;
3933 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003934
3935 rd->n_reg_rules = num_rules;
3936 rd->alpha2[0] = alpha2[0];
3937 rd->alpha2[1] = alpha2[1];
3938
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003939 /*
3940 * Disable DFS master mode if the DFS region was
3941 * not supported or known on this kernel.
3942 */
3943 if (reg_supported_dfs_region(dfs_region))
3944 rd->dfs_region = dfs_region;
3945
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003946 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3947 rem_reg_rules) {
3948 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3949 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3950 reg_rule_policy);
3951 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3952 if (r)
3953 goto bad_reg;
3954
3955 rule_idx++;
3956
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003957 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3958 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003959 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003960 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003961 }
3962
3963 BUG_ON(rule_idx != num_rules);
3964
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003965 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003966
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003967 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003968
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003969 return r;
3970
Johannes Bergd2372b32008-10-24 20:32:20 +02003971 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003972 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003973 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003974 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003975}
3976
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003977static int validate_scan_freqs(struct nlattr *freqs)
3978{
3979 struct nlattr *attr1, *attr2;
3980 int n_channels = 0, tmp1, tmp2;
3981
3982 nla_for_each_nested(attr1, freqs, tmp1) {
3983 n_channels++;
3984 /*
3985 * Some hardware has a limited channel list for
3986 * scanning, and it is pretty much nonsensical
3987 * to scan for a channel twice, so disallow that
3988 * and don't require drivers to check that the
3989 * channel list they get isn't longer than what
3990 * they can scan, as long as they can scan all
3991 * the channels they registered at once.
3992 */
3993 nla_for_each_nested(attr2, freqs, tmp2)
3994 if (attr1 != attr2 &&
3995 nla_get_u32(attr1) == nla_get_u32(attr2))
3996 return 0;
3997 }
3998
3999 return n_channels;
4000}
4001
Johannes Berg2a519312009-02-10 21:25:55 +01004002static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4003{
Johannes Berg4c476992010-10-04 21:36:35 +02004004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4005 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004006 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004007 struct nlattr *attr;
4008 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004009 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004010 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004011
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004012 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4013 return -EINVAL;
4014
Johannes Berg79c97e92009-07-07 03:56:12 +02004015 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004016
Johannes Berg4c476992010-10-04 21:36:35 +02004017 if (!rdev->ops->scan)
4018 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004019
Johannes Berg4c476992010-10-04 21:36:35 +02004020 if (rdev->scan_req)
4021 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004022
4023 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004024 n_channels = validate_scan_freqs(
4025 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004026 if (!n_channels)
4027 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004028 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004029 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004030 n_channels = 0;
4031
Johannes Berg2a519312009-02-10 21:25:55 +01004032 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4033 if (wiphy->bands[band])
4034 n_channels += wiphy->bands[band]->n_channels;
4035 }
4036
4037 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4038 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4039 n_ssids++;
4040
Johannes Berg4c476992010-10-04 21:36:35 +02004041 if (n_ssids > wiphy->max_scan_ssids)
4042 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004043
Jouni Malinen70692ad2009-02-16 19:39:13 +02004044 if (info->attrs[NL80211_ATTR_IE])
4045 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4046 else
4047 ie_len = 0;
4048
Johannes Berg4c476992010-10-04 21:36:35 +02004049 if (ie_len > wiphy->max_scan_ie_len)
4050 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004051
Johannes Berg2a519312009-02-10 21:25:55 +01004052 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004053 + sizeof(*request->ssids) * n_ssids
4054 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004055 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004056 if (!request)
4057 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004058
Johannes Berg2a519312009-02-10 21:25:55 +01004059 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004060 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004061 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004062 if (ie_len) {
4063 if (request->ssids)
4064 request->ie = (void *)(request->ssids + n_ssids);
4065 else
4066 request->ie = (void *)(request->channels + n_channels);
4067 }
Johannes Berg2a519312009-02-10 21:25:55 +01004068
Johannes Berg584991d2009-11-02 13:32:03 +01004069 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004070 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4071 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004072 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004073 struct ieee80211_channel *chan;
4074
4075 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4076
4077 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004078 err = -EINVAL;
4079 goto out_free;
4080 }
Johannes Berg584991d2009-11-02 13:32:03 +01004081
4082 /* ignore disabled channels */
4083 if (chan->flags & IEEE80211_CHAN_DISABLED)
4084 continue;
4085
4086 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004087 i++;
4088 }
4089 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004090 enum ieee80211_band band;
4091
Johannes Berg2a519312009-02-10 21:25:55 +01004092 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004093 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4094 int j;
4095 if (!wiphy->bands[band])
4096 continue;
4097 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004098 struct ieee80211_channel *chan;
4099
4100 chan = &wiphy->bands[band]->channels[j];
4101
4102 if (chan->flags & IEEE80211_CHAN_DISABLED)
4103 continue;
4104
4105 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004106 i++;
4107 }
4108 }
4109 }
4110
Johannes Berg584991d2009-11-02 13:32:03 +01004111 if (!i) {
4112 err = -EINVAL;
4113 goto out_free;
4114 }
4115
4116 request->n_channels = i;
4117
Johannes Berg2a519312009-02-10 21:25:55 +01004118 i = 0;
4119 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4120 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004121 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004122 err = -EINVAL;
4123 goto out_free;
4124 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004125 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004126 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004127 i++;
4128 }
4129 }
4130
Jouni Malinen70692ad2009-02-16 19:39:13 +02004131 if (info->attrs[NL80211_ATTR_IE]) {
4132 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004133 memcpy((void *)request->ie,
4134 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004135 request->ie_len);
4136 }
4137
Johannes Berg34850ab2011-07-18 18:08:35 +02004138 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004139 if (wiphy->bands[i])
4140 request->rates[i] =
4141 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004142
4143 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4144 nla_for_each_nested(attr,
4145 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4146 tmp) {
4147 enum ieee80211_band band = nla_type(attr);
4148
Dan Carpenter84404622011-07-29 11:52:18 +03004149 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004150 err = -EINVAL;
4151 goto out_free;
4152 }
4153 err = ieee80211_get_ratemask(wiphy->bands[band],
4154 nla_data(attr),
4155 nla_len(attr),
4156 &request->rates[band]);
4157 if (err)
4158 goto out_free;
4159 }
4160 }
4161
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304162 request->no_cck =
4163 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4164
Johannes Berg463d0182009-07-14 00:33:35 +02004165 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004166 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004167
Johannes Berg79c97e92009-07-07 03:56:12 +02004168 rdev->scan_req = request;
4169 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004170
Johannes Berg463d0182009-07-14 00:33:35 +02004171 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004172 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004173 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004174 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004175 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004176 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004177 kfree(request);
4178 }
Johannes Berg3b858752009-03-12 09:55:09 +01004179
Johannes Berg2a519312009-02-10 21:25:55 +01004180 return err;
4181}
4182
Luciano Coelho807f8a82011-05-11 17:09:35 +03004183static int nl80211_start_sched_scan(struct sk_buff *skb,
4184 struct genl_info *info)
4185{
4186 struct cfg80211_sched_scan_request *request;
4187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4188 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004189 struct nlattr *attr;
4190 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004191 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004192 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004193 enum ieee80211_band band;
4194 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004195 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004196
4197 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4198 !rdev->ops->sched_scan_start)
4199 return -EOPNOTSUPP;
4200
4201 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4202 return -EINVAL;
4203
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004204 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4205 return -EINVAL;
4206
4207 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4208 if (interval == 0)
4209 return -EINVAL;
4210
Luciano Coelho807f8a82011-05-11 17:09:35 +03004211 wiphy = &rdev->wiphy;
4212
4213 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4214 n_channels = validate_scan_freqs(
4215 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4216 if (!n_channels)
4217 return -EINVAL;
4218 } else {
4219 n_channels = 0;
4220
4221 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4222 if (wiphy->bands[band])
4223 n_channels += wiphy->bands[band]->n_channels;
4224 }
4225
4226 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4227 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4228 tmp)
4229 n_ssids++;
4230
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004231 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004232 return -EINVAL;
4233
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004234 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4235 nla_for_each_nested(attr,
4236 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4237 tmp)
4238 n_match_sets++;
4239
4240 if (n_match_sets > wiphy->max_match_sets)
4241 return -EINVAL;
4242
Luciano Coelho807f8a82011-05-11 17:09:35 +03004243 if (info->attrs[NL80211_ATTR_IE])
4244 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4245 else
4246 ie_len = 0;
4247
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004248 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004249 return -EINVAL;
4250
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004251 mutex_lock(&rdev->sched_scan_mtx);
4252
4253 if (rdev->sched_scan_req) {
4254 err = -EINPROGRESS;
4255 goto out;
4256 }
4257
Luciano Coelho807f8a82011-05-11 17:09:35 +03004258 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004259 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004260 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004261 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004262 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004263 if (!request) {
4264 err = -ENOMEM;
4265 goto out;
4266 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004267
4268 if (n_ssids)
4269 request->ssids = (void *)&request->channels[n_channels];
4270 request->n_ssids = n_ssids;
4271 if (ie_len) {
4272 if (request->ssids)
4273 request->ie = (void *)(request->ssids + n_ssids);
4274 else
4275 request->ie = (void *)(request->channels + n_channels);
4276 }
4277
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004278 if (n_match_sets) {
4279 if (request->ie)
4280 request->match_sets = (void *)(request->ie + ie_len);
4281 else if (request->ssids)
4282 request->match_sets =
4283 (void *)(request->ssids + n_ssids);
4284 else
4285 request->match_sets =
4286 (void *)(request->channels + n_channels);
4287 }
4288 request->n_match_sets = n_match_sets;
4289
Luciano Coelho807f8a82011-05-11 17:09:35 +03004290 i = 0;
4291 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4292 /* user specified, bail out if channel not found */
4293 nla_for_each_nested(attr,
4294 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4295 tmp) {
4296 struct ieee80211_channel *chan;
4297
4298 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4299
4300 if (!chan) {
4301 err = -EINVAL;
4302 goto out_free;
4303 }
4304
4305 /* ignore disabled channels */
4306 if (chan->flags & IEEE80211_CHAN_DISABLED)
4307 continue;
4308
4309 request->channels[i] = chan;
4310 i++;
4311 }
4312 } else {
4313 /* all channels */
4314 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4315 int j;
4316 if (!wiphy->bands[band])
4317 continue;
4318 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4319 struct ieee80211_channel *chan;
4320
4321 chan = &wiphy->bands[band]->channels[j];
4322
4323 if (chan->flags & IEEE80211_CHAN_DISABLED)
4324 continue;
4325
4326 request->channels[i] = chan;
4327 i++;
4328 }
4329 }
4330 }
4331
4332 if (!i) {
4333 err = -EINVAL;
4334 goto out_free;
4335 }
4336
4337 request->n_channels = i;
4338
4339 i = 0;
4340 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4341 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4342 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004343 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004344 err = -EINVAL;
4345 goto out_free;
4346 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004347 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004348 memcpy(request->ssids[i].ssid, nla_data(attr),
4349 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004350 i++;
4351 }
4352 }
4353
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004354 i = 0;
4355 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4356 nla_for_each_nested(attr,
4357 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4358 tmp) {
4359 struct nlattr *ssid;
4360
4361 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4362 nla_data(attr), nla_len(attr),
4363 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004364 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004365 if (ssid) {
4366 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4367 err = -EINVAL;
4368 goto out_free;
4369 }
4370 memcpy(request->match_sets[i].ssid.ssid,
4371 nla_data(ssid), nla_len(ssid));
4372 request->match_sets[i].ssid.ssid_len =
4373 nla_len(ssid);
4374 }
4375 i++;
4376 }
4377 }
4378
Luciano Coelho807f8a82011-05-11 17:09:35 +03004379 if (info->attrs[NL80211_ATTR_IE]) {
4380 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4381 memcpy((void *)request->ie,
4382 nla_data(info->attrs[NL80211_ATTR_IE]),
4383 request->ie_len);
4384 }
4385
4386 request->dev = dev;
4387 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004388 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004389
4390 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4391 if (!err) {
4392 rdev->sched_scan_req = request;
4393 nl80211_send_sched_scan(rdev, dev,
4394 NL80211_CMD_START_SCHED_SCAN);
4395 goto out;
4396 }
4397
4398out_free:
4399 kfree(request);
4400out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004401 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004402 return err;
4403}
4404
4405static int nl80211_stop_sched_scan(struct sk_buff *skb,
4406 struct genl_info *info)
4407{
4408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004409 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004410
4411 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4412 !rdev->ops->sched_scan_stop)
4413 return -EOPNOTSUPP;
4414
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004415 mutex_lock(&rdev->sched_scan_mtx);
4416 err = __cfg80211_stop_sched_scan(rdev, false);
4417 mutex_unlock(&rdev->sched_scan_mtx);
4418
4419 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004420}
4421
Johannes Berg9720bb32011-06-21 09:45:33 +02004422static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4423 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004424 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004425 struct wireless_dev *wdev,
4426 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004427{
Johannes Berg48ab9052009-07-10 18:42:31 +02004428 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004429 void *hdr;
4430 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004431
4432 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004433
Johannes Berg9720bb32011-06-21 09:45:33 +02004434 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004435 NL80211_CMD_NEW_SCAN_RESULTS);
4436 if (!hdr)
4437 return -1;
4438
Johannes Berg9720bb32011-06-21 09:45:33 +02004439 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4440
David S. Miller9360ffd2012-03-29 04:41:26 -04004441 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4442 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4443 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004444
4445 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4446 if (!bss)
4447 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004448 if ((!is_zero_ether_addr(res->bssid) &&
4449 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4450 (res->information_elements && res->len_information_elements &&
4451 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4452 res->len_information_elements,
4453 res->information_elements)) ||
4454 (res->beacon_ies && res->len_beacon_ies &&
4455 res->beacon_ies != res->information_elements &&
4456 nla_put(msg, NL80211_BSS_BEACON_IES,
4457 res->len_beacon_ies, res->beacon_ies)))
4458 goto nla_put_failure;
4459 if (res->tsf &&
4460 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4461 goto nla_put_failure;
4462 if (res->beacon_interval &&
4463 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4464 goto nla_put_failure;
4465 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4466 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4467 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4468 jiffies_to_msecs(jiffies - intbss->ts)))
4469 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004470
Johannes Berg77965c92009-02-18 18:45:06 +01004471 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004472 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004473 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4474 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004475 break;
4476 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004477 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4478 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004479 break;
4480 default:
4481 break;
4482 }
4483
Johannes Berg48ab9052009-07-10 18:42:31 +02004484 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004485 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004486 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004487 if (intbss == wdev->current_bss &&
4488 nla_put_u32(msg, NL80211_BSS_STATUS,
4489 NL80211_BSS_STATUS_ASSOCIATED))
4490 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004491 break;
4492 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004493 if (intbss == wdev->current_bss &&
4494 nla_put_u32(msg, NL80211_BSS_STATUS,
4495 NL80211_BSS_STATUS_IBSS_JOINED))
4496 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004497 break;
4498 default:
4499 break;
4500 }
4501
Johannes Berg2a519312009-02-10 21:25:55 +01004502 nla_nest_end(msg, bss);
4503
4504 return genlmsg_end(msg, hdr);
4505
4506 nla_put_failure:
4507 genlmsg_cancel(msg, hdr);
4508 return -EMSGSIZE;
4509}
4510
4511static int nl80211_dump_scan(struct sk_buff *skb,
4512 struct netlink_callback *cb)
4513{
Johannes Berg48ab9052009-07-10 18:42:31 +02004514 struct cfg80211_registered_device *rdev;
4515 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004516 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004517 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004518 int start = cb->args[1], idx = 0;
4519 int err;
4520
Johannes Berg67748892010-10-04 21:14:06 +02004521 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4522 if (err)
4523 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004524
Johannes Berg48ab9052009-07-10 18:42:31 +02004525 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004526
Johannes Berg48ab9052009-07-10 18:42:31 +02004527 wdev_lock(wdev);
4528 spin_lock_bh(&rdev->bss_lock);
4529 cfg80211_bss_expire(rdev);
4530
Johannes Berg9720bb32011-06-21 09:45:33 +02004531 cb->seq = rdev->bss_generation;
4532
Johannes Berg48ab9052009-07-10 18:42:31 +02004533 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004534 if (++idx <= start)
4535 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004536 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004537 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004538 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004539 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004540 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004541 }
4542 }
4543
Johannes Berg48ab9052009-07-10 18:42:31 +02004544 spin_unlock_bh(&rdev->bss_lock);
4545 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004546
4547 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004548 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004549
Johannes Berg67748892010-10-04 21:14:06 +02004550 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004551}
4552
Holger Schurig61fa7132009-11-11 12:25:40 +01004553static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4554 int flags, struct net_device *dev,
4555 struct survey_info *survey)
4556{
4557 void *hdr;
4558 struct nlattr *infoattr;
4559
Holger Schurig61fa7132009-11-11 12:25:40 +01004560 hdr = nl80211hdr_put(msg, pid, seq, flags,
4561 NL80211_CMD_NEW_SURVEY_RESULTS);
4562 if (!hdr)
4563 return -ENOMEM;
4564
David S. Miller9360ffd2012-03-29 04:41:26 -04004565 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4566 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004567
4568 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4569 if (!infoattr)
4570 goto nla_put_failure;
4571
David S. Miller9360ffd2012-03-29 04:41:26 -04004572 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4573 survey->channel->center_freq))
4574 goto nla_put_failure;
4575
4576 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4577 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4578 goto nla_put_failure;
4579 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4580 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4581 goto nla_put_failure;
4582 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4583 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4584 survey->channel_time))
4585 goto nla_put_failure;
4586 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4587 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4588 survey->channel_time_busy))
4589 goto nla_put_failure;
4590 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4591 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4592 survey->channel_time_ext_busy))
4593 goto nla_put_failure;
4594 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4595 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4596 survey->channel_time_rx))
4597 goto nla_put_failure;
4598 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4599 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4600 survey->channel_time_tx))
4601 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004602
4603 nla_nest_end(msg, infoattr);
4604
4605 return genlmsg_end(msg, hdr);
4606
4607 nla_put_failure:
4608 genlmsg_cancel(msg, hdr);
4609 return -EMSGSIZE;
4610}
4611
4612static int nl80211_dump_survey(struct sk_buff *skb,
4613 struct netlink_callback *cb)
4614{
4615 struct survey_info survey;
4616 struct cfg80211_registered_device *dev;
4617 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004618 int survey_idx = cb->args[1];
4619 int res;
4620
Johannes Berg67748892010-10-04 21:14:06 +02004621 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4622 if (res)
4623 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004624
4625 if (!dev->ops->dump_survey) {
4626 res = -EOPNOTSUPP;
4627 goto out_err;
4628 }
4629
4630 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004631 struct ieee80211_channel *chan;
4632
Holger Schurig61fa7132009-11-11 12:25:40 +01004633 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4634 &survey);
4635 if (res == -ENOENT)
4636 break;
4637 if (res)
4638 goto out_err;
4639
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004640 /* Survey without a channel doesn't make sense */
4641 if (!survey.channel) {
4642 res = -EINVAL;
4643 goto out;
4644 }
4645
4646 chan = ieee80211_get_channel(&dev->wiphy,
4647 survey.channel->center_freq);
4648 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4649 survey_idx++;
4650 continue;
4651 }
4652
Holger Schurig61fa7132009-11-11 12:25:40 +01004653 if (nl80211_send_survey(skb,
4654 NETLINK_CB(cb->skb).pid,
4655 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4656 netdev,
4657 &survey) < 0)
4658 goto out;
4659 survey_idx++;
4660 }
4661
4662 out:
4663 cb->args[1] = survey_idx;
4664 res = skb->len;
4665 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004666 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004667 return res;
4668}
4669
Jouni Malinen255e7372009-03-20 21:21:17 +02004670static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4671{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004672 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004673}
4674
Samuel Ortizb23aa672009-07-01 21:26:54 +02004675static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4676{
4677 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4678 NL80211_WPA_VERSION_2));
4679}
4680
Jouni Malinen636a5d32009-03-19 13:39:22 +02004681static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4682{
Johannes Berg4c476992010-10-04 21:36:35 +02004683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4684 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004685 struct ieee80211_channel *chan;
4686 const u8 *bssid, *ssid, *ie = NULL;
4687 int err, ssid_len, ie_len = 0;
4688 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004689 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004690 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004691
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004692 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4693 return -EINVAL;
4694
4695 if (!info->attrs[NL80211_ATTR_MAC])
4696 return -EINVAL;
4697
Jouni Malinen17780922009-03-27 20:52:47 +02004698 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4699 return -EINVAL;
4700
Johannes Berg19957bb2009-07-02 17:20:43 +02004701 if (!info->attrs[NL80211_ATTR_SSID])
4702 return -EINVAL;
4703
4704 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4705 return -EINVAL;
4706
Johannes Bergfffd0932009-07-08 14:22:54 +02004707 err = nl80211_parse_key(info, &key);
4708 if (err)
4709 return err;
4710
4711 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004712 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4713 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004714 if (!key.p.key || !key.p.key_len)
4715 return -EINVAL;
4716 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4717 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4718 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4719 key.p.key_len != WLAN_KEY_LEN_WEP104))
4720 return -EINVAL;
4721 if (key.idx > 4)
4722 return -EINVAL;
4723 } else {
4724 key.p.key_len = 0;
4725 key.p.key = NULL;
4726 }
4727
Johannes Bergafea0b72010-08-10 09:46:42 +02004728 if (key.idx >= 0) {
4729 int i;
4730 bool ok = false;
4731 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4732 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4733 ok = true;
4734 break;
4735 }
4736 }
Johannes Berg4c476992010-10-04 21:36:35 +02004737 if (!ok)
4738 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004739 }
4740
Johannes Berg4c476992010-10-04 21:36:35 +02004741 if (!rdev->ops->auth)
4742 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004743
Johannes Berg074ac8d2010-09-16 14:58:22 +02004744 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004745 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4746 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004747
Johannes Berg19957bb2009-07-02 17:20:43 +02004748 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004749 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004750 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004751 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4752 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004753
Johannes Berg19957bb2009-07-02 17:20:43 +02004754 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4755 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4756
4757 if (info->attrs[NL80211_ATTR_IE]) {
4758 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4759 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4760 }
4761
4762 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004763 if (!nl80211_valid_auth_type(auth_type))
4764 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004765
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004766 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4767
Johannes Berg95de8172012-01-20 13:55:25 +01004768 /*
4769 * Since we no longer track auth state, ignore
4770 * requests to only change local state.
4771 */
4772 if (local_state_change)
4773 return 0;
4774
Johannes Berg4c476992010-10-04 21:36:35 +02004775 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4776 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004777 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004778}
4779
Johannes Bergc0692b82010-08-27 14:26:53 +03004780static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4781 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004782 struct cfg80211_crypto_settings *settings,
4783 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004784{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004785 memset(settings, 0, sizeof(*settings));
4786
Samuel Ortizb23aa672009-07-01 21:26:54 +02004787 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4788
Johannes Bergc0692b82010-08-27 14:26:53 +03004789 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4790 u16 proto;
4791 proto = nla_get_u16(
4792 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4793 settings->control_port_ethertype = cpu_to_be16(proto);
4794 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4795 proto != ETH_P_PAE)
4796 return -EINVAL;
4797 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4798 settings->control_port_no_encrypt = true;
4799 } else
4800 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4801
Samuel Ortizb23aa672009-07-01 21:26:54 +02004802 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4803 void *data;
4804 int len, i;
4805
4806 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4807 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4808 settings->n_ciphers_pairwise = len / sizeof(u32);
4809
4810 if (len % sizeof(u32))
4811 return -EINVAL;
4812
Johannes Berg3dc27d22009-07-02 21:36:37 +02004813 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004814 return -EINVAL;
4815
4816 memcpy(settings->ciphers_pairwise, data, len);
4817
4818 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004819 if (!cfg80211_supported_cipher_suite(
4820 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004821 settings->ciphers_pairwise[i]))
4822 return -EINVAL;
4823 }
4824
4825 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4826 settings->cipher_group =
4827 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004828 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4829 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004830 return -EINVAL;
4831 }
4832
4833 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4834 settings->wpa_versions =
4835 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4836 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4837 return -EINVAL;
4838 }
4839
4840 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4841 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004842 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004843
4844 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4845 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4846 settings->n_akm_suites = len / sizeof(u32);
4847
4848 if (len % sizeof(u32))
4849 return -EINVAL;
4850
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004851 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4852 return -EINVAL;
4853
Samuel Ortizb23aa672009-07-01 21:26:54 +02004854 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004855 }
4856
4857 return 0;
4858}
4859
Jouni Malinen636a5d32009-03-19 13:39:22 +02004860static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4861{
Johannes Berg4c476992010-10-04 21:36:35 +02004862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4863 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004864 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004865 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004866 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004867 int err, ssid_len, ie_len = 0;
4868 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004869 u32 flags = 0;
4870 struct ieee80211_ht_cap *ht_capa = NULL;
4871 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004872
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004873 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4874 return -EINVAL;
4875
4876 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004877 !info->attrs[NL80211_ATTR_SSID] ||
4878 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004879 return -EINVAL;
4880
Johannes Berg4c476992010-10-04 21:36:35 +02004881 if (!rdev->ops->assoc)
4882 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004883
Johannes Berg074ac8d2010-09-16 14:58:22 +02004884 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004885 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4886 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004887
Johannes Berg19957bb2009-07-02 17:20:43 +02004888 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004889
Johannes Berg19957bb2009-07-02 17:20:43 +02004890 chan = ieee80211_get_channel(&rdev->wiphy,
4891 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004892 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4893 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004894
Johannes Berg19957bb2009-07-02 17:20:43 +02004895 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4896 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004897
4898 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004899 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4900 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004901 }
4902
Jouni Malinendc6382c2009-05-06 22:09:37 +03004903 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004904 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004905 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004906 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004907 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004908 else if (mfp != NL80211_MFP_NO)
4909 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004910 }
4911
Johannes Berg3e5d7642009-07-07 14:37:26 +02004912 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4913 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4914
Ben Greear7e7c8922011-11-18 11:31:59 -08004915 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4916 flags |= ASSOC_REQ_DISABLE_HT;
4917
4918 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4919 ht_capa_mask =
4920 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4921
4922 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4923 if (!ht_capa_mask)
4924 return -EINVAL;
4925 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4926 }
4927
Johannes Bergc0692b82010-08-27 14:26:53 +03004928 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004929 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004930 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4931 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004932 &crypto, flags, ht_capa,
4933 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004934
Jouni Malinen636a5d32009-03-19 13:39:22 +02004935 return err;
4936}
4937
4938static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4939{
Johannes Berg4c476992010-10-04 21:36:35 +02004940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4941 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004942 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004943 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004944 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004945 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004946
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004947 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4948 return -EINVAL;
4949
4950 if (!info->attrs[NL80211_ATTR_MAC])
4951 return -EINVAL;
4952
4953 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4954 return -EINVAL;
4955
Johannes Berg4c476992010-10-04 21:36:35 +02004956 if (!rdev->ops->deauth)
4957 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004958
Johannes Berg074ac8d2010-09-16 14:58:22 +02004959 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4961 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004962
Johannes Berg19957bb2009-07-02 17:20:43 +02004963 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004964
Johannes Berg19957bb2009-07-02 17:20:43 +02004965 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4966 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004967 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004968 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004969 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004970
4971 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004972 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4973 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004974 }
4975
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004976 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4977
Johannes Berg4c476992010-10-04 21:36:35 +02004978 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4979 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004980}
4981
4982static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4983{
Johannes Berg4c476992010-10-04 21:36:35 +02004984 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4985 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004986 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004987 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004988 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004989 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004990
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004991 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4992 return -EINVAL;
4993
4994 if (!info->attrs[NL80211_ATTR_MAC])
4995 return -EINVAL;
4996
4997 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4998 return -EINVAL;
4999
Johannes Berg4c476992010-10-04 21:36:35 +02005000 if (!rdev->ops->disassoc)
5001 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005002
Johannes Berg074ac8d2010-09-16 14:58:22 +02005003 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005004 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5005 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005006
Johannes Berg19957bb2009-07-02 17:20:43 +02005007 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005008
Johannes Berg19957bb2009-07-02 17:20:43 +02005009 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5010 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005011 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005012 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005013 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005014
5015 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005016 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5017 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005018 }
5019
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005020 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5021
Johannes Berg4c476992010-10-04 21:36:35 +02005022 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5023 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005024}
5025
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005026static bool
5027nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5028 int mcast_rate[IEEE80211_NUM_BANDS],
5029 int rateval)
5030{
5031 struct wiphy *wiphy = &rdev->wiphy;
5032 bool found = false;
5033 int band, i;
5034
5035 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5036 struct ieee80211_supported_band *sband;
5037
5038 sband = wiphy->bands[band];
5039 if (!sband)
5040 continue;
5041
5042 for (i = 0; i < sband->n_bitrates; i++) {
5043 if (sband->bitrates[i].bitrate == rateval) {
5044 mcast_rate[band] = i + 1;
5045 found = true;
5046 break;
5047 }
5048 }
5049 }
5050
5051 return found;
5052}
5053
Johannes Berg04a773a2009-04-19 21:24:32 +02005054static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5055{
Johannes Berg4c476992010-10-04 21:36:35 +02005056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5057 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005058 struct cfg80211_ibss_params ibss;
5059 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005060 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005061 int err;
5062
Johannes Berg8e30bc52009-04-22 17:45:38 +02005063 memset(&ibss, 0, sizeof(ibss));
5064
Johannes Berg04a773a2009-04-19 21:24:32 +02005065 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5066 return -EINVAL;
5067
5068 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5069 !info->attrs[NL80211_ATTR_SSID] ||
5070 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5071 return -EINVAL;
5072
Johannes Berg8e30bc52009-04-22 17:45:38 +02005073 ibss.beacon_interval = 100;
5074
5075 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5076 ibss.beacon_interval =
5077 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5078 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5079 return -EINVAL;
5080 }
5081
Johannes Berg4c476992010-10-04 21:36:35 +02005082 if (!rdev->ops->join_ibss)
5083 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005084
Johannes Berg4c476992010-10-04 21:36:35 +02005085 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5086 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005087
Johannes Berg79c97e92009-07-07 03:56:12 +02005088 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005089
Johannes Berg39193492011-09-16 13:45:25 +02005090 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005091 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005092
5093 if (!is_valid_ether_addr(ibss.bssid))
5094 return -EINVAL;
5095 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005096 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5097 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5098
5099 if (info->attrs[NL80211_ATTR_IE]) {
5100 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5101 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5102 }
5103
Alexander Simon54858ee2011-11-30 16:56:32 +01005104 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5105 enum nl80211_channel_type channel_type;
5106
Johannes Bergcd6c6592012-05-10 21:27:18 +02005107 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee2011-11-30 16:56:32 +01005108 return -EINVAL;
5109
5110 if (channel_type != NL80211_CHAN_NO_HT &&
5111 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5112 return -EINVAL;
5113
5114 ibss.channel_type = channel_type;
5115 } else {
5116 ibss.channel_type = NL80211_CHAN_NO_HT;
5117 }
5118
5119 ibss.channel = rdev_freq_to_chan(rdev,
5120 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5121 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005122 if (!ibss.channel ||
5123 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005124 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5125 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005126
Alexander Simon54858ee2011-11-30 16:56:32 +01005127 /* Both channels should be able to initiate communication */
5128 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5129 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5130 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5131 ibss.channel_type))
5132 return -EINVAL;
5133
Johannes Berg04a773a2009-04-19 21:24:32 +02005134 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005135 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005136
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005137 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5138 u8 *rates =
5139 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5140 int n_rates =
5141 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5142 struct ieee80211_supported_band *sband =
5143 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005144
Johannes Berg34850ab2011-07-18 18:08:35 +02005145 err = ieee80211_get_ratemask(sband, rates, n_rates,
5146 &ibss.basic_rates);
5147 if (err)
5148 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005149 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005150
5151 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5152 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5153 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5154 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005155
Johannes Berg4c476992010-10-04 21:36:35 +02005156 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5157 connkeys = nl80211_parse_connkeys(rdev,
5158 info->attrs[NL80211_ATTR_KEYS]);
5159 if (IS_ERR(connkeys))
5160 return PTR_ERR(connkeys);
5161 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005162
Antonio Quartulli267335d2012-01-31 20:25:47 +01005163 ibss.control_port =
5164 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5165
Johannes Berg4c476992010-10-04 21:36:35 +02005166 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005167 if (err)
5168 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005169 return err;
5170}
5171
5172static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5173{
Johannes Berg4c476992010-10-04 21:36:35 +02005174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5175 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005176
Johannes Berg4c476992010-10-04 21:36:35 +02005177 if (!rdev->ops->leave_ibss)
5178 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005179
Johannes Berg4c476992010-10-04 21:36:35 +02005180 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5181 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005182
Johannes Berg4c476992010-10-04 21:36:35 +02005183 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005184}
5185
Johannes Bergaff89a92009-07-01 21:26:51 +02005186#ifdef CONFIG_NL80211_TESTMODE
5187static struct genl_multicast_group nl80211_testmode_mcgrp = {
5188 .name = "testmode",
5189};
5190
5191static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5192{
Johannes Berg4c476992010-10-04 21:36:35 +02005193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005194 int err;
5195
5196 if (!info->attrs[NL80211_ATTR_TESTDATA])
5197 return -EINVAL;
5198
Johannes Bergaff89a92009-07-01 21:26:51 +02005199 err = -EOPNOTSUPP;
5200 if (rdev->ops->testmode_cmd) {
5201 rdev->testmode_info = info;
5202 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5203 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5204 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5205 rdev->testmode_info = NULL;
5206 }
5207
Johannes Bergaff89a92009-07-01 21:26:51 +02005208 return err;
5209}
5210
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005211static int nl80211_testmode_dump(struct sk_buff *skb,
5212 struct netlink_callback *cb)
5213{
Johannes Berg00918d32011-12-13 17:22:05 +01005214 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005215 int err;
5216 long phy_idx;
5217 void *data = NULL;
5218 int data_len = 0;
5219
5220 if (cb->args[0]) {
5221 /*
5222 * 0 is a valid index, but not valid for args[0],
5223 * so we need to offset by 1.
5224 */
5225 phy_idx = cb->args[0] - 1;
5226 } else {
5227 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5228 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5229 nl80211_policy);
5230 if (err)
5231 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005232 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
5233 phy_idx = nla_get_u32(
5234 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
5235 } else {
5236 struct net_device *netdev;
5237
5238 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
5239 nl80211_fam.attrbuf,
5240 &rdev, &netdev);
5241 if (err)
5242 return err;
5243 dev_put(netdev);
5244 phy_idx = rdev->wiphy_idx;
5245 cfg80211_unlock_rdev(rdev);
5246 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005247 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5248 cb->args[1] =
5249 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5250 }
5251
5252 if (cb->args[1]) {
5253 data = nla_data((void *)cb->args[1]);
5254 data_len = nla_len((void *)cb->args[1]);
5255 }
5256
5257 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005258 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5259 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005260 mutex_unlock(&cfg80211_mutex);
5261 return -ENOENT;
5262 }
Johannes Berg00918d32011-12-13 17:22:05 +01005263 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005264 mutex_unlock(&cfg80211_mutex);
5265
Johannes Berg00918d32011-12-13 17:22:05 +01005266 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005267 err = -EOPNOTSUPP;
5268 goto out_err;
5269 }
5270
5271 while (1) {
5272 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5273 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5274 NL80211_CMD_TESTMODE);
5275 struct nlattr *tmdata;
5276
David S. Miller9360ffd2012-03-29 04:41:26 -04005277 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005278 genlmsg_cancel(skb, hdr);
5279 break;
5280 }
5281
5282 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5283 if (!tmdata) {
5284 genlmsg_cancel(skb, hdr);
5285 break;
5286 }
Johannes Berg00918d32011-12-13 17:22:05 +01005287 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5288 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005289 nla_nest_end(skb, tmdata);
5290
5291 if (err == -ENOBUFS || err == -ENOENT) {
5292 genlmsg_cancel(skb, hdr);
5293 break;
5294 } else if (err) {
5295 genlmsg_cancel(skb, hdr);
5296 goto out_err;
5297 }
5298
5299 genlmsg_end(skb, hdr);
5300 }
5301
5302 err = skb->len;
5303 /* see above */
5304 cb->args[0] = phy_idx + 1;
5305 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005306 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005307 return err;
5308}
5309
Johannes Bergaff89a92009-07-01 21:26:51 +02005310static struct sk_buff *
5311__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5312 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5313{
5314 struct sk_buff *skb;
5315 void *hdr;
5316 struct nlattr *data;
5317
5318 skb = nlmsg_new(approxlen + 100, gfp);
5319 if (!skb)
5320 return NULL;
5321
5322 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5323 if (!hdr) {
5324 kfree_skb(skb);
5325 return NULL;
5326 }
5327
David S. Miller9360ffd2012-03-29 04:41:26 -04005328 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5329 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005330 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5331
5332 ((void **)skb->cb)[0] = rdev;
5333 ((void **)skb->cb)[1] = hdr;
5334 ((void **)skb->cb)[2] = data;
5335
5336 return skb;
5337
5338 nla_put_failure:
5339 kfree_skb(skb);
5340 return NULL;
5341}
5342
5343struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5344 int approxlen)
5345{
5346 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5347
5348 if (WARN_ON(!rdev->testmode_info))
5349 return NULL;
5350
5351 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5352 rdev->testmode_info->snd_pid,
5353 rdev->testmode_info->snd_seq,
5354 GFP_KERNEL);
5355}
5356EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5357
5358int cfg80211_testmode_reply(struct sk_buff *skb)
5359{
5360 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5361 void *hdr = ((void **)skb->cb)[1];
5362 struct nlattr *data = ((void **)skb->cb)[2];
5363
5364 if (WARN_ON(!rdev->testmode_info)) {
5365 kfree_skb(skb);
5366 return -EINVAL;
5367 }
5368
5369 nla_nest_end(skb, data);
5370 genlmsg_end(skb, hdr);
5371 return genlmsg_reply(skb, rdev->testmode_info);
5372}
5373EXPORT_SYMBOL(cfg80211_testmode_reply);
5374
5375struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5376 int approxlen, gfp_t gfp)
5377{
5378 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5379
5380 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5381}
5382EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5383
5384void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5385{
5386 void *hdr = ((void **)skb->cb)[1];
5387 struct nlattr *data = ((void **)skb->cb)[2];
5388
5389 nla_nest_end(skb, data);
5390 genlmsg_end(skb, hdr);
5391 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5392}
5393EXPORT_SYMBOL(cfg80211_testmode_event);
5394#endif
5395
Samuel Ortizb23aa672009-07-01 21:26:54 +02005396static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5397{
Johannes Berg4c476992010-10-04 21:36:35 +02005398 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5399 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005400 struct cfg80211_connect_params connect;
5401 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005402 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005403 int err;
5404
5405 memset(&connect, 0, sizeof(connect));
5406
5407 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5408 return -EINVAL;
5409
5410 if (!info->attrs[NL80211_ATTR_SSID] ||
5411 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5412 return -EINVAL;
5413
5414 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5415 connect.auth_type =
5416 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5417 if (!nl80211_valid_auth_type(connect.auth_type))
5418 return -EINVAL;
5419 } else
5420 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5421
5422 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5423
Johannes Bergc0692b82010-08-27 14:26:53 +03005424 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005425 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005426 if (err)
5427 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005428
Johannes Berg074ac8d2010-09-16 14:58:22 +02005429 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005430 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5431 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005432
Johannes Berg79c97e92009-07-07 03:56:12 +02005433 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005434
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305435 connect.bg_scan_period = -1;
5436 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5437 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5438 connect.bg_scan_period =
5439 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5440 }
5441
Samuel Ortizb23aa672009-07-01 21:26:54 +02005442 if (info->attrs[NL80211_ATTR_MAC])
5443 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5444 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5445 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5446
5447 if (info->attrs[NL80211_ATTR_IE]) {
5448 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5449 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5450 }
5451
5452 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5453 connect.channel =
5454 ieee80211_get_channel(wiphy,
5455 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5456 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005457 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5458 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005459 }
5460
Johannes Bergfffd0932009-07-08 14:22:54 +02005461 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5462 connkeys = nl80211_parse_connkeys(rdev,
5463 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005464 if (IS_ERR(connkeys))
5465 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005466 }
5467
Ben Greear7e7c8922011-11-18 11:31:59 -08005468 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5469 connect.flags |= ASSOC_REQ_DISABLE_HT;
5470
5471 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5472 memcpy(&connect.ht_capa_mask,
5473 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5474 sizeof(connect.ht_capa_mask));
5475
5476 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5477 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5478 return -EINVAL;
5479 memcpy(&connect.ht_capa,
5480 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5481 sizeof(connect.ht_capa));
5482 }
5483
Johannes Bergfffd0932009-07-08 14:22:54 +02005484 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005485 if (err)
5486 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005487 return err;
5488}
5489
5490static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5491{
Johannes Berg4c476992010-10-04 21:36:35 +02005492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5493 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005494 u16 reason;
5495
5496 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5497 reason = WLAN_REASON_DEAUTH_LEAVING;
5498 else
5499 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5500
5501 if (reason == 0)
5502 return -EINVAL;
5503
Johannes Berg074ac8d2010-09-16 14:58:22 +02005504 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005505 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5506 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005507
Johannes Berg4c476992010-10-04 21:36:35 +02005508 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005509}
5510
Johannes Berg463d0182009-07-14 00:33:35 +02005511static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5512{
Johannes Berg4c476992010-10-04 21:36:35 +02005513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005514 struct net *net;
5515 int err;
5516 u32 pid;
5517
5518 if (!info->attrs[NL80211_ATTR_PID])
5519 return -EINVAL;
5520
5521 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5522
Johannes Berg463d0182009-07-14 00:33:35 +02005523 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005524 if (IS_ERR(net))
5525 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005526
5527 err = 0;
5528
5529 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005530 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5531 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005532
Johannes Berg463d0182009-07-14 00:33:35 +02005533 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005534 return err;
5535}
5536
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005537static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5538{
Johannes Berg4c476992010-10-04 21:36:35 +02005539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005540 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5541 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005542 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005543 struct cfg80211_pmksa pmksa;
5544
5545 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5546
5547 if (!info->attrs[NL80211_ATTR_MAC])
5548 return -EINVAL;
5549
5550 if (!info->attrs[NL80211_ATTR_PMKID])
5551 return -EINVAL;
5552
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005553 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5554 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5555
Johannes Berg074ac8d2010-09-16 14:58:22 +02005556 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005557 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5558 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005559
5560 switch (info->genlhdr->cmd) {
5561 case NL80211_CMD_SET_PMKSA:
5562 rdev_ops = rdev->ops->set_pmksa;
5563 break;
5564 case NL80211_CMD_DEL_PMKSA:
5565 rdev_ops = rdev->ops->del_pmksa;
5566 break;
5567 default:
5568 WARN_ON(1);
5569 break;
5570 }
5571
Johannes Berg4c476992010-10-04 21:36:35 +02005572 if (!rdev_ops)
5573 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005574
Johannes Berg4c476992010-10-04 21:36:35 +02005575 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005576}
5577
5578static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5579{
Johannes Berg4c476992010-10-04 21:36:35 +02005580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5581 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005582
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
Johannes Berg4c476992010-10-04 21:36:35 +02005587 if (!rdev->ops->flush_pmksa)
5588 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005589
Johannes Berg4c476992010-10-04 21:36:35 +02005590 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005591}
5592
Arik Nemtsov109086c2011-09-28 14:12:50 +03005593static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5594{
5595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5596 struct net_device *dev = info->user_ptr[1];
5597 u8 action_code, dialog_token;
5598 u16 status_code;
5599 u8 *peer;
5600
5601 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5602 !rdev->ops->tdls_mgmt)
5603 return -EOPNOTSUPP;
5604
5605 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5606 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5607 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5608 !info->attrs[NL80211_ATTR_IE] ||
5609 !info->attrs[NL80211_ATTR_MAC])
5610 return -EINVAL;
5611
5612 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5613 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5614 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5615 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5616
5617 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5618 dialog_token, status_code,
5619 nla_data(info->attrs[NL80211_ATTR_IE]),
5620 nla_len(info->attrs[NL80211_ATTR_IE]));
5621}
5622
5623static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5624{
5625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5626 struct net_device *dev = info->user_ptr[1];
5627 enum nl80211_tdls_operation operation;
5628 u8 *peer;
5629
5630 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5631 !rdev->ops->tdls_oper)
5632 return -EOPNOTSUPP;
5633
5634 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5635 !info->attrs[NL80211_ATTR_MAC])
5636 return -EINVAL;
5637
5638 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5639 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5640
5641 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5642}
5643
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005644static int nl80211_remain_on_channel(struct sk_buff *skb,
5645 struct genl_info *info)
5646{
Johannes Berg4c476992010-10-04 21:36:35 +02005647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5648 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005649 struct ieee80211_channel *chan;
5650 struct sk_buff *msg;
5651 void *hdr;
5652 u64 cookie;
5653 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5654 u32 freq, duration;
5655 int err;
5656
5657 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5658 !info->attrs[NL80211_ATTR_DURATION])
5659 return -EINVAL;
5660
5661 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5662
Johannes Berg7c4ef712011-11-18 15:33:48 +01005663 if (!rdev->ops->remain_on_channel ||
5664 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005665 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005666
Johannes Bergebf348f2012-06-01 12:50:54 +02005667 /*
5668 * We should be on that channel for at least a minimum amount of
5669 * time (10ms) but no longer than the driver supports.
5670 */
5671 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5672 duration > rdev->wiphy.max_remain_on_channel_duration)
5673 return -EINVAL;
5674
Johannes Bergcd6c6592012-05-10 21:27:18 +02005675 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5676 !nl80211_valid_channel_type(info, &channel_type))
5677 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005678
5679 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5680 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005681 if (chan == NULL)
5682 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005683
5684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005685 if (!msg)
5686 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005687
5688 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5689 NL80211_CMD_REMAIN_ON_CHANNEL);
5690
5691 if (IS_ERR(hdr)) {
5692 err = PTR_ERR(hdr);
5693 goto free_msg;
5694 }
5695
5696 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5697 channel_type, duration, &cookie);
5698
5699 if (err)
5700 goto free_msg;
5701
David S. Miller9360ffd2012-03-29 04:41:26 -04005702 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5703 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005704
5705 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005706
5707 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005708
5709 nla_put_failure:
5710 err = -ENOBUFS;
5711 free_msg:
5712 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005713 return err;
5714}
5715
5716static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5717 struct genl_info *info)
5718{
Johannes Berg4c476992010-10-04 21:36:35 +02005719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5720 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005721 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005722
5723 if (!info->attrs[NL80211_ATTR_COOKIE])
5724 return -EINVAL;
5725
Johannes Berg4c476992010-10-04 21:36:35 +02005726 if (!rdev->ops->cancel_remain_on_channel)
5727 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005728
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005729 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5730
Johannes Berg4c476992010-10-04 21:36:35 +02005731 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005732}
5733
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005734static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5735 u8 *rates, u8 rates_len)
5736{
5737 u8 i;
5738 u32 mask = 0;
5739
5740 for (i = 0; i < rates_len; i++) {
5741 int rate = (rates[i] & 0x7f) * 5;
5742 int ridx;
5743 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5744 struct ieee80211_rate *srate =
5745 &sband->bitrates[ridx];
5746 if (rate == srate->bitrate) {
5747 mask |= 1 << ridx;
5748 break;
5749 }
5750 }
5751 if (ridx == sband->n_bitrates)
5752 return 0; /* rate not found */
5753 }
5754
5755 return mask;
5756}
5757
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005758static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5759 u8 *rates, u8 rates_len,
5760 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5761{
5762 u8 i;
5763
5764 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5765
5766 for (i = 0; i < rates_len; i++) {
5767 int ridx, rbit;
5768
5769 ridx = rates[i] / 8;
5770 rbit = BIT(rates[i] % 8);
5771
5772 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005773 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005774 return false;
5775
5776 /* check availability */
5777 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5778 mcs[ridx] |= rbit;
5779 else
5780 return false;
5781 }
5782
5783 return true;
5784}
5785
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005786static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005787 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5788 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005789 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5790 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005791};
5792
5793static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5794 struct genl_info *info)
5795{
5796 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005798 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005799 int rem, i;
5800 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005801 struct nlattr *tx_rates;
5802 struct ieee80211_supported_band *sband;
5803
5804 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5805 return -EINVAL;
5806
Johannes Berg4c476992010-10-04 21:36:35 +02005807 if (!rdev->ops->set_bitrate_mask)
5808 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005809
5810 memset(&mask, 0, sizeof(mask));
5811 /* Default to all rates enabled */
5812 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5813 sband = rdev->wiphy.bands[i];
5814 mask.control[i].legacy =
5815 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005816 if (sband)
5817 memcpy(mask.control[i].mcs,
5818 sband->ht_cap.mcs.rx_mask,
5819 sizeof(mask.control[i].mcs));
5820 else
5821 memset(mask.control[i].mcs, 0,
5822 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005823 }
5824
5825 /*
5826 * The nested attribute uses enum nl80211_band as the index. This maps
5827 * directly to the enum ieee80211_band values used in cfg80211.
5828 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005829 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005830 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5831 {
5832 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005833 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5834 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005835 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005836 if (sband == NULL)
5837 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005838 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5839 nla_len(tx_rates), nl80211_txattr_policy);
5840 if (tb[NL80211_TXRATE_LEGACY]) {
5841 mask.control[band].legacy = rateset_to_mask(
5842 sband,
5843 nla_data(tb[NL80211_TXRATE_LEGACY]),
5844 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305845 if ((mask.control[band].legacy == 0) &&
5846 nla_len(tb[NL80211_TXRATE_LEGACY]))
5847 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005848 }
5849 if (tb[NL80211_TXRATE_MCS]) {
5850 if (!ht_rateset_to_mask(
5851 sband,
5852 nla_data(tb[NL80211_TXRATE_MCS]),
5853 nla_len(tb[NL80211_TXRATE_MCS]),
5854 mask.control[band].mcs))
5855 return -EINVAL;
5856 }
5857
5858 if (mask.control[band].legacy == 0) {
5859 /* don't allow empty legacy rates if HT
5860 * is not even supported. */
5861 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5862 return -EINVAL;
5863
5864 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5865 if (mask.control[band].mcs[i])
5866 break;
5867
5868 /* legacy and mcs rates may not be both empty */
5869 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005870 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005871 }
5872 }
5873
Johannes Berg4c476992010-10-04 21:36:35 +02005874 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005875}
5876
Johannes Berg2e161f72010-08-12 15:38:38 +02005877static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005878{
Johannes Berg4c476992010-10-04 21:36:35 +02005879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5880 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005881 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005882
5883 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5884 return -EINVAL;
5885
Johannes Berg2e161f72010-08-12 15:38:38 +02005886 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5887 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005888
Johannes Berg9d38d852010-06-09 17:20:33 +02005889 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005890 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005894 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005895 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5896 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005897
5898 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005899 if (!rdev->ops->mgmt_tx)
5900 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005901
Johannes Berg4c476992010-10-04 21:36:35 +02005902 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005903 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005904 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5905 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005906}
5907
Johannes Berg2e161f72010-08-12 15:38:38 +02005908static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005909{
Johannes Berg4c476992010-10-04 21:36:35 +02005910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5911 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005912 struct ieee80211_channel *chan;
5913 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005914 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005915 u32 freq;
5916 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005917 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005918 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005919 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005920 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005921 bool offchan, no_cck, dont_wait_for_ack;
5922
5923 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005924
5925 if (!info->attrs[NL80211_ATTR_FRAME] ||
5926 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5927 return -EINVAL;
5928
Johannes Berg4c476992010-10-04 21:36:35 +02005929 if (!rdev->ops->mgmt_tx)
5930 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005931
Johannes Berg9d38d852010-06-09 17:20:33 +02005932 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5935 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5936 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005938 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5939 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005940
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005941 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005942 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005943 return -EINVAL;
5944 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005945
5946 /*
5947 * We should wait on the channel for at least a minimum amount
5948 * of time (10ms) but no longer than the driver supports.
5949 */
5950 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5951 wait > rdev->wiphy.max_remain_on_channel_duration)
5952 return -EINVAL;
5953
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005954 }
5955
Jouni Malinen026331c2010-02-15 12:53:10 +02005956 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005957 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005958 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005959 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005960 }
5961
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005962 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5963
Johannes Berg7c4ef712011-11-18 15:33:48 +01005964 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5965 return -EINVAL;
5966
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305967 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5968
Jouni Malinen026331c2010-02-15 12:53:10 +02005969 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5970 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005971 if (chan == NULL)
5972 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005973
Johannes Berge247bd902011-11-04 11:18:21 +01005974 if (!dont_wait_for_ack) {
5975 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5976 if (!msg)
5977 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005978
Johannes Berge247bd902011-11-04 11:18:21 +01005979 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5980 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005981
Johannes Berge247bd902011-11-04 11:18:21 +01005982 if (IS_ERR(hdr)) {
5983 err = PTR_ERR(hdr);
5984 goto free_msg;
5985 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005986 }
Johannes Berge247bd902011-11-04 11:18:21 +01005987
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005988 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5989 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005990 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5991 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005992 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005993 if (err)
5994 goto free_msg;
5995
Johannes Berge247bd902011-11-04 11:18:21 +01005996 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04005997 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5998 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02005999
Johannes Berge247bd902011-11-04 11:18:21 +01006000 genlmsg_end(msg, hdr);
6001 return genlmsg_reply(msg, info);
6002 }
6003
6004 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006005
6006 nla_put_failure:
6007 err = -ENOBUFS;
6008 free_msg:
6009 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006010 return err;
6011}
6012
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006013static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6014{
6015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6016 struct net_device *dev = info->user_ptr[1];
6017 u64 cookie;
6018
6019 if (!info->attrs[NL80211_ATTR_COOKIE])
6020 return -EINVAL;
6021
6022 if (!rdev->ops->mgmt_tx_cancel_wait)
6023 return -EOPNOTSUPP;
6024
6025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6028 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6031 return -EOPNOTSUPP;
6032
6033 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6034
6035 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6036}
6037
Kalle Valoffb9eb32010-02-17 17:58:10 +02006038static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6039{
Johannes Berg4c476992010-10-04 21:36:35 +02006040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006041 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006042 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006043 u8 ps_state;
6044 bool state;
6045 int err;
6046
Johannes Berg4c476992010-10-04 21:36:35 +02006047 if (!info->attrs[NL80211_ATTR_PS_STATE])
6048 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006049
6050 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6051
Johannes Berg4c476992010-10-04 21:36:35 +02006052 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6053 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006054
6055 wdev = dev->ieee80211_ptr;
6056
Johannes Berg4c476992010-10-04 21:36:35 +02006057 if (!rdev->ops->set_power_mgmt)
6058 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006059
6060 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6061
6062 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006063 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006064
Johannes Berg4c476992010-10-04 21:36:35 +02006065 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6066 wdev->ps_timeout);
6067 if (!err)
6068 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006069 return err;
6070}
6071
6072static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6073{
Johannes Berg4c476992010-10-04 21:36:35 +02006074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006075 enum nl80211_ps_state ps_state;
6076 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006077 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006078 struct sk_buff *msg;
6079 void *hdr;
6080 int err;
6081
Kalle Valoffb9eb32010-02-17 17:58:10 +02006082 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 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006088 if (!msg)
6089 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006090
6091 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6092 NL80211_CMD_GET_POWER_SAVE);
6093 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006094 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006095 goto free_msg;
6096 }
6097
6098 if (wdev->ps)
6099 ps_state = NL80211_PS_ENABLED;
6100 else
6101 ps_state = NL80211_PS_DISABLED;
6102
David S. Miller9360ffd2012-03-29 04:41:26 -04006103 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6104 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006105
6106 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006107 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006108
Johannes Berg4c476992010-10-04 21:36:35 +02006109 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006111 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006112 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006113 return err;
6114}
6115
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006116static struct nla_policy
6117nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6118 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6119 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6120 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6121};
6122
6123static int nl80211_set_cqm_rssi(struct genl_info *info,
6124 s32 threshold, u32 hysteresis)
6125{
Johannes Berg4c476992010-10-04 21:36:35 +02006126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006127 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006128 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006129
6130 if (threshold > 0)
6131 return -EINVAL;
6132
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006133 wdev = dev->ieee80211_ptr;
6134
Johannes Berg4c476992010-10-04 21:36:35 +02006135 if (!rdev->ops->set_cqm_rssi_config)
6136 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006137
Johannes Berg074ac8d2010-09-16 14:58:22 +02006138 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006139 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6140 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006141
Johannes Berg4c476992010-10-04 21:36:35 +02006142 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6143 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006144}
6145
6146static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6147{
6148 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6149 struct nlattr *cqm;
6150 int err;
6151
6152 cqm = info->attrs[NL80211_ATTR_CQM];
6153 if (!cqm) {
6154 err = -EINVAL;
6155 goto out;
6156 }
6157
6158 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6159 nl80211_attr_cqm_policy);
6160 if (err)
6161 goto out;
6162
6163 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6164 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6165 s32 threshold;
6166 u32 hysteresis;
6167 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6168 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6169 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6170 } else
6171 err = -EINVAL;
6172
6173out:
6174 return err;
6175}
6176
Johannes Berg29cbe682010-12-03 09:20:44 +01006177static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6178{
6179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6180 struct net_device *dev = info->user_ptr[1];
6181 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006182 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006183 int err;
6184
6185 /* start with default */
6186 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006187 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006188
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006189 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006190 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006191 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006192 if (err)
6193 return err;
6194 }
6195
6196 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6197 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6198 return -EINVAL;
6199
Javier Cardonac80d5452010-12-16 17:37:49 -08006200 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6201 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6202
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006203 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6204 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6205 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6206 return -EINVAL;
6207
Javier Cardonac80d5452010-12-16 17:37:49 -08006208 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6209 /* parse additional setup parameters if given */
6210 err = nl80211_parse_mesh_setup(info, &setup);
6211 if (err)
6212 return err;
6213 }
6214
Johannes Bergcc1d2802012-05-16 23:50:20 +02006215 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6216 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6217
6218 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6219 !nl80211_valid_channel_type(info, &channel_type))
6220 return -EINVAL;
6221
6222 setup.channel = rdev_freq_to_chan(rdev,
6223 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6224 channel_type);
6225 if (!setup.channel)
6226 return -EINVAL;
6227 setup.channel_type = channel_type;
6228 } else {
6229 /* cfg80211_join_mesh() will sort it out */
6230 setup.channel = NULL;
6231 }
6232
Javier Cardonac80d5452010-12-16 17:37:49 -08006233 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006234}
6235
6236static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6237{
6238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6239 struct net_device *dev = info->user_ptr[1];
6240
6241 return cfg80211_leave_mesh(rdev, dev);
6242}
6243
Johannes Bergff1b6e62011-05-04 15:37:28 +02006244static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6245{
6246 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6247 struct sk_buff *msg;
6248 void *hdr;
6249
6250 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6251 return -EOPNOTSUPP;
6252
6253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6254 if (!msg)
6255 return -ENOMEM;
6256
6257 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6258 NL80211_CMD_GET_WOWLAN);
6259 if (!hdr)
6260 goto nla_put_failure;
6261
6262 if (rdev->wowlan) {
6263 struct nlattr *nl_wowlan;
6264
6265 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6266 if (!nl_wowlan)
6267 goto nla_put_failure;
6268
David S. Miller9360ffd2012-03-29 04:41:26 -04006269 if ((rdev->wowlan->any &&
6270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6271 (rdev->wowlan->disconnect &&
6272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6273 (rdev->wowlan->magic_pkt &&
6274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6275 (rdev->wowlan->gtk_rekey_failure &&
6276 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6277 (rdev->wowlan->eap_identity_req &&
6278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6279 (rdev->wowlan->four_way_handshake &&
6280 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6281 (rdev->wowlan->rfkill_release &&
6282 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6283 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006284 if (rdev->wowlan->n_patterns) {
6285 struct nlattr *nl_pats, *nl_pat;
6286 int i, pat_len;
6287
6288 nl_pats = nla_nest_start(msg,
6289 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6290 if (!nl_pats)
6291 goto nla_put_failure;
6292
6293 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6294 nl_pat = nla_nest_start(msg, i + 1);
6295 if (!nl_pat)
6296 goto nla_put_failure;
6297 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006298 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6299 DIV_ROUND_UP(pat_len, 8),
6300 rdev->wowlan->patterns[i].mask) ||
6301 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6302 pat_len,
6303 rdev->wowlan->patterns[i].pattern))
6304 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006305 nla_nest_end(msg, nl_pat);
6306 }
6307 nla_nest_end(msg, nl_pats);
6308 }
6309
6310 nla_nest_end(msg, nl_wowlan);
6311 }
6312
6313 genlmsg_end(msg, hdr);
6314 return genlmsg_reply(msg, info);
6315
6316nla_put_failure:
6317 nlmsg_free(msg);
6318 return -ENOBUFS;
6319}
6320
6321static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6322{
6323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6324 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6325 struct cfg80211_wowlan no_triggers = {};
6326 struct cfg80211_wowlan new_triggers = {};
6327 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6328 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006329 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006330
6331 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6332 return -EOPNOTSUPP;
6333
6334 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6335 goto no_triggers;
6336
6337 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6338 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6339 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6340 nl80211_wowlan_policy);
6341 if (err)
6342 return err;
6343
6344 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6345 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6346 return -EINVAL;
6347 new_triggers.any = true;
6348 }
6349
6350 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6351 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6352 return -EINVAL;
6353 new_triggers.disconnect = true;
6354 }
6355
6356 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6357 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6358 return -EINVAL;
6359 new_triggers.magic_pkt = true;
6360 }
6361
Johannes Berg77dbbb132011-07-13 10:48:55 +02006362 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6363 return -EINVAL;
6364
6365 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6366 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6367 return -EINVAL;
6368 new_triggers.gtk_rekey_failure = true;
6369 }
6370
6371 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6372 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6373 return -EINVAL;
6374 new_triggers.eap_identity_req = true;
6375 }
6376
6377 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6378 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6379 return -EINVAL;
6380 new_triggers.four_way_handshake = true;
6381 }
6382
6383 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6384 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6385 return -EINVAL;
6386 new_triggers.rfkill_release = true;
6387 }
6388
Johannes Bergff1b6e62011-05-04 15:37:28 +02006389 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6390 struct nlattr *pat;
6391 int n_patterns = 0;
6392 int rem, pat_len, mask_len;
6393 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6394
6395 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6396 rem)
6397 n_patterns++;
6398 if (n_patterns > wowlan->n_patterns)
6399 return -EINVAL;
6400
6401 new_triggers.patterns = kcalloc(n_patterns,
6402 sizeof(new_triggers.patterns[0]),
6403 GFP_KERNEL);
6404 if (!new_triggers.patterns)
6405 return -ENOMEM;
6406
6407 new_triggers.n_patterns = n_patterns;
6408 i = 0;
6409
6410 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6411 rem) {
6412 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6413 nla_data(pat), nla_len(pat), NULL);
6414 err = -EINVAL;
6415 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6416 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6417 goto error;
6418 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6419 mask_len = DIV_ROUND_UP(pat_len, 8);
6420 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6421 mask_len)
6422 goto error;
6423 if (pat_len > wowlan->pattern_max_len ||
6424 pat_len < wowlan->pattern_min_len)
6425 goto error;
6426
6427 new_triggers.patterns[i].mask =
6428 kmalloc(mask_len + pat_len, GFP_KERNEL);
6429 if (!new_triggers.patterns[i].mask) {
6430 err = -ENOMEM;
6431 goto error;
6432 }
6433 new_triggers.patterns[i].pattern =
6434 new_triggers.patterns[i].mask + mask_len;
6435 memcpy(new_triggers.patterns[i].mask,
6436 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6437 mask_len);
6438 new_triggers.patterns[i].pattern_len = pat_len;
6439 memcpy(new_triggers.patterns[i].pattern,
6440 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6441 pat_len);
6442 i++;
6443 }
6444 }
6445
6446 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6447 struct cfg80211_wowlan *ntrig;
6448 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6449 GFP_KERNEL);
6450 if (!ntrig) {
6451 err = -ENOMEM;
6452 goto error;
6453 }
6454 cfg80211_rdev_free_wowlan(rdev);
6455 rdev->wowlan = ntrig;
6456 } else {
6457 no_triggers:
6458 cfg80211_rdev_free_wowlan(rdev);
6459 rdev->wowlan = NULL;
6460 }
6461
Johannes Berg6d525632012-04-04 15:05:25 +02006462 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6463 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6464
Johannes Bergff1b6e62011-05-04 15:37:28 +02006465 return 0;
6466 error:
6467 for (i = 0; i < new_triggers.n_patterns; i++)
6468 kfree(new_triggers.patterns[i].mask);
6469 kfree(new_triggers.patterns);
6470 return err;
6471}
6472
Johannes Berge5497d72011-07-05 16:35:40 +02006473static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6474{
6475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6476 struct net_device *dev = info->user_ptr[1];
6477 struct wireless_dev *wdev = dev->ieee80211_ptr;
6478 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6479 struct cfg80211_gtk_rekey_data rekey_data;
6480 int err;
6481
6482 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6483 return -EINVAL;
6484
6485 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6486 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6487 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6488 nl80211_rekey_policy);
6489 if (err)
6490 return err;
6491
6492 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6493 return -ERANGE;
6494 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6495 return -ERANGE;
6496 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6497 return -ERANGE;
6498
6499 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6500 NL80211_KEK_LEN);
6501 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6502 NL80211_KCK_LEN);
6503 memcpy(rekey_data.replay_ctr,
6504 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6505 NL80211_REPLAY_CTR_LEN);
6506
6507 wdev_lock(wdev);
6508 if (!wdev->current_bss) {
6509 err = -ENOTCONN;
6510 goto out;
6511 }
6512
6513 if (!rdev->ops->set_rekey_data) {
6514 err = -EOPNOTSUPP;
6515 goto out;
6516 }
6517
6518 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6519 out:
6520 wdev_unlock(wdev);
6521 return err;
6522}
6523
Johannes Berg28946da2011-11-04 11:18:12 +01006524static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6525 struct genl_info *info)
6526{
6527 struct net_device *dev = info->user_ptr[1];
6528 struct wireless_dev *wdev = dev->ieee80211_ptr;
6529
6530 if (wdev->iftype != NL80211_IFTYPE_AP &&
6531 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6532 return -EINVAL;
6533
6534 if (wdev->ap_unexpected_nlpid)
6535 return -EBUSY;
6536
6537 wdev->ap_unexpected_nlpid = info->snd_pid;
6538 return 0;
6539}
6540
Johannes Berg7f6cf312011-11-04 11:18:15 +01006541static int nl80211_probe_client(struct sk_buff *skb,
6542 struct genl_info *info)
6543{
6544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6545 struct net_device *dev = info->user_ptr[1];
6546 struct wireless_dev *wdev = dev->ieee80211_ptr;
6547 struct sk_buff *msg;
6548 void *hdr;
6549 const u8 *addr;
6550 u64 cookie;
6551 int err;
6552
6553 if (wdev->iftype != NL80211_IFTYPE_AP &&
6554 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6555 return -EOPNOTSUPP;
6556
6557 if (!info->attrs[NL80211_ATTR_MAC])
6558 return -EINVAL;
6559
6560 if (!rdev->ops->probe_client)
6561 return -EOPNOTSUPP;
6562
6563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6564 if (!msg)
6565 return -ENOMEM;
6566
6567 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6568 NL80211_CMD_PROBE_CLIENT);
6569
6570 if (IS_ERR(hdr)) {
6571 err = PTR_ERR(hdr);
6572 goto free_msg;
6573 }
6574
6575 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6576
6577 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6578 if (err)
6579 goto free_msg;
6580
David S. Miller9360ffd2012-03-29 04:41:26 -04006581 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6582 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006583
6584 genlmsg_end(msg, hdr);
6585
6586 return genlmsg_reply(msg, info);
6587
6588 nla_put_failure:
6589 err = -ENOBUFS;
6590 free_msg:
6591 nlmsg_free(msg);
6592 return err;
6593}
6594
Johannes Berg5e760232011-11-04 11:18:17 +01006595static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6596{
6597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6598
6599 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6600 return -EOPNOTSUPP;
6601
6602 if (rdev->ap_beacons_nlpid)
6603 return -EBUSY;
6604
6605 rdev->ap_beacons_nlpid = info->snd_pid;
6606
6607 return 0;
6608}
6609
Johannes Berg4c476992010-10-04 21:36:35 +02006610#define NL80211_FLAG_NEED_WIPHY 0x01
6611#define NL80211_FLAG_NEED_NETDEV 0x02
6612#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006613#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6614#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6615 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006616
6617static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6618 struct genl_info *info)
6619{
6620 struct cfg80211_registered_device *rdev;
6621 struct net_device *dev;
6622 int err;
6623 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6624
6625 if (rtnl)
6626 rtnl_lock();
6627
6628 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006629 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006630 if (IS_ERR(rdev)) {
6631 if (rtnl)
6632 rtnl_unlock();
6633 return PTR_ERR(rdev);
6634 }
6635 info->user_ptr[0] = rdev;
6636 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006637 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6638 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006639 if (err) {
6640 if (rtnl)
6641 rtnl_unlock();
6642 return err;
6643 }
Johannes Berg41265712010-10-04 21:14:05 +02006644 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6645 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006646 cfg80211_unlock_rdev(rdev);
6647 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006648 if (rtnl)
6649 rtnl_unlock();
6650 return -ENETDOWN;
6651 }
Johannes Berg4c476992010-10-04 21:36:35 +02006652 info->user_ptr[0] = rdev;
6653 info->user_ptr[1] = dev;
6654 }
6655
6656 return 0;
6657}
6658
6659static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6660 struct genl_info *info)
6661{
6662 if (info->user_ptr[0])
6663 cfg80211_unlock_rdev(info->user_ptr[0]);
6664 if (info->user_ptr[1])
6665 dev_put(info->user_ptr[1]);
6666 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6667 rtnl_unlock();
6668}
6669
Johannes Berg55682962007-09-20 13:09:35 -04006670static struct genl_ops nl80211_ops[] = {
6671 {
6672 .cmd = NL80211_CMD_GET_WIPHY,
6673 .doit = nl80211_get_wiphy,
6674 .dumpit = nl80211_dump_wiphy,
6675 .policy = nl80211_policy,
6676 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006677 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006678 },
6679 {
6680 .cmd = NL80211_CMD_SET_WIPHY,
6681 .doit = nl80211_set_wiphy,
6682 .policy = nl80211_policy,
6683 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006684 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006685 },
6686 {
6687 .cmd = NL80211_CMD_GET_INTERFACE,
6688 .doit = nl80211_get_interface,
6689 .dumpit = nl80211_dump_interface,
6690 .policy = nl80211_policy,
6691 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006692 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006693 },
6694 {
6695 .cmd = NL80211_CMD_SET_INTERFACE,
6696 .doit = nl80211_set_interface,
6697 .policy = nl80211_policy,
6698 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006699 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6700 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006701 },
6702 {
6703 .cmd = NL80211_CMD_NEW_INTERFACE,
6704 .doit = nl80211_new_interface,
6705 .policy = nl80211_policy,
6706 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006707 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6708 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006709 },
6710 {
6711 .cmd = NL80211_CMD_DEL_INTERFACE,
6712 .doit = nl80211_del_interface,
6713 .policy = nl80211_policy,
6714 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006715 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6716 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006717 },
Johannes Berg41ade002007-12-19 02:03:29 +01006718 {
6719 .cmd = NL80211_CMD_GET_KEY,
6720 .doit = nl80211_get_key,
6721 .policy = nl80211_policy,
6722 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006724 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006725 },
6726 {
6727 .cmd = NL80211_CMD_SET_KEY,
6728 .doit = nl80211_set_key,
6729 .policy = nl80211_policy,
6730 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006731 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006732 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006733 },
6734 {
6735 .cmd = NL80211_CMD_NEW_KEY,
6736 .doit = nl80211_new_key,
6737 .policy = nl80211_policy,
6738 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006739 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006740 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006741 },
6742 {
6743 .cmd = NL80211_CMD_DEL_KEY,
6744 .doit = nl80211_del_key,
6745 .policy = nl80211_policy,
6746 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006748 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006749 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006750 {
6751 .cmd = NL80211_CMD_SET_BEACON,
6752 .policy = nl80211_policy,
6753 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006754 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006756 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006757 },
6758 {
Johannes Berg88600202012-02-13 15:17:18 +01006759 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006760 .policy = nl80211_policy,
6761 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006762 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006764 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006765 },
6766 {
Johannes Berg88600202012-02-13 15:17:18 +01006767 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006768 .policy = nl80211_policy,
6769 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006770 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006772 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006773 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006774 {
6775 .cmd = NL80211_CMD_GET_STATION,
6776 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006777 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006778 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006779 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6780 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006781 },
6782 {
6783 .cmd = NL80211_CMD_SET_STATION,
6784 .doit = nl80211_set_station,
6785 .policy = nl80211_policy,
6786 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006787 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006788 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006789 },
6790 {
6791 .cmd = NL80211_CMD_NEW_STATION,
6792 .doit = nl80211_new_station,
6793 .policy = nl80211_policy,
6794 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006795 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006796 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006797 },
6798 {
6799 .cmd = NL80211_CMD_DEL_STATION,
6800 .doit = nl80211_del_station,
6801 .policy = nl80211_policy,
6802 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006804 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006805 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006806 {
6807 .cmd = NL80211_CMD_GET_MPATH,
6808 .doit = nl80211_get_mpath,
6809 .dumpit = nl80211_dump_mpath,
6810 .policy = nl80211_policy,
6811 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006813 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006814 },
6815 {
6816 .cmd = NL80211_CMD_SET_MPATH,
6817 .doit = nl80211_set_mpath,
6818 .policy = nl80211_policy,
6819 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006821 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006822 },
6823 {
6824 .cmd = NL80211_CMD_NEW_MPATH,
6825 .doit = nl80211_new_mpath,
6826 .policy = nl80211_policy,
6827 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006829 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006830 },
6831 {
6832 .cmd = NL80211_CMD_DEL_MPATH,
6833 .doit = nl80211_del_mpath,
6834 .policy = nl80211_policy,
6835 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006837 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006838 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006839 {
6840 .cmd = NL80211_CMD_SET_BSS,
6841 .doit = nl80211_set_bss,
6842 .policy = nl80211_policy,
6843 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006845 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006846 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006847 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006848 .cmd = NL80211_CMD_GET_REG,
6849 .doit = nl80211_get_reg,
6850 .policy = nl80211_policy,
6851 /* can be retrieved by unprivileged users */
6852 },
6853 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006854 .cmd = NL80211_CMD_SET_REG,
6855 .doit = nl80211_set_reg,
6856 .policy = nl80211_policy,
6857 .flags = GENL_ADMIN_PERM,
6858 },
6859 {
6860 .cmd = NL80211_CMD_REQ_SET_REG,
6861 .doit = nl80211_req_set_reg,
6862 .policy = nl80211_policy,
6863 .flags = GENL_ADMIN_PERM,
6864 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006865 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006866 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6867 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006868 .policy = nl80211_policy,
6869 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006870 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006871 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006872 },
6873 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006874 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6875 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006876 .policy = nl80211_policy,
6877 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006879 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006880 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006881 {
Johannes Berg2a519312009-02-10 21:25:55 +01006882 .cmd = NL80211_CMD_TRIGGER_SCAN,
6883 .doit = nl80211_trigger_scan,
6884 .policy = nl80211_policy,
6885 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006886 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006887 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006888 },
6889 {
6890 .cmd = NL80211_CMD_GET_SCAN,
6891 .policy = nl80211_policy,
6892 .dumpit = nl80211_dump_scan,
6893 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006894 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006895 .cmd = NL80211_CMD_START_SCHED_SCAN,
6896 .doit = nl80211_start_sched_scan,
6897 .policy = nl80211_policy,
6898 .flags = GENL_ADMIN_PERM,
6899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6900 NL80211_FLAG_NEED_RTNL,
6901 },
6902 {
6903 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6904 .doit = nl80211_stop_sched_scan,
6905 .policy = nl80211_policy,
6906 .flags = GENL_ADMIN_PERM,
6907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6908 NL80211_FLAG_NEED_RTNL,
6909 },
6910 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006911 .cmd = NL80211_CMD_AUTHENTICATE,
6912 .doit = nl80211_authenticate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006917 },
6918 {
6919 .cmd = NL80211_CMD_ASSOCIATE,
6920 .doit = nl80211_associate,
6921 .policy = nl80211_policy,
6922 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006924 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006925 },
6926 {
6927 .cmd = NL80211_CMD_DEAUTHENTICATE,
6928 .doit = nl80211_deauthenticate,
6929 .policy = nl80211_policy,
6930 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006931 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006932 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006933 },
6934 {
6935 .cmd = NL80211_CMD_DISASSOCIATE,
6936 .doit = nl80211_disassociate,
6937 .policy = nl80211_policy,
6938 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006939 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006940 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006941 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006942 {
6943 .cmd = NL80211_CMD_JOIN_IBSS,
6944 .doit = nl80211_join_ibss,
6945 .policy = nl80211_policy,
6946 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006948 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006949 },
6950 {
6951 .cmd = NL80211_CMD_LEAVE_IBSS,
6952 .doit = nl80211_leave_ibss,
6953 .policy = nl80211_policy,
6954 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006955 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006956 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006957 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006958#ifdef CONFIG_NL80211_TESTMODE
6959 {
6960 .cmd = NL80211_CMD_TESTMODE,
6961 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006962 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006963 .policy = nl80211_policy,
6964 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006965 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6966 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006967 },
6968#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006969 {
6970 .cmd = NL80211_CMD_CONNECT,
6971 .doit = nl80211_connect,
6972 .policy = nl80211_policy,
6973 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006974 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006975 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006976 },
6977 {
6978 .cmd = NL80211_CMD_DISCONNECT,
6979 .doit = nl80211_disconnect,
6980 .policy = nl80211_policy,
6981 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006982 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006983 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006984 },
Johannes Berg463d0182009-07-14 00:33:35 +02006985 {
6986 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6987 .doit = nl80211_wiphy_netns,
6988 .policy = nl80211_policy,
6989 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006990 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6991 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006992 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006993 {
6994 .cmd = NL80211_CMD_GET_SURVEY,
6995 .policy = nl80211_policy,
6996 .dumpit = nl80211_dump_survey,
6997 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006998 {
6999 .cmd = NL80211_CMD_SET_PMKSA,
7000 .doit = nl80211_setdel_pmksa,
7001 .policy = nl80211_policy,
7002 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007004 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007005 },
7006 {
7007 .cmd = NL80211_CMD_DEL_PMKSA,
7008 .doit = nl80211_setdel_pmksa,
7009 .policy = nl80211_policy,
7010 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007012 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007013 },
7014 {
7015 .cmd = NL80211_CMD_FLUSH_PMKSA,
7016 .doit = nl80211_flush_pmksa,
7017 .policy = nl80211_policy,
7018 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007020 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007021 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007022 {
7023 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7024 .doit = nl80211_remain_on_channel,
7025 .policy = nl80211_policy,
7026 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007028 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007029 },
7030 {
7031 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7032 .doit = nl80211_cancel_remain_on_channel,
7033 .policy = nl80211_policy,
7034 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007036 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007037 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007038 {
7039 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7040 .doit = nl80211_set_tx_bitrate_mask,
7041 .policy = nl80211_policy,
7042 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007043 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7044 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007045 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007046 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007047 .cmd = NL80211_CMD_REGISTER_FRAME,
7048 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007049 .policy = nl80211_policy,
7050 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007051 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7052 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007053 },
7054 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007055 .cmd = NL80211_CMD_FRAME,
7056 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007057 .policy = nl80211_policy,
7058 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007060 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007061 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007062 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007063 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7064 .doit = nl80211_tx_mgmt_cancel_wait,
7065 .policy = nl80211_policy,
7066 .flags = GENL_ADMIN_PERM,
7067 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7068 NL80211_FLAG_NEED_RTNL,
7069 },
7070 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007071 .cmd = NL80211_CMD_SET_POWER_SAVE,
7072 .doit = nl80211_set_power_save,
7073 .policy = nl80211_policy,
7074 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007075 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7076 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007077 },
7078 {
7079 .cmd = NL80211_CMD_GET_POWER_SAVE,
7080 .doit = nl80211_get_power_save,
7081 .policy = nl80211_policy,
7082 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007083 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7084 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007085 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007086 {
7087 .cmd = NL80211_CMD_SET_CQM,
7088 .doit = nl80211_set_cqm,
7089 .policy = nl80211_policy,
7090 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007091 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7092 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007093 },
Johannes Bergf444de02010-05-05 15:25:02 +02007094 {
7095 .cmd = NL80211_CMD_SET_CHANNEL,
7096 .doit = nl80211_set_channel,
7097 .policy = nl80211_policy,
7098 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007099 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7100 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007101 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007102 {
7103 .cmd = NL80211_CMD_SET_WDS_PEER,
7104 .doit = nl80211_set_wds_peer,
7105 .policy = nl80211_policy,
7106 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007107 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7108 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007109 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007110 {
7111 .cmd = NL80211_CMD_JOIN_MESH,
7112 .doit = nl80211_join_mesh,
7113 .policy = nl80211_policy,
7114 .flags = GENL_ADMIN_PERM,
7115 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7116 NL80211_FLAG_NEED_RTNL,
7117 },
7118 {
7119 .cmd = NL80211_CMD_LEAVE_MESH,
7120 .doit = nl80211_leave_mesh,
7121 .policy = nl80211_policy,
7122 .flags = GENL_ADMIN_PERM,
7123 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7124 NL80211_FLAG_NEED_RTNL,
7125 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02007126 {
7127 .cmd = NL80211_CMD_GET_WOWLAN,
7128 .doit = nl80211_get_wowlan,
7129 .policy = nl80211_policy,
7130 /* can be retrieved by unprivileged users */
7131 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7132 NL80211_FLAG_NEED_RTNL,
7133 },
7134 {
7135 .cmd = NL80211_CMD_SET_WOWLAN,
7136 .doit = nl80211_set_wowlan,
7137 .policy = nl80211_policy,
7138 .flags = GENL_ADMIN_PERM,
7139 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7140 NL80211_FLAG_NEED_RTNL,
7141 },
Johannes Berge5497d72011-07-05 16:35:40 +02007142 {
7143 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7144 .doit = nl80211_set_rekey_data,
7145 .policy = nl80211_policy,
7146 .flags = GENL_ADMIN_PERM,
7147 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7148 NL80211_FLAG_NEED_RTNL,
7149 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007150 {
7151 .cmd = NL80211_CMD_TDLS_MGMT,
7152 .doit = nl80211_tdls_mgmt,
7153 .policy = nl80211_policy,
7154 .flags = GENL_ADMIN_PERM,
7155 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7156 NL80211_FLAG_NEED_RTNL,
7157 },
7158 {
7159 .cmd = NL80211_CMD_TDLS_OPER,
7160 .doit = nl80211_tdls_oper,
7161 .policy = nl80211_policy,
7162 .flags = GENL_ADMIN_PERM,
7163 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7164 NL80211_FLAG_NEED_RTNL,
7165 },
Johannes Berg28946da2011-11-04 11:18:12 +01007166 {
7167 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7168 .doit = nl80211_register_unexpected_frame,
7169 .policy = nl80211_policy,
7170 .flags = GENL_ADMIN_PERM,
7171 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7172 NL80211_FLAG_NEED_RTNL,
7173 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007174 {
7175 .cmd = NL80211_CMD_PROBE_CLIENT,
7176 .doit = nl80211_probe_client,
7177 .policy = nl80211_policy,
7178 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007179 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007180 NL80211_FLAG_NEED_RTNL,
7181 },
Johannes Berg5e760232011-11-04 11:18:17 +01007182 {
7183 .cmd = NL80211_CMD_REGISTER_BEACONS,
7184 .doit = nl80211_register_beacons,
7185 .policy = nl80211_policy,
7186 .flags = GENL_ADMIN_PERM,
7187 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7188 NL80211_FLAG_NEED_RTNL,
7189 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007190 {
7191 .cmd = NL80211_CMD_SET_NOACK_MAP,
7192 .doit = nl80211_set_noack_map,
7193 .policy = nl80211_policy,
7194 .flags = GENL_ADMIN_PERM,
7195 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7196 NL80211_FLAG_NEED_RTNL,
7197 },
7198
Johannes Berg55682962007-09-20 13:09:35 -04007199};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007200
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007201static struct genl_multicast_group nl80211_mlme_mcgrp = {
7202 .name = "mlme",
7203};
Johannes Berg55682962007-09-20 13:09:35 -04007204
7205/* multicast groups */
7206static struct genl_multicast_group nl80211_config_mcgrp = {
7207 .name = "config",
7208};
Johannes Berg2a519312009-02-10 21:25:55 +01007209static struct genl_multicast_group nl80211_scan_mcgrp = {
7210 .name = "scan",
7211};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007212static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7213 .name = "regulatory",
7214};
Johannes Berg55682962007-09-20 13:09:35 -04007215
7216/* notification functions */
7217
7218void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7219{
7220 struct sk_buff *msg;
7221
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007222 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007223 if (!msg)
7224 return;
7225
7226 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7227 nlmsg_free(msg);
7228 return;
7229 }
7230
Johannes Berg463d0182009-07-14 00:33:35 +02007231 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7232 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007233}
7234
Johannes Berg362a4152009-05-24 16:43:15 +02007235static int nl80211_add_scan_req(struct sk_buff *msg,
7236 struct cfg80211_registered_device *rdev)
7237{
7238 struct cfg80211_scan_request *req = rdev->scan_req;
7239 struct nlattr *nest;
7240 int i;
7241
Johannes Berg667503d2009-07-07 03:56:11 +02007242 ASSERT_RDEV_LOCK(rdev);
7243
Johannes Berg362a4152009-05-24 16:43:15 +02007244 if (WARN_ON(!req))
7245 return 0;
7246
7247 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7248 if (!nest)
7249 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007250 for (i = 0; i < req->n_ssids; i++) {
7251 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7252 goto nla_put_failure;
7253 }
Johannes Berg362a4152009-05-24 16:43:15 +02007254 nla_nest_end(msg, nest);
7255
7256 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7257 if (!nest)
7258 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007259 for (i = 0; i < req->n_channels; i++) {
7260 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7261 goto nla_put_failure;
7262 }
Johannes Berg362a4152009-05-24 16:43:15 +02007263 nla_nest_end(msg, nest);
7264
David S. Miller9360ffd2012-03-29 04:41:26 -04007265 if (req->ie &&
7266 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7267 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007268
7269 return 0;
7270 nla_put_failure:
7271 return -ENOBUFS;
7272}
7273
Johannes Berga538e2d2009-06-16 19:56:42 +02007274static int nl80211_send_scan_msg(struct sk_buff *msg,
7275 struct cfg80211_registered_device *rdev,
7276 struct net_device *netdev,
7277 u32 pid, u32 seq, int flags,
7278 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007279{
7280 void *hdr;
7281
7282 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7283 if (!hdr)
7284 return -1;
7285
David S. Miller9360ffd2012-03-29 04:41:26 -04007286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7288 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007289
Johannes Berg362a4152009-05-24 16:43:15 +02007290 /* ignore errors and send incomplete event anyway */
7291 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007292
7293 return genlmsg_end(msg, hdr);
7294
7295 nla_put_failure:
7296 genlmsg_cancel(msg, hdr);
7297 return -EMSGSIZE;
7298}
7299
Luciano Coelho807f8a82011-05-11 17:09:35 +03007300static int
7301nl80211_send_sched_scan_msg(struct sk_buff *msg,
7302 struct cfg80211_registered_device *rdev,
7303 struct net_device *netdev,
7304 u32 pid, u32 seq, int flags, u32 cmd)
7305{
7306 void *hdr;
7307
7308 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7309 if (!hdr)
7310 return -1;
7311
David S. Miller9360ffd2012-03-29 04:41:26 -04007312 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7313 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7314 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007315
7316 return genlmsg_end(msg, hdr);
7317
7318 nla_put_failure:
7319 genlmsg_cancel(msg, hdr);
7320 return -EMSGSIZE;
7321}
7322
Johannes Berga538e2d2009-06-16 19:56:42 +02007323void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7324 struct net_device *netdev)
7325{
7326 struct sk_buff *msg;
7327
7328 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7329 if (!msg)
7330 return;
7331
7332 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7333 NL80211_CMD_TRIGGER_SCAN) < 0) {
7334 nlmsg_free(msg);
7335 return;
7336 }
7337
Johannes Berg463d0182009-07-14 00:33:35 +02007338 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7339 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007340}
7341
Johannes Berg2a519312009-02-10 21:25:55 +01007342void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7343 struct net_device *netdev)
7344{
7345 struct sk_buff *msg;
7346
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007347 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007348 if (!msg)
7349 return;
7350
Johannes Berga538e2d2009-06-16 19:56:42 +02007351 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7352 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007353 nlmsg_free(msg);
7354 return;
7355 }
7356
Johannes Berg463d0182009-07-14 00:33:35 +02007357 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7358 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007359}
7360
7361void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7362 struct net_device *netdev)
7363{
7364 struct sk_buff *msg;
7365
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007367 if (!msg)
7368 return;
7369
Johannes Berga538e2d2009-06-16 19:56:42 +02007370 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7371 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007372 nlmsg_free(msg);
7373 return;
7374 }
7375
Johannes Berg463d0182009-07-14 00:33:35 +02007376 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7377 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007378}
7379
Luciano Coelho807f8a82011-05-11 17:09:35 +03007380void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7381 struct net_device *netdev)
7382{
7383 struct sk_buff *msg;
7384
7385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7386 if (!msg)
7387 return;
7388
7389 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7390 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7391 nlmsg_free(msg);
7392 return;
7393 }
7394
7395 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7396 nl80211_scan_mcgrp.id, GFP_KERNEL);
7397}
7398
7399void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7400 struct net_device *netdev, u32 cmd)
7401{
7402 struct sk_buff *msg;
7403
7404 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7405 if (!msg)
7406 return;
7407
7408 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7409 nlmsg_free(msg);
7410 return;
7411 }
7412
7413 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7414 nl80211_scan_mcgrp.id, GFP_KERNEL);
7415}
7416
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007417/*
7418 * This can happen on global regulatory changes or device specific settings
7419 * based on custom world regulatory domains.
7420 */
7421void nl80211_send_reg_change_event(struct regulatory_request *request)
7422{
7423 struct sk_buff *msg;
7424 void *hdr;
7425
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007426 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007427 if (!msg)
7428 return;
7429
7430 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7431 if (!hdr) {
7432 nlmsg_free(msg);
7433 return;
7434 }
7435
7436 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007437 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7438 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007439
David S. Miller9360ffd2012-03-29 04:41:26 -04007440 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7441 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7442 NL80211_REGDOM_TYPE_WORLD))
7443 goto nla_put_failure;
7444 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7445 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7446 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7447 goto nla_put_failure;
7448 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7449 request->intersect) {
7450 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7451 NL80211_REGDOM_TYPE_INTERSECTION))
7452 goto nla_put_failure;
7453 } else {
7454 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7455 NL80211_REGDOM_TYPE_COUNTRY) ||
7456 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7457 request->alpha2))
7458 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007459 }
7460
David S. Miller9360ffd2012-03-29 04:41:26 -04007461 if (wiphy_idx_valid(request->wiphy_idx) &&
7462 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7463 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007464
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007465 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007466
Johannes Bergbc43b282009-07-25 10:54:13 +02007467 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007468 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007469 GFP_ATOMIC);
7470 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007471
7472 return;
7473
7474nla_put_failure:
7475 genlmsg_cancel(msg, hdr);
7476 nlmsg_free(msg);
7477}
7478
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007479static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7480 struct net_device *netdev,
7481 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007482 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007483{
7484 struct sk_buff *msg;
7485 void *hdr;
7486
Johannes Berge6d6e342009-07-01 21:26:47 +02007487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007488 if (!msg)
7489 return;
7490
7491 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7492 if (!hdr) {
7493 nlmsg_free(msg);
7494 return;
7495 }
7496
David S. Miller9360ffd2012-03-29 04:41:26 -04007497 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7499 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7500 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007501
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007502 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007503
Johannes Berg463d0182009-07-14 00:33:35 +02007504 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7505 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007506 return;
7507
7508 nla_put_failure:
7509 genlmsg_cancel(msg, hdr);
7510 nlmsg_free(msg);
7511}
7512
7513void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007514 struct net_device *netdev, const u8 *buf,
7515 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007516{
7517 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007518 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007519}
7520
7521void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7522 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007523 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007524{
Johannes Berge6d6e342009-07-01 21:26:47 +02007525 nl80211_send_mlme_event(rdev, netdev, buf, len,
7526 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007527}
7528
Jouni Malinen53b46b82009-03-27 20:53:56 +02007529void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007530 struct net_device *netdev, const u8 *buf,
7531 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007532{
7533 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007534 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007535}
7536
Jouni Malinen53b46b82009-03-27 20:53:56 +02007537void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7538 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007539 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007540{
7541 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007542 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007543}
7544
Jouni Malinencf4e5942010-12-16 00:52:40 +02007545void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7546 struct net_device *netdev, const u8 *buf,
7547 size_t len, gfp_t gfp)
7548{
7549 nl80211_send_mlme_event(rdev, netdev, buf, len,
7550 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7551}
7552
7553void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7554 struct net_device *netdev, const u8 *buf,
7555 size_t len, gfp_t gfp)
7556{
7557 nl80211_send_mlme_event(rdev, netdev, buf, len,
7558 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7559}
7560
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007561static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7562 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007563 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007564{
7565 struct sk_buff *msg;
7566 void *hdr;
7567
Johannes Berge6d6e342009-07-01 21:26:47 +02007568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007569 if (!msg)
7570 return;
7571
7572 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7573 if (!hdr) {
7574 nlmsg_free(msg);
7575 return;
7576 }
7577
David S. Miller9360ffd2012-03-29 04:41:26 -04007578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7579 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7580 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7581 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7582 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007583
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007584 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007585
Johannes Berg463d0182009-07-14 00:33:35 +02007586 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7587 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007588 return;
7589
7590 nla_put_failure:
7591 genlmsg_cancel(msg, hdr);
7592 nlmsg_free(msg);
7593}
7594
7595void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007596 struct net_device *netdev, const u8 *addr,
7597 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007598{
7599 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007600 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007601}
7602
7603void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007604 struct net_device *netdev, const u8 *addr,
7605 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007606{
Johannes Berge6d6e342009-07-01 21:26:47 +02007607 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7608 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007609}
7610
Samuel Ortizb23aa672009-07-01 21:26:54 +02007611void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7612 struct net_device *netdev, const u8 *bssid,
7613 const u8 *req_ie, size_t req_ie_len,
7614 const u8 *resp_ie, size_t resp_ie_len,
7615 u16 status, gfp_t gfp)
7616{
7617 struct sk_buff *msg;
7618 void *hdr;
7619
7620 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7621 if (!msg)
7622 return;
7623
7624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7625 if (!hdr) {
7626 nlmsg_free(msg);
7627 return;
7628 }
7629
David S. Miller9360ffd2012-03-29 04:41:26 -04007630 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7631 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7632 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7633 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7634 (req_ie &&
7635 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7636 (resp_ie &&
7637 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7638 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007639
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007640 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007641
Johannes Berg463d0182009-07-14 00:33:35 +02007642 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7643 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007644 return;
7645
7646 nla_put_failure:
7647 genlmsg_cancel(msg, hdr);
7648 nlmsg_free(msg);
7649
7650}
7651
7652void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7653 struct net_device *netdev, const u8 *bssid,
7654 const u8 *req_ie, size_t req_ie_len,
7655 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7656{
7657 struct sk_buff *msg;
7658 void *hdr;
7659
7660 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7661 if (!msg)
7662 return;
7663
7664 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7665 if (!hdr) {
7666 nlmsg_free(msg);
7667 return;
7668 }
7669
David S. Miller9360ffd2012-03-29 04:41:26 -04007670 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7671 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7672 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7673 (req_ie &&
7674 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7675 (resp_ie &&
7676 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7677 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007678
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007679 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007680
Johannes Berg463d0182009-07-14 00:33:35 +02007681 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7682 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007683 return;
7684
7685 nla_put_failure:
7686 genlmsg_cancel(msg, hdr);
7687 nlmsg_free(msg);
7688
7689}
7690
7691void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7692 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02007693 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007694{
7695 struct sk_buff *msg;
7696 void *hdr;
7697
Johannes Berg667503d2009-07-07 03:56:11 +02007698 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007699 if (!msg)
7700 return;
7701
7702 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7703 if (!hdr) {
7704 nlmsg_free(msg);
7705 return;
7706 }
7707
David S. Miller9360ffd2012-03-29 04:41:26 -04007708 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7709 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7710 (from_ap && reason &&
7711 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7712 (from_ap &&
7713 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7714 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7715 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007716
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007717 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007718
Johannes Berg463d0182009-07-14 00:33:35 +02007719 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7720 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007721 return;
7722
7723 nla_put_failure:
7724 genlmsg_cancel(msg, hdr);
7725 nlmsg_free(msg);
7726
7727}
7728
Johannes Berg04a773a2009-04-19 21:24:32 +02007729void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7730 struct net_device *netdev, const u8 *bssid,
7731 gfp_t gfp)
7732{
7733 struct sk_buff *msg;
7734 void *hdr;
7735
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007737 if (!msg)
7738 return;
7739
7740 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7741 if (!hdr) {
7742 nlmsg_free(msg);
7743 return;
7744 }
7745
David S. Miller9360ffd2012-03-29 04:41:26 -04007746 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7747 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7748 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7749 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007750
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007751 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007752
Johannes Berg463d0182009-07-14 00:33:35 +02007753 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7754 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007755 return;
7756
7757 nla_put_failure:
7758 genlmsg_cancel(msg, hdr);
7759 nlmsg_free(msg);
7760}
7761
Javier Cardonac93b5e72011-04-07 15:08:34 -07007762void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7763 struct net_device *netdev,
7764 const u8 *macaddr, const u8* ie, u8 ie_len,
7765 gfp_t gfp)
7766{
7767 struct sk_buff *msg;
7768 void *hdr;
7769
7770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7771 if (!msg)
7772 return;
7773
7774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7775 if (!hdr) {
7776 nlmsg_free(msg);
7777 return;
7778 }
7779
David S. Miller9360ffd2012-03-29 04:41:26 -04007780 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7781 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7782 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7783 (ie_len && ie &&
7784 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7785 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007786
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007787 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007788
7789 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7790 nl80211_mlme_mcgrp.id, gfp);
7791 return;
7792
7793 nla_put_failure:
7794 genlmsg_cancel(msg, hdr);
7795 nlmsg_free(msg);
7796}
7797
Jouni Malinena3b8b052009-03-27 21:59:49 +02007798void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7799 struct net_device *netdev, const u8 *addr,
7800 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007801 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007802{
7803 struct sk_buff *msg;
7804 void *hdr;
7805
Johannes Berge6d6e342009-07-01 21:26:47 +02007806 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007807 if (!msg)
7808 return;
7809
7810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7811 if (!hdr) {
7812 nlmsg_free(msg);
7813 return;
7814 }
7815
David S. Miller9360ffd2012-03-29 04:41:26 -04007816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7818 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7819 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7820 (key_id != -1 &&
7821 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7822 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7823 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007824
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007825 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007826
Johannes Berg463d0182009-07-14 00:33:35 +02007827 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7828 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007829 return;
7830
7831 nla_put_failure:
7832 genlmsg_cancel(msg, hdr);
7833 nlmsg_free(msg);
7834}
7835
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007836void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7837 struct ieee80211_channel *channel_before,
7838 struct ieee80211_channel *channel_after)
7839{
7840 struct sk_buff *msg;
7841 void *hdr;
7842 struct nlattr *nl_freq;
7843
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007844 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007845 if (!msg)
7846 return;
7847
7848 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7849 if (!hdr) {
7850 nlmsg_free(msg);
7851 return;
7852 }
7853
7854 /*
7855 * Since we are applying the beacon hint to a wiphy we know its
7856 * wiphy_idx is valid
7857 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7859 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007860
7861 /* Before */
7862 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7863 if (!nl_freq)
7864 goto nla_put_failure;
7865 if (nl80211_msg_put_channel(msg, channel_before))
7866 goto nla_put_failure;
7867 nla_nest_end(msg, nl_freq);
7868
7869 /* After */
7870 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7871 if (!nl_freq)
7872 goto nla_put_failure;
7873 if (nl80211_msg_put_channel(msg, channel_after))
7874 goto nla_put_failure;
7875 nla_nest_end(msg, nl_freq);
7876
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007877 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007878
Johannes Berg463d0182009-07-14 00:33:35 +02007879 rcu_read_lock();
7880 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7881 GFP_ATOMIC);
7882 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007883
7884 return;
7885
7886nla_put_failure:
7887 genlmsg_cancel(msg, hdr);
7888 nlmsg_free(msg);
7889}
7890
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007891static void nl80211_send_remain_on_chan_event(
7892 int cmd, struct cfg80211_registered_device *rdev,
7893 struct net_device *netdev, u64 cookie,
7894 struct ieee80211_channel *chan,
7895 enum nl80211_channel_type channel_type,
7896 unsigned int duration, gfp_t gfp)
7897{
7898 struct sk_buff *msg;
7899 void *hdr;
7900
7901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7902 if (!msg)
7903 return;
7904
7905 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7906 if (!hdr) {
7907 nlmsg_free(msg);
7908 return;
7909 }
7910
David S. Miller9360ffd2012-03-29 04:41:26 -04007911 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7912 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7913 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7914 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7915 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7916 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007917
David S. Miller9360ffd2012-03-29 04:41:26 -04007918 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7919 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7920 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007921
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007922 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007923
7924 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7925 nl80211_mlme_mcgrp.id, gfp);
7926 return;
7927
7928 nla_put_failure:
7929 genlmsg_cancel(msg, hdr);
7930 nlmsg_free(msg);
7931}
7932
7933void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7934 struct net_device *netdev, u64 cookie,
7935 struct ieee80211_channel *chan,
7936 enum nl80211_channel_type channel_type,
7937 unsigned int duration, gfp_t gfp)
7938{
7939 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7940 rdev, netdev, cookie, chan,
7941 channel_type, duration, gfp);
7942}
7943
7944void nl80211_send_remain_on_channel_cancel(
7945 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7946 u64 cookie, struct ieee80211_channel *chan,
7947 enum nl80211_channel_type channel_type, gfp_t gfp)
7948{
7949 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7950 rdev, netdev, cookie, chan,
7951 channel_type, 0, gfp);
7952}
7953
Johannes Berg98b62182009-12-23 13:15:44 +01007954void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7955 struct net_device *dev, const u8 *mac_addr,
7956 struct station_info *sinfo, gfp_t gfp)
7957{
7958 struct sk_buff *msg;
7959
7960 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7961 if (!msg)
7962 return;
7963
John W. Linville66266b32012-03-15 13:25:41 -04007964 if (nl80211_send_station(msg, 0, 0, 0,
7965 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007966 nlmsg_free(msg);
7967 return;
7968 }
7969
7970 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7971 nl80211_mlme_mcgrp.id, gfp);
7972}
7973
Jouni Malinenec15e682011-03-23 15:29:52 +02007974void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7975 struct net_device *dev, const u8 *mac_addr,
7976 gfp_t gfp)
7977{
7978 struct sk_buff *msg;
7979 void *hdr;
7980
7981 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7982 if (!msg)
7983 return;
7984
7985 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7986 if (!hdr) {
7987 nlmsg_free(msg);
7988 return;
7989 }
7990
David S. Miller9360ffd2012-03-29 04:41:26 -04007991 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7992 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
7993 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02007994
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007995 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007996
7997 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7998 nl80211_mlme_mcgrp.id, gfp);
7999 return;
8000
8001 nla_put_failure:
8002 genlmsg_cancel(msg, hdr);
8003 nlmsg_free(msg);
8004}
8005
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008006static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8007 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008008{
8009 struct wireless_dev *wdev = dev->ieee80211_ptr;
8010 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8011 struct sk_buff *msg;
8012 void *hdr;
8013 int err;
8014 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8015
8016 if (!nlpid)
8017 return false;
8018
8019 msg = nlmsg_new(100, gfp);
8020 if (!msg)
8021 return true;
8022
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008023 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008024 if (!hdr) {
8025 nlmsg_free(msg);
8026 return true;
8027 }
8028
David S. Miller9360ffd2012-03-29 04:41:26 -04008029 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8030 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8031 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8032 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008033
8034 err = genlmsg_end(msg, hdr);
8035 if (err < 0) {
8036 nlmsg_free(msg);
8037 return true;
8038 }
8039
8040 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8041 return true;
8042
8043 nla_put_failure:
8044 genlmsg_cancel(msg, hdr);
8045 nlmsg_free(msg);
8046 return true;
8047}
8048
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008049bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8050{
8051 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8052 addr, gfp);
8053}
8054
8055bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8056 const u8 *addr, gfp_t gfp)
8057{
8058 return __nl80211_unexpected_frame(dev,
8059 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8060 addr, gfp);
8061}
8062
Johannes Berg2e161f72010-08-12 15:38:38 +02008063int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8064 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008065 int freq, int sig_dbm,
8066 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008067{
8068 struct sk_buff *msg;
8069 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008070
8071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8072 if (!msg)
8073 return -ENOMEM;
8074
Johannes Berg2e161f72010-08-12 15:38:38 +02008075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008076 if (!hdr) {
8077 nlmsg_free(msg);
8078 return -ENOMEM;
8079 }
8080
David S. Miller9360ffd2012-03-29 04:41:26 -04008081 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8082 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8083 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8084 (sig_dbm &&
8085 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8086 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8087 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008088
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008089 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008090
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008091 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008092
8093 nla_put_failure:
8094 genlmsg_cancel(msg, hdr);
8095 nlmsg_free(msg);
8096 return -ENOBUFS;
8097}
8098
Johannes Berg2e161f72010-08-12 15:38:38 +02008099void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8100 struct net_device *netdev, u64 cookie,
8101 const u8 *buf, size_t len, bool ack,
8102 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008103{
8104 struct sk_buff *msg;
8105 void *hdr;
8106
8107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8108 if (!msg)
8109 return;
8110
Johannes Berg2e161f72010-08-12 15:38:38 +02008111 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008112 if (!hdr) {
8113 nlmsg_free(msg);
8114 return;
8115 }
8116
David S. Miller9360ffd2012-03-29 04:41:26 -04008117 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8118 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8119 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8120 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8121 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8122 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008123
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008124 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008125
8126 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8127 return;
8128
8129 nla_put_failure:
8130 genlmsg_cancel(msg, hdr);
8131 nlmsg_free(msg);
8132}
8133
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008134void
8135nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8136 struct net_device *netdev,
8137 enum nl80211_cqm_rssi_threshold_event rssi_event,
8138 gfp_t gfp)
8139{
8140 struct sk_buff *msg;
8141 struct nlattr *pinfoattr;
8142 void *hdr;
8143
8144 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8145 if (!msg)
8146 return;
8147
8148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8149 if (!hdr) {
8150 nlmsg_free(msg);
8151 return;
8152 }
8153
David S. Miller9360ffd2012-03-29 04:41:26 -04008154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8156 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008157
8158 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8159 if (!pinfoattr)
8160 goto nla_put_failure;
8161
David S. Miller9360ffd2012-03-29 04:41:26 -04008162 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8163 rssi_event))
8164 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008165
8166 nla_nest_end(msg, pinfoattr);
8167
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008168 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008169
8170 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8171 nl80211_mlme_mcgrp.id, gfp);
8172 return;
8173
8174 nla_put_failure:
8175 genlmsg_cancel(msg, hdr);
8176 nlmsg_free(msg);
8177}
8178
Johannes Berge5497d72011-07-05 16:35:40 +02008179void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8180 struct net_device *netdev, const u8 *bssid,
8181 const u8 *replay_ctr, gfp_t gfp)
8182{
8183 struct sk_buff *msg;
8184 struct nlattr *rekey_attr;
8185 void *hdr;
8186
8187 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8188 if (!msg)
8189 return;
8190
8191 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8192 if (!hdr) {
8193 nlmsg_free(msg);
8194 return;
8195 }
8196
David S. Miller9360ffd2012-03-29 04:41:26 -04008197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8199 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8200 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008201
8202 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8203 if (!rekey_attr)
8204 goto nla_put_failure;
8205
David S. Miller9360ffd2012-03-29 04:41:26 -04008206 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8207 NL80211_REPLAY_CTR_LEN, replay_ctr))
8208 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008209
8210 nla_nest_end(msg, rekey_attr);
8211
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008212 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008213
8214 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8215 nl80211_mlme_mcgrp.id, gfp);
8216 return;
8217
8218 nla_put_failure:
8219 genlmsg_cancel(msg, hdr);
8220 nlmsg_free(msg);
8221}
8222
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008223void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8224 struct net_device *netdev, int index,
8225 const u8 *bssid, bool preauth, gfp_t gfp)
8226{
8227 struct sk_buff *msg;
8228 struct nlattr *attr;
8229 void *hdr;
8230
8231 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8232 if (!msg)
8233 return;
8234
8235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8236 if (!hdr) {
8237 nlmsg_free(msg);
8238 return;
8239 }
8240
David S. Miller9360ffd2012-03-29 04:41:26 -04008241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8242 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8243 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008244
8245 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8246 if (!attr)
8247 goto nla_put_failure;
8248
David S. Miller9360ffd2012-03-29 04:41:26 -04008249 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8250 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8251 (preauth &&
8252 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8253 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008254
8255 nla_nest_end(msg, attr);
8256
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008257 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008258
8259 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8260 nl80211_mlme_mcgrp.id, gfp);
8261 return;
8262
8263 nla_put_failure:
8264 genlmsg_cancel(msg, hdr);
8265 nlmsg_free(msg);
8266}
8267
Thomas Pedersen53145262012-04-06 13:35:47 -07008268void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8269 struct net_device *netdev, int freq,
8270 enum nl80211_channel_type type, gfp_t gfp)
8271{
8272 struct sk_buff *msg;
8273 void *hdr;
8274
8275 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8276 if (!msg)
8277 return;
8278
8279 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8280 if (!hdr) {
8281 nlmsg_free(msg);
8282 return;
8283 }
8284
John W. Linville7eab0f62012-04-12 14:25:14 -04008285 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8286 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8287 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8288 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008289
8290 genlmsg_end(msg, hdr);
8291
8292 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8293 nl80211_mlme_mcgrp.id, gfp);
8294 return;
8295
8296 nla_put_failure:
8297 genlmsg_cancel(msg, hdr);
8298 nlmsg_free(msg);
8299}
8300
Johannes Bergc063dbf2010-11-24 08:10:05 +01008301void
8302nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8303 struct net_device *netdev, const u8 *peer,
8304 u32 num_packets, gfp_t gfp)
8305{
8306 struct sk_buff *msg;
8307 struct nlattr *pinfoattr;
8308 void *hdr;
8309
8310 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8311 if (!msg)
8312 return;
8313
8314 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8315 if (!hdr) {
8316 nlmsg_free(msg);
8317 return;
8318 }
8319
David S. Miller9360ffd2012-03-29 04:41:26 -04008320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8321 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8322 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8323 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008324
8325 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8326 if (!pinfoattr)
8327 goto nla_put_failure;
8328
David S. Miller9360ffd2012-03-29 04:41:26 -04008329 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8330 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008331
8332 nla_nest_end(msg, pinfoattr);
8333
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008334 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008335
8336 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8337 nl80211_mlme_mcgrp.id, gfp);
8338 return;
8339
8340 nla_put_failure:
8341 genlmsg_cancel(msg, hdr);
8342 nlmsg_free(msg);
8343}
8344
Johannes Berg7f6cf312011-11-04 11:18:15 +01008345void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8346 u64 cookie, bool acked, gfp_t gfp)
8347{
8348 struct wireless_dev *wdev = dev->ieee80211_ptr;
8349 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8350 struct sk_buff *msg;
8351 void *hdr;
8352 int err;
8353
8354 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8355 if (!msg)
8356 return;
8357
8358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8359 if (!hdr) {
8360 nlmsg_free(msg);
8361 return;
8362 }
8363
David S. Miller9360ffd2012-03-29 04:41:26 -04008364 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8366 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8367 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8368 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8369 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008370
8371 err = genlmsg_end(msg, hdr);
8372 if (err < 0) {
8373 nlmsg_free(msg);
8374 return;
8375 }
8376
8377 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8378 nl80211_mlme_mcgrp.id, gfp);
8379 return;
8380
8381 nla_put_failure:
8382 genlmsg_cancel(msg, hdr);
8383 nlmsg_free(msg);
8384}
8385EXPORT_SYMBOL(cfg80211_probe_status);
8386
Johannes Berg5e760232011-11-04 11:18:17 +01008387void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8388 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008389 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008390{
8391 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8392 struct sk_buff *msg;
8393 void *hdr;
8394 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8395
8396 if (!nlpid)
8397 return;
8398
8399 msg = nlmsg_new(len + 100, gfp);
8400 if (!msg)
8401 return;
8402
8403 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8404 if (!hdr) {
8405 nlmsg_free(msg);
8406 return;
8407 }
8408
David S. Miller9360ffd2012-03-29 04:41:26 -04008409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8410 (freq &&
8411 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8412 (sig_dbm &&
8413 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8414 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8415 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008416
8417 genlmsg_end(msg, hdr);
8418
8419 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8420 return;
8421
8422 nla_put_failure:
8423 genlmsg_cancel(msg, hdr);
8424 nlmsg_free(msg);
8425}
8426EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8427
Jouni Malinen026331c2010-02-15 12:53:10 +02008428static int nl80211_netlink_notify(struct notifier_block * nb,
8429 unsigned long state,
8430 void *_notify)
8431{
8432 struct netlink_notify *notify = _notify;
8433 struct cfg80211_registered_device *rdev;
8434 struct wireless_dev *wdev;
8435
8436 if (state != NETLINK_URELEASE)
8437 return NOTIFY_DONE;
8438
8439 rcu_read_lock();
8440
Johannes Berg5e760232011-11-04 11:18:17 +01008441 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008442 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008443 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008444 if (rdev->ap_beacons_nlpid == notify->pid)
8445 rdev->ap_beacons_nlpid = 0;
8446 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008447
8448 rcu_read_unlock();
8449
8450 return NOTIFY_DONE;
8451}
8452
8453static struct notifier_block nl80211_netlink_notifier = {
8454 .notifier_call = nl80211_netlink_notify,
8455};
8456
Johannes Berg55682962007-09-20 13:09:35 -04008457/* initialisation/exit functions */
8458
8459int nl80211_init(void)
8460{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008461 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008462
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008463 err = genl_register_family_with_ops(&nl80211_fam,
8464 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008465 if (err)
8466 return err;
8467
Johannes Berg55682962007-09-20 13:09:35 -04008468 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8469 if (err)
8470 goto err_out;
8471
Johannes Berg2a519312009-02-10 21:25:55 +01008472 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8473 if (err)
8474 goto err_out;
8475
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008476 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8477 if (err)
8478 goto err_out;
8479
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008480 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8481 if (err)
8482 goto err_out;
8483
Johannes Bergaff89a92009-07-01 21:26:51 +02008484#ifdef CONFIG_NL80211_TESTMODE
8485 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8486 if (err)
8487 goto err_out;
8488#endif
8489
Jouni Malinen026331c2010-02-15 12:53:10 +02008490 err = netlink_register_notifier(&nl80211_netlink_notifier);
8491 if (err)
8492 goto err_out;
8493
Johannes Berg55682962007-09-20 13:09:35 -04008494 return 0;
8495 err_out:
8496 genl_unregister_family(&nl80211_fam);
8497 return err;
8498}
8499
8500void nl80211_exit(void)
8501{
Jouni Malinen026331c2010-02-15 12:53:10 +02008502 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008503 genl_unregister_family(&nl80211_fam);
8504}