blob: 771e766968b16ca55c1419be3665f557b2e394b8 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Driver interaction with Linux nl80211/cfg80211
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
8 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011 */
12
13#include "includes.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include <sys/types.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015#include <fcntl.h>
16#include <net/if.h>
17#include <netlink/genl/genl.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include <netlink/genl/ctrl.h>
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070019#ifdef CONFIG_LIBNL3_ROUTE
20#include <netlink/route/neighbour.h>
21#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <linux/rtnetlink.h>
23#include <netpacket/packet.h>
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080024#include <linux/errqueue.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025
26#include "common.h"
27#include "eloop.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080028#include "common/qca-vendor.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070029#include "common/qca-vendor-attr.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080031#include "common/ieee802_11_common.h"
Paul Stewart092955c2017-02-06 09:13:09 -080032#include "common/wpa_common.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080033#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080035#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "linux_ioctl.h"
37#include "radiotap.h"
38#include "radiotap_iter.h"
39#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080040#include "driver_nl80211.h"
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080041
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080042
Hai Shalom39ba6fc2019-01-22 12:40:38 -080043/* support for extack if compilation headers are too old */
44#ifndef NETLINK_EXT_ACK
45#define NETLINK_EXT_ACK 11
46enum nlmsgerr_attrs {
47 NLMSGERR_ATTR_UNUSED,
48 NLMSGERR_ATTR_MSG,
49 NLMSGERR_ATTR_OFFS,
50 NLMSGERR_ATTR_COOKIE,
51
52 __NLMSGERR_ATTR_MAX,
53 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
54};
55#endif
56#ifndef NLM_F_CAPPED
57#define NLM_F_CAPPED 0x100
58#endif
59#ifndef NLM_F_ACK_TLVS
60#define NLM_F_ACK_TLVS 0x200
61#endif
62#ifndef SOL_NETLINK
63#define SOL_NETLINK 270
64#endif
65
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080066#ifndef CONFIG_LIBNL20
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067/*
68 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
69 * but when you free a socket again it will mess up its bitmap and
70 * and use the wrong number the next time it needs a socket ID.
71 * Therefore, we wrap the handle alloc/destroy and add our own pid
72 * accounting.
73 */
74static uint32_t port_bitmap[32] = { 0 };
75
76static struct nl_handle *nl80211_handle_alloc(void *cb)
77{
78 struct nl_handle *handle;
79 uint32_t pid = getpid() & 0x3FFFFF;
80 int i;
81
82 handle = nl_handle_alloc_cb(cb);
83
84 for (i = 0; i < 1024; i++) {
85 if (port_bitmap[i / 32] & (1 << (i % 32)))
86 continue;
87 port_bitmap[i / 32] |= 1 << (i % 32);
88 pid += i << 22;
89 break;
90 }
91
92 nl_socket_set_local_port(handle, pid);
93
94 return handle;
95}
96
97static void nl80211_handle_destroy(struct nl_handle *handle)
98{
99 uint32_t port = nl_socket_get_local_port(handle);
100
101 port >>= 22;
102 port_bitmap[port / 32] &= ~(1 << (port % 32));
103
104 nl_handle_destroy(handle);
105}
106#endif /* CONFIG_LIBNL20 */
107
108
Dmitry Shmidt54605472013-11-08 11:10:19 -0800109#ifdef ANDROID
110/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -0800111#undef nl_socket_set_nonblocking
112#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800113
Dmitry Shmidt54605472013-11-08 11:10:19 -0800114#endif /* ANDROID */
115
116
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800117static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
118{
119 struct nl_handle *handle;
120
121 handle = nl80211_handle_alloc(cb);
122 if (handle == NULL) {
123 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
124 "callbacks (%s)", dbg);
125 return NULL;
126 }
127
128 if (genl_connect(handle)) {
129 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
130 "netlink (%s)", dbg);
131 nl80211_handle_destroy(handle);
132 return NULL;
133 }
134
135 return handle;
136}
137
138
139static void nl_destroy_handles(struct nl_handle **handle)
140{
141 if (*handle == NULL)
142 return;
143 nl80211_handle_destroy(*handle);
144 *handle = NULL;
145}
146
147
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700148#if __WORDSIZE == 64
149#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
150#else
151#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
152#endif
153
154static void nl80211_register_eloop_read(struct nl_handle **handle,
155 eloop_sock_handler handler,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700156 void *eloop_data, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700157{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800158#ifdef CONFIG_LIBNL20
159 /*
160 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
161 * by default. It is possible to hit that limit in some cases where
162 * operations are blocked, e.g., with a burst of Deauthentication frames
163 * to hostapd and STA entry deletion. Try to increase the buffer to make
164 * this less likely to occur.
165 */
166 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
167 wpa_printf(MSG_DEBUG,
168 "nl80211: Could not set nl_socket RX buffer size: %s",
169 strerror(errno));
170 /* continue anyway with the default (smaller) buffer */
171 }
172#endif /* CONFIG_LIBNL20 */
173
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700174 nl_socket_set_nonblocking(*handle);
175 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
176 eloop_data, *handle);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700177 if (!persist)
178 *handle = (void *) (((intptr_t) *handle) ^
179 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700180}
181
182
Roshan Pius3a1667e2018-07-03 15:17:14 -0700183static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700184{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700185 if (!persist)
186 *handle = (void *) (((intptr_t) *handle) ^
187 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700188 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
189 nl_destroy_handles(handle);
190}
191
192
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800193static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800194static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800196static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700197static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
198 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800201wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800202 const u8 *set_addr, int first,
203 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800204static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800206 const u8 *buf, size_t buf_len, u64 *cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800207 int no_cck, int no_ack, int offchanok,
208 const u16 *csa_offs, size_t csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800209static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
210 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800212#define IFIDX_ANY -1
213
214static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
215 int ifidx_reason);
216static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
217 int ifidx_reason);
218static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
219 int ifidx_reason);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700220
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700221static int nl80211_set_channel(struct i802_bss *bss,
222 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
224 int ifindex, int disabled);
225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800226static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
227 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800228
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700229static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800230static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700231#ifdef CONFIG_MESH
232static int nl80211_put_mesh_config(struct nl_msg *msg,
233 struct wpa_driver_mesh_bss_params *params);
234#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -0800235static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
236 int reason);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700237
238
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800239/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800240enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800241{
242 switch (width) {
243 case NL80211_CHAN_WIDTH_20_NOHT:
244 return CHAN_WIDTH_20_NOHT;
245 case NL80211_CHAN_WIDTH_20:
246 return CHAN_WIDTH_20;
247 case NL80211_CHAN_WIDTH_40:
248 return CHAN_WIDTH_40;
249 case NL80211_CHAN_WIDTH_80:
250 return CHAN_WIDTH_80;
251 case NL80211_CHAN_WIDTH_80P80:
252 return CHAN_WIDTH_80P80;
253 case NL80211_CHAN_WIDTH_160:
254 return CHAN_WIDTH_160;
255 }
256 return CHAN_WIDTH_UNKNOWN;
257}
258
259
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800260int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800261{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700262 return nlmode == NL80211_IFTYPE_AP ||
263 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264}
265
266
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800267int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800268{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700269 return nlmode == NL80211_IFTYPE_STATION ||
270 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800271}
272
273
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700274static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700276 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
277 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279
280
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800281struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
282 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700283{
284 struct i802_bss *bss;
285
286 for (bss = drv->first_bss; bss; bss = bss->next) {
287 if (bss->ifindex == ifindex)
288 return bss;
289 }
290
291 return NULL;
292}
293
294
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800295static int is_mesh_interface(enum nl80211_iftype nlmode)
296{
297 return nlmode == NL80211_IFTYPE_MESH_POINT;
298}
299
300
301void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700302{
303 if (drv->associated)
304 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
305 drv->associated = 0;
306 os_memset(drv->bssid, 0, ETH_ALEN);
307}
308
309
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310/* nl80211 code */
311static int ack_handler(struct nl_msg *msg, void *arg)
312{
313 int *err = arg;
314 *err = 0;
315 return NL_STOP;
316}
317
318static int finish_handler(struct nl_msg *msg, void *arg)
319{
320 int *ret = arg;
321 *ret = 0;
322 return NL_SKIP;
323}
324
325static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
326 void *arg)
327{
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800328 struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1;
329 int len = nlh->nlmsg_len;
330 struct nlattr *attrs;
331 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 int *ret = arg;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800333 int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 *ret = err->error;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800336
337 if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
338 return NL_SKIP;
339
340 if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
341 ack_len += err->msg.nlmsg_len - sizeof(*nlh);
342
343 if (len <= ack_len)
344 return NL_STOP;
345
346 attrs = (void *) ((unsigned char *) nlh + ack_len);
347 len -= ack_len;
348
349 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
350 if (tb[NLMSGERR_ATTR_MSG]) {
351 len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]),
352 nla_len(tb[NLMSGERR_ATTR_MSG]));
353 wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s",
354 len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG]));
355 }
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 return NL_SKIP;
358}
359
360
361static int no_seq_check(struct nl_msg *msg, void *arg)
362{
363 return NL_OK;
364}
365
366
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800367static void nl80211_nlmsg_clear(struct nl_msg *msg)
368{
369 /*
370 * Clear nlmsg data, e.g., to make sure key material is not left in
371 * heap memory for unnecessarily long time.
372 */
373 if (msg) {
374 struct nlmsghdr *hdr = nlmsg_hdr(msg);
375 void *data = nlmsg_data(hdr);
376 /*
377 * This would use nlmsg_datalen() or the older nlmsg_len() if
378 * only libnl were to maintain a stable API.. Neither will work
379 * with all released versions, so just calculate the length
380 * here.
381 */
382 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
383
384 os_memset(data, 0, len);
385 }
386}
387
388
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800389static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 struct nl_handle *nl_handle, struct nl_msg *msg,
391 int (*valid_handler)(struct nl_msg *, void *),
392 void *valid_data)
393{
394 struct nl_cb *cb;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800395 int err = -ENOMEM, opt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800397 if (!msg)
398 return -ENOMEM;
399
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800400 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700401 if (!cb)
402 goto out;
403
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800404 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
405 opt = 1;
406 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
407 NETLINK_EXT_ACK, &opt, sizeof(opt));
408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 err = nl_send_auto_complete(nl_handle, msg);
410 if (err < 0)
411 goto out;
412
413 err = 1;
414
415 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
416 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
417 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
418
419 if (valid_handler)
420 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
421 valid_handler, valid_data);
422
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700423 while (err > 0) {
424 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700425 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700426 wpa_printf(MSG_INFO,
427 "nl80211: %s->nl_recvmsgs failed: %d",
428 __func__, res);
429 }
430 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 out:
432 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800433 if (!valid_handler && valid_data == (void *) -1)
434 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435 nlmsg_free(msg);
436 return err;
437}
438
439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
441 struct nl_msg *msg,
442 int (*valid_handler)(struct nl_msg *, void *),
443 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800445 return send_and_recv(drv->global, drv->global->nl, msg,
446 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447}
448
449
450struct family_data {
451 const char *group;
452 int id;
453};
454
455
456static int family_handler(struct nl_msg *msg, void *arg)
457{
458 struct family_data *res = arg;
459 struct nlattr *tb[CTRL_ATTR_MAX + 1];
460 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
461 struct nlattr *mcgrp;
462 int i;
463
464 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
465 genlmsg_attrlen(gnlh, 0), NULL);
466 if (!tb[CTRL_ATTR_MCAST_GROUPS])
467 return NL_SKIP;
468
469 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
470 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
471 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
472 nla_len(mcgrp), NULL);
473 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
474 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
475 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
476 res->group,
477 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
478 continue;
479 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
480 break;
481 };
482
483 return NL_SKIP;
484}
485
486
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800487static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 const char *family, const char *group)
489{
490 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800491 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492 struct family_data res = { group, -ENOENT };
493
494 msg = nlmsg_alloc();
495 if (!msg)
496 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800497 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
498 0, 0, CTRL_CMD_GETFAMILY, 0) ||
499 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
500 nlmsg_free(msg);
501 return -1;
502 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800504 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505 if (ret == 0)
506 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 return ret;
508}
509
510
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800511void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
512 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800513{
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700514 if (TEST_FAIL())
515 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
517 0, flags, cmd, 0);
518}
519
520
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800521static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
522{
523 if (bss->wdev_id_set)
524 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
525 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
526}
527
528
529struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
530{
531 struct nl_msg *msg;
532
533 msg = nlmsg_alloc();
534 if (!msg)
535 return NULL;
536
537 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
538 nl80211_set_iface_id(msg, bss) < 0) {
539 nlmsg_free(msg);
540 return NULL;
541 }
542
543 return msg;
544}
545
546
547static struct nl_msg *
548nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
549 int flags, uint8_t cmd)
550{
551 struct nl_msg *msg;
552
553 msg = nlmsg_alloc();
554 if (!msg)
555 return NULL;
556
557 if (!nl80211_cmd(drv, msg, flags, cmd) ||
558 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
559 nlmsg_free(msg);
560 return NULL;
561 }
562
563 return msg;
564}
565
566
567struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
568 uint8_t cmd)
569{
570 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
571}
572
573
574struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
575{
576 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
577}
578
579
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800580struct wiphy_idx_data {
581 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700582 enum nl80211_iftype nlmode;
583 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800584};
585
586
587static int netdev_info_handler(struct nl_msg *msg, void *arg)
588{
589 struct nlattr *tb[NL80211_ATTR_MAX + 1];
590 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
591 struct wiphy_idx_data *info = arg;
592
593 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
594 genlmsg_attrlen(gnlh, 0), NULL);
595
596 if (tb[NL80211_ATTR_WIPHY])
597 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
598
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700599 if (tb[NL80211_ATTR_IFTYPE])
600 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
601
602 if (tb[NL80211_ATTR_MAC] && info->macaddr)
603 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
604 ETH_ALEN);
605
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800606 return NL_SKIP;
607}
608
609
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800610int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800611{
612 struct nl_msg *msg;
613 struct wiphy_idx_data data = {
614 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700615 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800616 };
617
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800618 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
619 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620
621 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
622 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623 return -1;
624}
625
626
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700627static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
628{
629 struct nl_msg *msg;
630 struct wiphy_idx_data data = {
631 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
632 .macaddr = NULL,
633 };
634
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800635 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
636 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700637
638 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
639 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700640 return NL80211_IFTYPE_UNSPECIFIED;
641}
642
643
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700644static int nl80211_get_macaddr(struct i802_bss *bss)
645{
646 struct nl_msg *msg;
647 struct wiphy_idx_data data = {
648 .macaddr = bss->addr,
649 };
650
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800651 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
652 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700653
654 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700655}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700656
657
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800658static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
659 struct nl80211_wiphy_data *w)
660{
661 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800662 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800663
664 msg = nlmsg_alloc();
665 if (!msg)
666 return -1;
667
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800668 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
669 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
670 nlmsg_free(msg);
671 return -1;
672 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800673
674 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800675 if (ret) {
676 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
677 "failed: ret=%d (%s)",
678 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800679 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800680 return ret;
681}
682
683
684static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
685{
686 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700687 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800688
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800689 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800690
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700691 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700692 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700693 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
694 __func__, res);
695 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800696}
697
698
699static int process_beacon_event(struct nl_msg *msg, void *arg)
700{
701 struct nl80211_wiphy_data *w = arg;
702 struct wpa_driver_nl80211_data *drv;
703 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
704 struct nlattr *tb[NL80211_ATTR_MAX + 1];
705 union wpa_event_data event;
706
707 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
708 genlmsg_attrlen(gnlh, 0), NULL);
709
710 if (gnlh->cmd != NL80211_CMD_FRAME) {
711 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
712 gnlh->cmd);
713 return NL_SKIP;
714 }
715
716 if (!tb[NL80211_ATTR_FRAME])
717 return NL_SKIP;
718
719 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
720 wiphy_list) {
721 os_memset(&event, 0, sizeof(event));
722 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
723 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
724 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
725 }
726
727 return NL_SKIP;
728}
729
730
731static struct nl80211_wiphy_data *
732nl80211_get_wiphy_data_ap(struct i802_bss *bss)
733{
734 static DEFINE_DL_LIST(nl80211_wiphys);
735 struct nl80211_wiphy_data *w;
736 int wiphy_idx, found = 0;
737 struct i802_bss *tmp_bss;
Paul Stewart092955c2017-02-06 09:13:09 -0800738 u8 channel;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800739
740 if (bss->wiphy_data != NULL)
741 return bss->wiphy_data;
742
743 wiphy_idx = nl80211_get_wiphy_index(bss);
744
745 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
746 if (w->wiphy_idx == wiphy_idx)
747 goto add;
748 }
749
750 /* alloc new one */
751 w = os_zalloc(sizeof(*w));
752 if (w == NULL)
753 return NULL;
754 w->wiphy_idx = wiphy_idx;
755 dl_list_init(&w->bsss);
756 dl_list_init(&w->drvs);
757
Paul Stewart092955c2017-02-06 09:13:09 -0800758 /* Beacon frames not supported in IEEE 802.11ad */
759 if (ieee80211_freq_to_chan(bss->freq, &channel) !=
760 HOSTAPD_MODE_IEEE80211AD) {
761 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
762 if (!w->nl_cb) {
763 os_free(w);
764 return NULL;
765 }
766 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
767 no_seq_check, NULL);
768 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
769 process_beacon_event, w);
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000770
Paul Stewart092955c2017-02-06 09:13:09 -0800771 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
772 "wiphy beacons");
773 if (w->nl_beacons == NULL) {
774 os_free(w);
775 return NULL;
776 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000777
Paul Stewart092955c2017-02-06 09:13:09 -0800778 if (nl80211_register_beacons(bss->drv, w)) {
779 nl_destroy_handles(&w->nl_beacons);
780 os_free(w);
781 return NULL;
782 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000783
Paul Stewart092955c2017-02-06 09:13:09 -0800784 nl80211_register_eloop_read(&w->nl_beacons,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700785 nl80211_recv_beacons, w, 0);
Paul Stewart092955c2017-02-06 09:13:09 -0800786 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800787
788 dl_list_add(&nl80211_wiphys, &w->list);
789
790add:
791 /* drv entry for this bss already there? */
792 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
793 if (tmp_bss->drv == bss->drv) {
794 found = 1;
795 break;
796 }
797 }
798 /* if not add it */
799 if (!found)
800 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
801
802 dl_list_add(&w->bsss, &bss->wiphy_list);
803 bss->wiphy_data = w;
804 return w;
805}
806
807
808static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
809{
810 struct nl80211_wiphy_data *w = bss->wiphy_data;
811 struct i802_bss *tmp_bss;
812 int found = 0;
813
814 if (w == NULL)
815 return;
816 bss->wiphy_data = NULL;
817 dl_list_del(&bss->wiphy_list);
818
819 /* still any for this drv present? */
820 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
821 if (tmp_bss->drv == bss->drv) {
822 found = 1;
823 break;
824 }
825 }
826 /* if not remove it */
827 if (!found)
828 dl_list_del(&bss->drv->wiphy_list);
829
830 if (!dl_list_empty(&w->bsss))
831 return;
832
Paul Stewart092955c2017-02-06 09:13:09 -0800833 if (w->nl_beacons)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700834 nl80211_destroy_eloop_handle(&w->nl_beacons, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800835
836 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800837 dl_list_del(&w->list);
838 os_free(w);
839}
840
841
Dmitry Shmidte4663042016-04-04 10:07:49 -0700842static unsigned int nl80211_get_ifindex(void *priv)
843{
844 struct i802_bss *bss = priv;
845 struct wpa_driver_nl80211_data *drv = bss->drv;
846
847 return drv->ifindex;
848}
849
850
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
852{
853 struct i802_bss *bss = priv;
854 struct wpa_driver_nl80211_data *drv = bss->drv;
855 if (!drv->associated)
856 return -1;
857 os_memcpy(bssid, drv->bssid, ETH_ALEN);
858 return 0;
859}
860
861
862static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
863{
864 struct i802_bss *bss = priv;
865 struct wpa_driver_nl80211_data *drv = bss->drv;
866 if (!drv->associated)
867 return -1;
868 os_memcpy(ssid, drv->ssid, drv->ssid_len);
869 return drv->ssid_len;
870}
871
872
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800873static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700874 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
875 int ifindex, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876{
877 union wpa_event_data event;
878
Dmitry Shmidte4663042016-04-04 10:07:49 -0700879 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800880 if (if_nametoindex(drv->first_bss->ifname) == 0) {
881 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
882 drv->first_bss->ifname);
883 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700884 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800885 if (!drv->if_removed)
886 return;
887 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
888 drv->first_bss->ifname);
889 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890 }
891
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800892 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700893 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800894 os_strlcpy(event.interface_status.ifname, ifname,
895 sizeof(event.interface_status.ifname));
896 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700897 if (drv)
898 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
899 else
900 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
901 &event);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800902}
903
904
905static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700906 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
907 int ifindex, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800908{
909 union wpa_event_data event;
910
Dmitry Shmidte4663042016-04-04 10:07:49 -0700911 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800912 if (drv->if_removed) {
913 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
914 ifname);
915 return;
916 }
917 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
918 ifname);
919 drv->if_removed = 1;
920 } else {
921 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
922 ifname);
923 }
924
925 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700926 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800927 os_strlcpy(event.interface_status.ifname, ifname,
928 sizeof(event.interface_status.ifname));
929 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700930 if (drv)
931 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
932 else
933 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
934 &event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935}
936
937
938static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
939 u8 *buf, size_t len)
940{
941 int attrlen, rta_len;
942 struct rtattr *attr;
943
944 attrlen = len;
945 attr = (struct rtattr *) buf;
946
947 rta_len = RTA_ALIGN(sizeof(struct rtattr));
948 while (RTA_OK(attr, attrlen)) {
949 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800950 if (os_strcmp(((char *) attr) + rta_len,
951 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952 return 1;
953 else
954 break;
955 }
956 attr = RTA_NEXT(attr, attrlen);
957 }
958
959 return 0;
960}
961
962
963static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
964 int ifindex, u8 *buf, size_t len)
965{
966 if (drv->ifindex == ifindex)
967 return 1;
968
969 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800970 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
972 "interface");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700973 if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0)
974 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975 return 1;
976 }
977
978 return 0;
979}
980
981
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800982static struct wpa_driver_nl80211_data *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700983nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len,
984 int *init_failed)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985{
986 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987 int res;
988
989 if (init_failed)
990 *init_failed = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991 dl_list_for_each(drv, &global->interfaces,
992 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700993 res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len);
994 if (res < 0) {
995 wpa_printf(MSG_DEBUG,
996 "nl80211: Found matching own interface, but failed to complete reinitialization");
997 if (init_failed)
998 *init_failed = 1;
999 return drv;
1000 }
1001 if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 return drv;
1003 }
1004 return NULL;
1005}
1006
1007
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001008static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001009 int ifindex, int notify)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001010{
1011 struct i802_bss *bss;
1012 u8 addr[ETH_ALEN];
1013
1014 bss = get_bss_ifindex(drv, ifindex);
1015 if (bss &&
1016 linux_get_ifhwaddr(drv->global->ioctl_sock,
1017 bss->ifname, addr) < 0) {
1018 wpa_printf(MSG_DEBUG,
1019 "nl80211: %s: failed to re-read MAC address",
1020 bss->ifname);
1021 } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1022 wpa_printf(MSG_DEBUG,
1023 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1024 MACSTR " to " MACSTR,
1025 ifindex, bss->ifname,
1026 MAC2STR(bss->addr), MAC2STR(addr));
1027 os_memcpy(bss->addr, addr, ETH_ALEN);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001028 if (notify)
1029 wpa_supplicant_event(drv->ctx,
1030 EVENT_INTERFACE_MAC_CHANGED, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001031 }
1032}
1033
1034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
1036 struct ifinfomsg *ifi,
1037 u8 *buf, size_t len)
1038{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001039 struct nl80211_global *global = ctx;
1040 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001041 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042 struct rtattr *attr;
1043 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001045 char ifname[IFNAMSIZ + 1];
1046 char extra[100], *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001047 int init_failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001049 extra[0] = '\0';
1050 pos = extra;
1051 end = pos + sizeof(extra);
1052 ifname[0] = '\0';
1053
1054 attrlen = len;
1055 attr = (struct rtattr *) buf;
1056 while (RTA_OK(attr, attrlen)) {
1057 switch (attr->rta_type) {
1058 case IFLA_IFNAME:
1059 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1060 break;
1061 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1062 ifname[RTA_PAYLOAD(attr)] = '\0';
1063 break;
1064 case IFLA_MASTER:
1065 brid = nla_get_u32((struct nlattr *) attr);
1066 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1067 break;
1068 case IFLA_WIRELESS:
1069 pos += os_snprintf(pos, end - pos, " wext");
1070 break;
1071 case IFLA_OPERSTATE:
1072 pos += os_snprintf(pos, end - pos, " operstate=%u",
1073 nla_get_u32((struct nlattr *) attr));
1074 break;
1075 case IFLA_LINKMODE:
1076 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1077 nla_get_u32((struct nlattr *) attr));
1078 break;
1079 }
1080 attr = RTA_NEXT(attr, attrlen);
1081 }
1082 extra[sizeof(extra) - 1] = '\0';
1083
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001084 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1085 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1086 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1088 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1089 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1090 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1091
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001092 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001093 if (!drv)
1094 goto event_newlink;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001095 if (init_failed)
1096 return; /* do not update interface state */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001097
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001099 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001100 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001101 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001102 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1103 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001104 drv->ignore_if_down_event = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001105 /* Re-read MAC address as it may have changed */
1106 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001107 return;
1108 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001109 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
1110 namebuf, ifname);
1111 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1112 wpa_printf(MSG_DEBUG,
1113 "nl80211: Not the main interface (%s) - do not indicate interface down",
1114 drv->first_bss->ifname);
1115 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1117 "event generated by mode change");
1118 drv->ignore_if_down_event = 0;
1119 } else {
1120 drv->if_disabled = 1;
1121 wpa_supplicant_event(drv->ctx,
1122 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001123
1124 /*
1125 * Try to get drv again, since it may be removed as
1126 * part of the EVENT_INTERFACE_DISABLED handling for
1127 * dynamic interfaces
1128 */
1129 drv = nl80211_find_drv(global, ifi->ifi_index,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001130 buf, len, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001131 if (!drv)
1132 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 }
1135
1136 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07001137 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001138 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001139 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001140 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1141 "event since interface %s is down",
1142 namebuf);
Hai Shalomc9e41a12018-07-31 14:41:42 -07001143 return;
1144 }
1145 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
1146 namebuf, ifname);
1147 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1148 wpa_printf(MSG_DEBUG,
1149 "nl80211: Not the main interface (%s) - do not indicate interface up",
1150 drv->first_bss->ifname);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001151 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001152 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1153 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001154 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001155 } else if (drv->if_removed) {
1156 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1157 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001158 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001159 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001160 /* Re-read MAC address as it may have changed */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001161 nl80211_refresh_mac(drv, ifi->ifi_index, 0);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001162
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001163 drv->if_disabled = 0;
1164 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1165 NULL);
1166 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 }
1168
1169 /*
1170 * Some drivers send the association event before the operup event--in
1171 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1172 * fails. This will hit us when wpa_supplicant does not need to do
1173 * IEEE 802.1X authentication
1174 */
1175 if (drv->operstate == 1 &&
1176 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001177 !(ifi->ifi_flags & IFF_RUNNING)) {
1178 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001179 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 }
1182
Dmitry Shmidte4663042016-04-04 10:07:49 -07001183event_newlink:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001184 if (ifname[0])
Dmitry Shmidte4663042016-04-04 10:07:49 -07001185 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1186 ifname);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001187
Dmitry Shmidte4663042016-04-04 10:07:49 -07001188 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001189 struct i802_bss *bss;
1190
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001192 if (!if_indextoname(brid, namebuf)) {
1193 wpa_printf(MSG_DEBUG,
1194 "nl80211: Could not find bridge ifname for ifindex %u",
1195 brid);
1196 return;
1197 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001198 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1199 brid, namebuf);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001200 add_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001201
1202 for (bss = drv->first_bss; bss; bss = bss->next) {
1203 if (os_strcmp(ifname, bss->ifname) == 0) {
1204 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1205 break;
1206 }
1207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001209}
1210
1211
1212static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1213 struct ifinfomsg *ifi,
1214 u8 *buf, size_t len)
1215{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001216 struct nl80211_global *global = ctx;
1217 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001218 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219 struct rtattr *attr;
1220 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001221 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001222 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001224 extra[0] = '\0';
1225 pos = extra;
1226 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001227 ifname[0] = '\0';
1228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 attrlen = len;
1230 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001232 switch (attr->rta_type) {
1233 case IFLA_IFNAME:
1234 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1235 break;
1236 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1237 ifname[RTA_PAYLOAD(attr)] = '\0';
1238 break;
1239 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001241 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1242 break;
1243 case IFLA_OPERSTATE:
1244 pos += os_snprintf(pos, end - pos, " operstate=%u",
1245 nla_get_u32((struct nlattr *) attr));
1246 break;
1247 case IFLA_LINKMODE:
1248 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1249 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001250 break;
1251 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 attr = RTA_NEXT(attr, attrlen);
1253 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001254 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001256 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1257 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1258 ifi->ifi_flags,
1259 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1260 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1261 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1262 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1263
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001264 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001265
Dmitry Shmidte4663042016-04-04 10:07:49 -07001266 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 /* device has been removed from bridge */
1268 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001269
1270 if (!if_indextoname(brid, namebuf)) {
1271 wpa_printf(MSG_DEBUG,
1272 "nl80211: Could not find bridge ifname for ifindex %u",
1273 brid);
1274 } else {
1275 wpa_printf(MSG_DEBUG,
1276 "nl80211: Remove ifindex %u for bridge %s",
1277 brid, namebuf);
1278 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001279 del_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001280 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001281
1282 if (ifi->ifi_family != AF_BRIDGE || !brid)
1283 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1284 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285}
1286
1287
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001288struct nl80211_get_assoc_freq_arg {
1289 struct wpa_driver_nl80211_data *drv;
1290 unsigned int assoc_freq;
1291 unsigned int ibss_freq;
1292 u8 assoc_bssid[ETH_ALEN];
1293 u8 assoc_ssid[SSID_MAX_LEN];
1294 u8 assoc_ssid_len;
1295};
1296
1297static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg)
1298{
1299 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1300 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1301 struct nlattr *bss[NL80211_BSS_MAX + 1];
1302 static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
1303 [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC },
1304 [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
1305 [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC },
1306 [NL80211_BSS_STATUS] = { .type = NLA_U32 },
1307 };
1308 struct nl80211_get_assoc_freq_arg *ctx = arg;
1309 enum nl80211_bss_status status;
1310
1311 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1312 genlmsg_attrlen(gnlh, 0), NULL);
1313 if (!tb[NL80211_ATTR_BSS] ||
1314 nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS],
1315 bss_policy) ||
1316 !bss[NL80211_BSS_STATUS])
1317 return NL_SKIP;
1318
1319 status = nla_get_u32(bss[NL80211_BSS_STATUS]);
1320 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1321 bss[NL80211_BSS_FREQUENCY]) {
1322 ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1323 wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz",
1324 ctx->assoc_freq);
1325 }
1326 if (status == NL80211_BSS_STATUS_IBSS_JOINED &&
1327 bss[NL80211_BSS_FREQUENCY]) {
1328 ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1329 wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz",
1330 ctx->ibss_freq);
1331 }
1332 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1333 bss[NL80211_BSS_BSSID]) {
1334 os_memcpy(ctx->assoc_bssid,
1335 nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN);
1336 wpa_printf(MSG_DEBUG, "nl80211: Associated with "
1337 MACSTR, MAC2STR(ctx->assoc_bssid));
1338 }
1339
1340 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1341 bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
1342 const u8 *ie, *ssid;
1343 size_t ie_len;
1344
1345 ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1346 ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1347 ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
1348 if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) {
1349 ctx->assoc_ssid_len = ssid[1];
1350 os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]);
1351 }
1352 }
1353
1354 return NL_SKIP;
1355}
1356
1357
1358int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001359{
1360 struct nl_msg *msg;
1361 int ret;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001362 struct nl80211_get_assoc_freq_arg arg;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001363
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001364 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001365 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001366 arg.drv = drv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001367 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1368 &arg);
1369 if (ret == 0) {
1370 os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len);
1371 return arg.assoc_ssid_len;
1372 }
1373 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)",
1374 ret, strerror(-ret));
1375 return ret;
1376}
1377
1378
1379unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
1380{
1381 struct nl_msg *msg;
1382 int ret;
1383 struct nl80211_get_assoc_freq_arg arg;
1384
1385 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1386 os_memset(&arg, 0, sizeof(arg));
1387 arg.drv = drv;
1388 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1389 &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001390 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001391 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1392 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001393 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001394 "associated BSS from scan results: %u MHz", freq);
1395 if (freq)
1396 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001397 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001398 }
1399 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1400 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001401 return drv->assoc_freq;
1402}
1403
1404
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405static int get_link_signal(struct nl_msg *msg, void *arg)
1406{
1407 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1408 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1409 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1410 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1411 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001412 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001413 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 };
1415 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1416 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1417 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1418 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1419 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1420 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1421 };
1422 struct wpa_signal_info *sig_change = arg;
1423
1424 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1425 genlmsg_attrlen(gnlh, 0), NULL);
1426 if (!tb[NL80211_ATTR_STA_INFO] ||
1427 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1428 tb[NL80211_ATTR_STA_INFO], policy))
1429 return NL_SKIP;
1430 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1431 return NL_SKIP;
1432
1433 sig_change->current_signal =
1434 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1435
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001436 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1437 sig_change->avg_signal =
1438 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1439 else
1440 sig_change->avg_signal = 0;
1441
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001442 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1443 sig_change->avg_beacon_signal =
1444 (s8)
1445 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1446 else
1447 sig_change->avg_beacon_signal = 0;
1448
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1450 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1451 sinfo[NL80211_STA_INFO_TX_BITRATE],
1452 rate_policy)) {
1453 sig_change->current_txrate = 0;
1454 } else {
1455 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1456 sig_change->current_txrate =
1457 nla_get_u16(rinfo[
1458 NL80211_RATE_INFO_BITRATE]) * 100;
1459 }
1460 }
1461 }
1462
1463 return NL_SKIP;
1464}
1465
1466
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001467int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1468 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001469{
1470 struct nl_msg *msg;
1471
1472 sig->current_signal = -9999;
1473 sig->current_txrate = 0;
1474
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001475 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1476 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1477 nlmsg_free(msg);
1478 return -ENOBUFS;
1479 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480
1481 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482}
1483
1484
1485static int get_link_noise(struct nl_msg *msg, void *arg)
1486{
1487 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1488 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1489 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1490 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1491 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1492 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1493 };
1494 struct wpa_signal_info *sig_change = arg;
1495
1496 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1497 genlmsg_attrlen(gnlh, 0), NULL);
1498
1499 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1500 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1501 return NL_SKIP;
1502 }
1503
1504 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1505 tb[NL80211_ATTR_SURVEY_INFO],
1506 survey_policy)) {
1507 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1508 "attributes!");
1509 return NL_SKIP;
1510 }
1511
1512 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1513 return NL_SKIP;
1514
1515 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1516 sig_change->frequency)
1517 return NL_SKIP;
1518
1519 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1520 return NL_SKIP;
1521
1522 sig_change->current_noise =
1523 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1524
1525 return NL_SKIP;
1526}
1527
1528
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001529int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1530 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531{
1532 struct nl_msg *msg;
1533
1534 sig_change->current_noise = 9999;
1535 sig_change->frequency = drv->assoc_freq;
1536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001537 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001538 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001539}
1540
1541
1542static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1543 void *handle)
1544{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001545 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001546 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001548 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001549
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001550 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001551 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001552 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1553 __func__, res);
1554 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001555}
1556
1557
1558/**
1559 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1560 * @priv: driver_nl80211 private data
1561 * @alpha2_arg: country to which to switch to
1562 * Returns: 0 on success, -1 on failure
1563 *
1564 * This asks nl80211 to set the regulatory domain for given
1565 * country ISO / IEC alpha2.
1566 */
1567static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1568{
1569 struct i802_bss *bss = priv;
1570 struct wpa_driver_nl80211_data *drv = bss->drv;
1571 char alpha2[3];
1572 struct nl_msg *msg;
1573
1574 msg = nlmsg_alloc();
1575 if (!msg)
1576 return -ENOMEM;
1577
1578 alpha2[0] = alpha2_arg[0];
1579 alpha2[1] = alpha2_arg[1];
1580 alpha2[2] = '\0';
1581
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001582 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1583 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1584 nlmsg_free(msg);
1585 return -EINVAL;
1586 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001587 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1588 return -EINVAL;
1589 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001590}
1591
1592
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001593static int nl80211_get_country(struct nl_msg *msg, void *arg)
1594{
1595 char *alpha2 = arg;
1596 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1597 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1598
1599 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1600 genlmsg_attrlen(gnlh, 0), NULL);
1601 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1602 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1603 return NL_SKIP;
1604 }
1605 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1606 return NL_SKIP;
1607}
1608
1609
1610static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1611{
1612 struct i802_bss *bss = priv;
1613 struct wpa_driver_nl80211_data *drv = bss->drv;
1614 struct nl_msg *msg;
1615 int ret;
1616
1617 msg = nlmsg_alloc();
1618 if (!msg)
1619 return -ENOMEM;
1620
1621 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1622 alpha2[0] = '\0';
1623 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1624 if (!alpha2[0])
1625 ret = -1;
1626
1627 return ret;
1628}
1629
1630
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001631static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632{
1633 int ret;
1634
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001635 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1636 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001637 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1638 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001639 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 }
1641
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001642 global->nl = nl_create_handle(global->nl_cb, "nl");
1643 if (global->nl == NULL)
1644 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001645
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001646 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1647 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1649 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001650 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 }
1652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001653 global->nl_event = nl_create_handle(global->nl_cb, "event");
1654 if (global->nl_event == NULL)
1655 goto err;
1656
1657 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001659 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 if (ret < 0) {
1661 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1662 "membership for scan events: %d (%s)",
1663 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001664 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665 }
1666
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001667 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001669 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670 if (ret < 0) {
1671 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1672 "membership for mlme events: %d (%s)",
1673 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001674 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 }
1676
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001677 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001679 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 if (ret < 0) {
1681 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1682 "membership for regulatory events: %d (%s)",
1683 ret, strerror(-ret));
1684 /* Continue without regulatory events */
1685 }
1686
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001687 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1688 if (ret >= 0)
1689 ret = nl_socket_add_membership(global->nl_event, ret);
1690 if (ret < 0) {
1691 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1692 "membership for vendor events: %d (%s)",
1693 ret, strerror(-ret));
1694 /* Continue without vendor events */
1695 }
1696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001697 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1698 no_seq_check, NULL);
1699 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1700 process_global_event, global);
1701
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001702 nl80211_register_eloop_read(&global->nl_event,
1703 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001704 global->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705
1706 return 0;
1707
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001708err:
1709 nl_destroy_handles(&global->nl_event);
1710 nl_destroy_handles(&global->nl);
1711 nl_cb_put(global->nl_cb);
1712 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 return -1;
1714}
1715
1716
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001717static void nl80211_check_global(struct nl80211_global *global)
1718{
1719 struct nl_handle *handle;
1720 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1721 int ret;
1722 unsigned int i;
1723
1724 /*
1725 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1726 * and all registration having been cleared.
1727 */
1728 handle = (void *) (((intptr_t) global->nl_event) ^
1729 ELOOP_SOCKET_INVALID);
1730
1731 for (i = 0; groups[i]; i++) {
1732 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1733 if (ret >= 0)
1734 ret = nl_socket_add_membership(handle, ret);
1735 if (ret < 0) {
1736 wpa_printf(MSG_INFO,
1737 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1738 groups[i], ret, strerror(-ret));
1739 }
1740 }
1741}
1742
1743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1745{
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001746 struct wpa_driver_nl80211_data *drv = ctx;
1747
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001749
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 /*
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001751 * rtnetlink ifdown handler will report interfaces other than the P2P
1752 * Device interface as disabled.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001754 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1755 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756}
1757
1758
1759static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1760{
1761 struct wpa_driver_nl80211_data *drv = ctx;
1762 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001763 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1765 "after rfkill unblock");
1766 return;
1767 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001768
1769 if (is_p2p_net_interface(drv->nlmode))
1770 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
1771
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001772 /*
1773 * rtnetlink ifup handler will report interfaces other than the P2P
1774 * Device interface as enabled.
1775 */
1776 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1777 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778}
1779
1780
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001781static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1782 void *eloop_ctx,
1783 void *handle)
1784{
1785 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1786 u8 data[2048];
1787 struct msghdr msg;
1788 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001789 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001790 struct cmsghdr *cmsg;
1791 int res, found_ee = 0, found_wifi = 0, acked = 0;
1792 union wpa_event_data event;
1793
1794 memset(&msg, 0, sizeof(msg));
1795 msg.msg_iov = &entry;
1796 msg.msg_iovlen = 1;
1797 entry.iov_base = data;
1798 entry.iov_len = sizeof(data);
1799 msg.msg_control = &control;
1800 msg.msg_controllen = sizeof(control);
1801
1802 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1803 /* if error or not fitting 802.3 header, return */
1804 if (res < 14)
1805 return;
1806
1807 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1808 {
1809 if (cmsg->cmsg_level == SOL_SOCKET &&
1810 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1811 int *ack;
1812
1813 found_wifi = 1;
1814 ack = (void *)CMSG_DATA(cmsg);
1815 acked = *ack;
1816 }
1817
1818 if (cmsg->cmsg_level == SOL_PACKET &&
1819 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1820 struct sock_extended_err *err =
1821 (struct sock_extended_err *)CMSG_DATA(cmsg);
1822
1823 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1824 found_ee = 1;
1825 }
1826 }
1827
1828 if (!found_ee || !found_wifi)
1829 return;
1830
1831 memset(&event, 0, sizeof(event));
1832 event.eapol_tx_status.dst = data;
1833 event.eapol_tx_status.data = data + 14;
1834 event.eapol_tx_status.data_len = res - 14;
1835 event.eapol_tx_status.ack = acked;
1836 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1837}
1838
1839
1840static int nl80211_init_bss(struct i802_bss *bss)
1841{
1842 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1843 if (!bss->nl_cb)
1844 return -1;
1845
1846 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1847 no_seq_check, NULL);
1848 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1849 process_bss_event, bss);
1850
1851 return 0;
1852}
1853
1854
1855static void nl80211_destroy_bss(struct i802_bss *bss)
1856{
1857 nl_cb_put(bss->nl_cb);
1858 bss->nl_cb = NULL;
1859}
1860
1861
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001862static void
1863wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
1864{
1865 struct rfkill_config *rcfg;
1866
1867 if (drv->rfkill)
1868 return;
1869
1870 rcfg = os_zalloc(sizeof(*rcfg));
1871 if (!rcfg)
1872 return;
1873
1874 rcfg->ctx = drv;
1875
1876 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1877 * not associated with a netdev, so use the name of some other interface
1878 * sharing the same wiphy as the P2P Device interface.
1879 *
1880 * Note: This is valid, as a P2P Device interface is always dynamically
1881 * created and is created only once another wpa_s interface was added.
1882 */
1883 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
1884 struct nl80211_global *global = drv->global;
1885 struct wpa_driver_nl80211_data *tmp1;
1886
1887 dl_list_for_each(tmp1, &global->interfaces,
1888 struct wpa_driver_nl80211_data, list) {
1889 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
1890 !tmp1->rfkill)
1891 continue;
1892
1893 wpa_printf(MSG_DEBUG,
1894 "nl80211: Use (%s) to initialize P2P Device rfkill",
1895 tmp1->first_bss->ifname);
1896 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
1897 sizeof(rcfg->ifname));
1898 break;
1899 }
1900 } else {
1901 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
1902 sizeof(rcfg->ifname));
1903 }
1904
1905 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1906 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1907 drv->rfkill = rfkill_init(rcfg);
1908 if (!drv->rfkill) {
1909 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1910 os_free(rcfg);
1911 }
1912}
1913
1914
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001915static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1916 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001917 const u8 *set_addr,
1918 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919{
1920 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921 struct i802_bss *bss;
1922
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001923 if (global_priv == NULL)
1924 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925 drv = os_zalloc(sizeof(*drv));
1926 if (drv == NULL)
1927 return NULL;
1928 drv->global = global_priv;
1929 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001930 drv->hostapd = !!hostapd;
1931 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001932
1933 /*
1934 * There is no driver capability flag for this, so assume it is
1935 * supported and disable this on first attempt to use if the driver
1936 * rejects the command due to missing support.
1937 */
1938 drv->set_rekey_offload = 1;
1939
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001940 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1941 drv->if_indices = drv->default_if_indices;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001942 drv->if_indices_reason = drv->default_if_indices_reason;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001943
1944 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1945 if (!drv->first_bss) {
1946 os_free(drv);
1947 return NULL;
1948 }
1949 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001950 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001951 bss->ctx = ctx;
1952
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1954 drv->monitor_ifidx = -1;
1955 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956 drv->eapol_tx_sock = -1;
1957 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001959 if (nl80211_init_bss(bss))
1960 goto failed;
1961
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001962 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963 goto failed;
1964
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001965 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1966 if (drv->eapol_tx_sock < 0)
1967 goto failed;
1968
1969 if (drv->data_tx_status) {
1970 int enabled = 1;
1971
1972 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1973 &enabled, sizeof(enabled)) < 0) {
1974 wpa_printf(MSG_DEBUG,
1975 "nl80211: wifi status sockopt failed\n");
1976 drv->data_tx_status = 0;
1977 if (!drv->use_monitor)
1978 drv->capa.flags &=
1979 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1980 } else {
1981 eloop_register_read_sock(drv->eapol_tx_sock,
1982 wpa_driver_nl80211_handle_eapol_tx_status,
1983 drv, NULL);
1984 }
1985 }
1986
1987 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001988 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001989 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001990 drv->in_interface_list = 1;
1991 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001992
1993 return bss;
1994
1995failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001996 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997 return NULL;
1998}
1999
2000
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002001/**
2002 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2003 * @ctx: context to be used when calling wpa_supplicant functions,
2004 * e.g., wpa_supplicant_event()
2005 * @ifname: interface name, e.g., wlan0
2006 * @global_priv: private driver global data from global_init()
2007 * Returns: Pointer to private data, %NULL on failure
2008 */
2009static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
2010 void *global_priv)
2011{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002012 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
2013 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002014}
2015
2016
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002017static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018 struct nl_handle *nl_handle,
2019 u16 type, const u8 *match, size_t match_len)
2020{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002021 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002022 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002023 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002024 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002026 buf[0] = '\0';
2027 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07002028 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
2029 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002031 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
2032 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
2033 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
2034 nlmsg_free(msg);
2035 return -1;
2036 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002038 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002039 if (ret) {
2040 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
2041 "failed (type=%u): ret=%d (%s)",
2042 type, ret, strerror(-ret));
2043 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
2044 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002046 return ret;
2047}
2048
2049
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002050static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
2051{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002052 if (bss->nl_mgmt) {
2053 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
2054 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
2055 return -1;
2056 }
2057
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002058 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002059 if (bss->nl_mgmt == NULL)
2060 return -1;
2061
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002062 return 0;
2063}
2064
2065
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002066static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
2067{
2068 nl80211_register_eloop_read(&bss->nl_mgmt,
2069 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002070 bss->nl_cb, 0);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002071}
2072
2073
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002074static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 const u8 *match, size_t match_len)
2076{
2077 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002078 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079 type, match, match_len);
2080}
2081
2082
Roshan Pius3a1667e2018-07-03 15:17:14 -07002083static int nl80211_init_connect_handle(struct i802_bss *bss)
2084{
2085 if (bss->nl_connect) {
2086 wpa_printf(MSG_DEBUG,
2087 "nl80211: Connect handle already created (nl_connect=%p)",
2088 bss->nl_connect);
2089 return -1;
2090 }
2091
2092 bss->nl_connect = nl_create_handle(bss->nl_cb, "connect");
2093 if (!bss->nl_connect)
2094 return -1;
2095 nl80211_register_eloop_read(&bss->nl_connect,
2096 wpa_driver_nl80211_event_receive,
2097 bss->nl_cb, 1);
2098 return 0;
2099}
2100
2101
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002102static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002104 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002105 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002106
2107 if (nl80211_alloc_mgmt_handle(bss))
2108 return -1;
2109 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
2110 "handle %p", bss->nl_mgmt);
2111
Roshan Pius3a1667e2018-07-03 15:17:14 -07002112 if (drv->nlmode == NL80211_IFTYPE_ADHOC ||
2113 ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
2114 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002115 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2116
2117 /* register for any AUTH message */
2118 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
2119 }
2120
Dmitry Shmidt051af732013-10-22 13:52:46 -07002121#ifdef CONFIG_INTERWORKING
2122 /* QoS Map Configure */
2123 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002124 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002125#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002126#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002128 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002129 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002130 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002131 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002132 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002133 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002134 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002135 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002136 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002137 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002138 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08002139 /* Protected GAS Initial Request */
2140 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
2141 ret = -1;
2142 /* Protected GAS Initial Response */
2143 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
2144 ret = -1;
2145 /* Protected GAS Comeback Request */
2146 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
2147 ret = -1;
2148 /* Protected GAS Comeback Response */
2149 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
2150 ret = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002151#endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002152#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002154 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
2156 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002157 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002159 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160 (u8 *) "\x7f\x50\x6f\x9a\x09",
2161 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002162 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163#endif /* CONFIG_P2P */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002164#ifdef CONFIG_DPP
2165 /* DPP Public Action */
2166 if (nl80211_register_action_frame(bss,
2167 (u8 *) "\x04\x09\x50\x6f\x9a\x1a",
2168 6) < 0)
2169 ret = -1;
2170#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171#ifdef CONFIG_IEEE80211W
2172 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002173 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002174 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002175#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002176#ifdef CONFIG_TDLS
2177 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
2178 /* TDLS Discovery Response */
2179 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
2180 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002181 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002182 }
2183#endif /* CONFIG_TDLS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002184#ifdef CONFIG_FST
2185 /* FST Action frames */
2186 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2187 ret = -1;
2188#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002189
2190 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002191 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002192 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193 else
2194 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
2195 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002197 /* WNM - BSS Transition Management Request */
2198 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002199 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002200 /* WNM-Sleep Mode Response */
2201 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002202 ret = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002203#ifdef CONFIG_WNM
2204 /* WNM - Collocated Interference Request */
2205 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0)
2206 ret = -1;
2207#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002208
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002209#ifdef CONFIG_HS20
2210 /* WNM-Notification */
2211 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002212 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002213#endif /* CONFIG_HS20 */
2214
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002215 /* WMM-AC ADDTS Response */
2216 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
2217 ret = -1;
2218
2219 /* WMM-AC DELTS */
2220 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
2221 ret = -1;
2222
2223 /* Radio Measurement - Neighbor Report Response */
2224 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
2225 ret = -1;
2226
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002227 /* Radio Measurement - Radio Measurement Request */
2228 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0)
2229 ret = -1;
2230
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002231 /* Radio Measurement - Link Measurement Request */
2232 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
2233 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
2234 ret = -1;
2235
2236 nl80211_mgmt_handle_register_eloop(bss);
2237
2238 return ret;
2239}
2240
2241
2242static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2243{
2244 int ret = 0;
2245
2246 if (nl80211_alloc_mgmt_handle(bss))
2247 return -1;
2248
2249 wpa_printf(MSG_DEBUG,
2250 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2251 bss->nl_mgmt);
2252
2253 /* Auth frames for mesh SAE */
2254 if (nl80211_register_frame(bss, bss->nl_mgmt,
2255 (WLAN_FC_TYPE_MGMT << 2) |
2256 (WLAN_FC_STYPE_AUTH << 4),
2257 NULL, 0) < 0)
2258 ret = -1;
2259
2260 /* Mesh peering open */
2261 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2262 ret = -1;
2263 /* Mesh peering confirm */
2264 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2265 ret = -1;
2266 /* Mesh peering close */
2267 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2268 ret = -1;
2269
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002270 nl80211_mgmt_handle_register_eloop(bss);
2271
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002272 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002273}
2274
2275
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002276static int nl80211_register_spurious_class3(struct i802_bss *bss)
2277{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002278 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002279 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002280
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002281 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
2282 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (ret) {
2284 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2285 "failed: ret=%d (%s)",
2286 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002287 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002288 return ret;
2289}
2290
2291
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002292static int nl80211_action_subscribe_ap(struct i802_bss *bss)
2293{
2294 int ret = 0;
2295
2296 /* Public Action frames */
2297 if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0)
2298 ret = -1;
2299 /* RRM Measurement Report */
2300 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0)
2301 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08002302 /* RRM Link Measurement Report */
2303 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0)
2304 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002305 /* RRM Neighbor Report Request */
2306 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0)
2307 ret = -1;
2308 /* FT Action frames */
2309 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2310 ret = -1;
2311#ifdef CONFIG_IEEE80211W
2312 /* SA Query */
2313 if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0)
2314 ret = -1;
2315#endif /* CONFIG_IEEE80211W */
2316 /* Protected Dual of Public Action */
2317 if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0)
2318 ret = -1;
2319 /* WNM */
2320 if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0)
2321 ret = -1;
2322 /* WMM */
2323 if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0)
2324 ret = -1;
2325#ifdef CONFIG_FST
2326 /* FST Action frames */
2327 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2328 ret = -1;
2329#endif /* CONFIG_FST */
2330 /* Vendor-specific */
2331 if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0)
2332 ret = -1;
2333
2334 return ret;
2335}
2336
2337
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002338static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2339{
2340 static const int stypes[] = {
2341 WLAN_FC_STYPE_AUTH,
2342 WLAN_FC_STYPE_ASSOC_REQ,
2343 WLAN_FC_STYPE_REASSOC_REQ,
2344 WLAN_FC_STYPE_DISASSOC,
2345 WLAN_FC_STYPE_DEAUTH,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002346 WLAN_FC_STYPE_PROBE_REQ,
2347/* Beacon doesn't work as mac80211 doesn't currently allow
2348 * it, but it wouldn't really be the right thing anyway as
2349 * it isn't per interface ... maybe just dump the scan
2350 * results periodically for OLBC?
2351 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002352 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002353 };
2354 unsigned int i;
2355
2356 if (nl80211_alloc_mgmt_handle(bss))
2357 return -1;
2358 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2359 "handle %p", bss->nl_mgmt);
2360
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002361 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002362 if (nl80211_register_frame(bss, bss->nl_mgmt,
2363 (WLAN_FC_TYPE_MGMT << 2) |
2364 (stypes[i] << 4),
2365 NULL, 0) < 0) {
2366 goto out_err;
2367 }
2368 }
2369
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002370 if (nl80211_action_subscribe_ap(bss))
2371 goto out_err;
2372
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002373 if (nl80211_register_spurious_class3(bss))
2374 goto out_err;
2375
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002376 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002377 return 0;
2378
2379out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002380 nl_destroy_handles(&bss->nl_mgmt);
2381 return -1;
2382}
2383
2384
2385static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2386{
2387 if (nl80211_alloc_mgmt_handle(bss))
2388 return -1;
2389 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2390 "handle %p (device SME)", bss->nl_mgmt);
2391
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002392 if (nl80211_action_subscribe_ap(bss))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002393 goto out_err;
2394
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002395 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002396 return 0;
2397
2398out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002399 nl_destroy_handles(&bss->nl_mgmt);
2400 return -1;
2401}
2402
2403
2404static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2405{
2406 if (bss->nl_mgmt == NULL)
2407 return;
2408 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2409 "(%s)", bss->nl_mgmt, reason);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002410 nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002411
2412 nl80211_put_wiphy_data_ap(bss);
2413}
2414
2415
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2417{
2418 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2419}
2420
2421
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002422static void nl80211_del_p2pdev(struct i802_bss *bss)
2423{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002424 struct nl_msg *msg;
2425 int ret;
2426
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002427 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2428 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002429
2430 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2431 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002432 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002433}
2434
2435
2436static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2437{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002438 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002439 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002440
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002441 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2442 NL80211_CMD_STOP_P2P_DEVICE);
2443 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002444
2445 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2446 start ? "Start" : "Stop",
2447 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002448 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002449 return ret;
2450}
2451
2452
2453static int i802_set_iface_flags(struct i802_bss *bss, int up)
2454{
2455 enum nl80211_iftype nlmode;
2456
2457 nlmode = nl80211_get_ifmode(bss);
2458 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2459 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2460 bss->ifname, up);
2461 }
2462
2463 /* P2P Device has start/stop which is equivalent */
2464 return nl80211_set_p2pdev(bss, up);
2465}
2466
2467
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002468#ifdef CONFIG_TESTING_OPTIONS
2469static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2470{
2471 /* struct wpa_driver_nl80211_data *drv = arg; */
2472 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2473 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2474
2475
2476 wpa_printf(MSG_DEBUG,
2477 "nl80211: QCA vendor test command response received");
2478
2479 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2480 genlmsg_attrlen(gnlh, 0), NULL);
2481 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2482 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2483 return NL_SKIP;
2484 }
2485
2486 wpa_hexdump(MSG_DEBUG,
2487 "nl80211: Received QCA vendor test command response",
2488 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2489 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2490
2491 return NL_SKIP;
2492}
2493#endif /* CONFIG_TESTING_OPTIONS */
2494
2495
2496static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2497{
2498#ifdef CONFIG_TESTING_OPTIONS
2499 struct nl_msg *msg;
2500 struct nlattr *params;
2501 int ret;
2502
2503 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2504 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2505 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2506 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2507 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2508 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2509 nlmsg_free(msg);
2510 return;
2511 }
2512 nla_nest_end(msg, params);
2513
2514 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2515 wpa_printf(MSG_DEBUG,
2516 "nl80211: QCA vendor test command returned %d (%s)",
2517 ret, strerror(-ret));
2518#endif /* CONFIG_TESTING_OPTIONS */
2519}
2520
2521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002522static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002523wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002524 const u8 *set_addr, int first,
2525 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002526{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002527 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002529 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002530
2531 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002532 bss->ifindex = drv->ifindex;
2533 bss->wdev_id = drv->global->if_add_wdevid;
2534 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2535
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002536 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2537 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002538 drv->global->if_add_wdevid_set = 0;
2539
Dmitry Shmidt03658832014-08-13 11:03:49 -07002540 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2541 bss->static_ap = 1;
2542
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002543 if (first &&
2544 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2545 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2546 drv->start_iface_up = 1;
2547
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002548 if (wpa_driver_nl80211_capa(drv))
2549 return -1;
2550
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002551 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2552 return -1;
2553
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002554 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2555 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002556
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002557 if (set_addr &&
2558 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2559 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2560 set_addr)))
2561 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002562
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002563 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2564 drv->start_mode_ap = 1;
2565
Dmitry Shmidt03658832014-08-13 11:03:49 -07002566 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002567 nlmode = NL80211_IFTYPE_AP;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002568 else if (bss->if_dynamic ||
2569 nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002570 nlmode = nl80211_get_ifmode(bss);
2571 else
2572 nlmode = NL80211_IFTYPE_STATION;
2573
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002574 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002575 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002576 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002578
Dmitry Shmidt98660862014-03-11 17:26:21 -07002579 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002580 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002581
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002582 wpa_driver_nl80211_drv_init_rfkill(drv);
2583
Dmitry Shmidt98660862014-03-11 17:26:21 -07002584 if (!rfkill_is_blocked(drv->rfkill)) {
2585 int ret = i802_set_iface_flags(bss, 1);
2586 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002587 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2588 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002589 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002590 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002591
2592 if (is_p2p_net_interface(nlmode))
2593 nl80211_disable_11b_rates(bss->drv,
2594 bss->drv->ifindex, 1);
2595
Dmitry Shmidt98660862014-03-11 17:26:21 -07002596 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2597 return ret;
2598 } else {
2599 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2600 "interface '%s' due to rfkill", bss->ifname);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002601 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
2602 drv->if_disabled = 1;
2603
Dmitry Shmidt98660862014-03-11 17:26:21 -07002604 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605 }
2606
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002607 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002608 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2609 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002610
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002611 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2612 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2613 bss->addr))
2614 return -1;
2615 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
2616 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002617
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002618 if (send_rfkill_event) {
2619 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2620 drv, drv->ctx);
2621 }
2622
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002623 if (drv->vendor_cmd_test_avail)
2624 qca_vendor_test(drv);
2625
Roshan Pius3a1667e2018-07-03 15:17:14 -07002626 nl80211_init_connect_handle(bss);
2627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002628 return 0;
2629}
2630
2631
Paul Stewart092955c2017-02-06 09:13:09 -08002632static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633{
2634 struct nl_msg *msg;
Paul Stewart092955c2017-02-06 09:13:09 -08002635 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002637 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2638 drv->ifindex);
Paul Stewart092955c2017-02-06 09:13:09 -08002639 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002640 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002641 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002642}
2643
2644
2645/**
2646 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002647 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002648 *
2649 * Shut down driver interface and processing of driver events. Free
2650 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2651 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002652static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002654 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002655 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002656
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002657 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2658 bss->ifname, drv->disabled_11b_rates);
2659
Dmitry Shmidt04949592012-07-19 12:16:46 -07002660 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002661 if (drv->data_tx_status)
2662 eloop_unregister_read_sock(drv->eapol_tx_sock);
2663 if (drv->eapol_tx_sock >= 0)
2664 close(drv->eapol_tx_sock);
2665
2666 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002667 wpa_driver_nl80211_probe_req_report(bss, 0);
2668 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002669 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2670 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002671 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2672 "interface %s from bridge %s: %s",
2673 bss->ifname, bss->brname, strerror(errno));
2674 }
Hai Shalomc9e41a12018-07-31 14:41:42 -07002675
2676 if (drv->rtnl_sk)
2677 nl80211_handle_destroy(drv->rtnl_sk);
2678
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002679 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002680 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2681 0) < 0)
2682 wpa_printf(MSG_INFO,
2683 "nl80211: Could not set bridge %s down",
2684 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002685 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2687 "bridge %s: %s",
2688 bss->brname, strerror(errno));
2689 }
2690
2691 nl80211_remove_monitor_interface(drv);
2692
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002693 if (is_ap_interface(drv->nlmode))
Paul Stewart092955c2017-02-06 09:13:09 -08002694 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002695
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 if (drv->eapol_sock >= 0) {
2697 eloop_unregister_read_sock(drv->eapol_sock);
2698 close(drv->eapol_sock);
2699 }
2700
2701 if (drv->if_indices != drv->default_if_indices)
2702 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002703
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002704 if (drv->if_indices_reason != drv->default_if_indices_reason)
2705 os_free(drv->if_indices_reason);
2706
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002707 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2709
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002710 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2711 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002712 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 rfkill_deinit(drv->rfkill);
2714
2715 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2716
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002717 if (!drv->start_iface_up)
2718 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002719
2720 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002721 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2722 0) < 0) {
2723 wpa_printf(MSG_DEBUG,
2724 "nl80211: Could not set interface down to restore permanent MAC address");
2725 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002726 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2727 drv->perm_addr) < 0) {
2728 wpa_printf(MSG_DEBUG,
2729 "nl80211: Could not restore permanent MAC address");
2730 }
2731 }
2732
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002733 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002734 if (!drv->hostapd || !drv->start_mode_ap)
2735 wpa_driver_nl80211_set_mode(bss,
2736 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002737 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002738 } else {
2739 nl80211_mgmt_unsubscribe(bss, "deinit");
2740 nl80211_del_p2pdev(bss);
2741 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742
Roshan Pius3a1667e2018-07-03 15:17:14 -07002743 if (bss->nl_connect)
2744 nl80211_destroy_eloop_handle(&bss->nl_connect, 1);
2745
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002746 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002747
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 os_free(drv->filter_ssids);
2749
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002750 os_free(drv->auth_ie);
2751
2752 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753 dl_list_del(&drv->list);
2754
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002755 os_free(drv->extended_capa);
2756 os_free(drv->extended_capa_mask);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002757 for (i = 0; i < drv->num_iface_ext_capa; i++) {
2758 os_free(drv->iface_ext_capa[i].ext_capa);
2759 os_free(drv->iface_ext_capa[i].ext_capa_mask);
2760 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002761 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 os_free(drv);
2763}
2764
2765
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002766static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2767{
2768 switch (alg) {
2769 case WPA_ALG_WEP:
2770 if (key_len == 5)
Paul Stewart092955c2017-02-06 09:13:09 -08002771 return RSN_CIPHER_SUITE_WEP40;
2772 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002773 case WPA_ALG_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002774 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002775 case WPA_ALG_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002776 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002777 case WPA_ALG_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002778 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002779 case WPA_ALG_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002780 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002781 case WPA_ALG_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002782 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002783 case WPA_ALG_IGTK:
Paul Stewart092955c2017-02-06 09:13:09 -08002784 return RSN_CIPHER_SUITE_AES_128_CMAC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002785 case WPA_ALG_BIP_GMAC_128:
Paul Stewart092955c2017-02-06 09:13:09 -08002786 return RSN_CIPHER_SUITE_BIP_GMAC_128;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002787 case WPA_ALG_BIP_GMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002788 return RSN_CIPHER_SUITE_BIP_GMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002789 case WPA_ALG_BIP_CMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002790 return RSN_CIPHER_SUITE_BIP_CMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002791 case WPA_ALG_SMS4:
Paul Stewart092955c2017-02-06 09:13:09 -08002792 return RSN_CIPHER_SUITE_SMS4;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002793 case WPA_ALG_KRK:
Paul Stewart092955c2017-02-06 09:13:09 -08002794 return RSN_CIPHER_SUITE_KRK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002795 case WPA_ALG_NONE:
2796 case WPA_ALG_PMK:
2797 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2798 alg);
2799 return 0;
2800 }
2801
2802 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2803 alg);
2804 return 0;
2805}
2806
2807
2808static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2809{
2810 switch (cipher) {
2811 case WPA_CIPHER_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002812 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002813 case WPA_CIPHER_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002814 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002815 case WPA_CIPHER_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002816 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002817 case WPA_CIPHER_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002818 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002819 case WPA_CIPHER_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002820 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002821 case WPA_CIPHER_WEP104:
Paul Stewart092955c2017-02-06 09:13:09 -08002822 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002823 case WPA_CIPHER_WEP40:
Paul Stewart092955c2017-02-06 09:13:09 -08002824 return RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002825 case WPA_CIPHER_GTK_NOT_USED:
Paul Stewart092955c2017-02-06 09:13:09 -08002826 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002827 }
2828
2829 return 0;
2830}
2831
2832
2833static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2834 int max_suites)
2835{
2836 int num_suites = 0;
2837
2838 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002839 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002840 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002841 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002842 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002843 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002844 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002845 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002846 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
Paul Stewart092955c2017-02-06 09:13:09 -08002847 suites[num_suites++] = RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002848 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
Paul Stewart092955c2017-02-06 09:13:09 -08002849 suites[num_suites++] = RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002850 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
Paul Stewart092955c2017-02-06 09:13:09 -08002851 suites[num_suites++] = RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002852
2853 return num_suites;
2854}
2855
2856
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002857#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002858static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2859 const u8 *key, size_t key_len)
2860{
2861 struct nl_msg *msg;
2862 int ret;
2863
2864 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2865 return 0;
2866
2867 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2868 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2869 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2870 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2871 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2872 nl80211_nlmsg_clear(msg);
2873 nlmsg_free(msg);
2874 return -1;
2875 }
2876 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2877 if (ret) {
2878 wpa_printf(MSG_DEBUG,
2879 "nl80211: Key management set key failed: ret=%d (%s)",
2880 ret, strerror(-ret));
2881 }
2882
2883 return ret;
2884}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002885#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002886
2887
Roshan Pius3a1667e2018-07-03 15:17:14 -07002888static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv,
2889 const u8 *key, size_t key_len,
2890 const u8 *addr)
2891{
2892 struct nl_msg *msg = NULL;
2893 int ret;
2894
2895 /*
2896 * If the authenticator address is not set, assume it is
2897 * the current BSSID.
2898 */
2899 if (!addr && drv->associated)
2900 addr = drv->bssid;
2901 else if (!addr)
2902 return -1;
2903
2904 wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR,
2905 MAC2STR(addr));
2906 wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len);
2907 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK);
2908 if (!msg ||
2909 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
2910 nla_put(msg, NL80211_ATTR_PMK, key_len, key)) {
2911 nl80211_nlmsg_clear(msg);
2912 nlmsg_free(msg);
2913 return -ENOBUFS;
2914 }
2915
2916 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2917 if (ret) {
2918 wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)",
2919 ret, strerror(-ret));
2920 }
2921
2922 return ret;
2923}
2924
2925
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002926static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927 enum wpa_alg alg, const u8 *addr,
2928 int key_idx, int set_tx,
2929 const u8 *seq, size_t seq_len,
2930 const u8 *key, size_t key_len)
2931{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002932 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002933 int ifindex;
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002934 struct nl_msg *msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002935 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002936 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002938 /* Ignore for P2P Device */
2939 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2940 return 0;
2941
2942 ifindex = if_nametoindex(ifname);
2943 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002945 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002947#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002948 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002949 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002950 tdls = 1;
2951 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002952#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002953
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002954#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002955 if (alg == WPA_ALG_PMK &&
2956 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2957 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2958 __func__);
2959 ret = issue_key_mgmt_set_key(drv, key, key_len);
2960 return ret;
2961 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002962#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002963
Roshan Pius3a1667e2018-07-03 15:17:14 -07002964 if (alg == WPA_ALG_PMK &&
2965 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
2966 return nl80211_set_pmk(drv, key, key_len, addr);
2967
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002968 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002969 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2970 if (!msg)
2971 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002972 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002973 u32 suite;
2974
2975 suite = wpa_alg_to_cipher_suite(alg, key_len);
2976 if (!suite)
2977 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002978 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2979 if (!msg ||
2980 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002981 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002982 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002983 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984 }
2985
Dmitry Shmidt98660862014-03-11 17:26:21 -07002986 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002987 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2988 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002989 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2990 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991
2992 if (addr && !is_broadcast_ether_addr(addr)) {
2993 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002994 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2995 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996
2997 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2998 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002999 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
3000 NL80211_KEYTYPE_GROUP))
3001 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 }
3003 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003004 struct nlattr *types;
3005
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003007
3008 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003009 if (!types ||
3010 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
3011 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003012 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003013 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003014 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3015 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003017 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003018 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
3019 ret = 0;
3020 if (ret)
3021 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
3022 ret, strerror(-ret));
3023
3024 /*
3025 * If we failed or don't need to set the default TX key (below),
3026 * we're done here.
3027 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003028 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003030 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031 !is_broadcast_ether_addr(addr))
3032 return ret;
3033
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003034 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
3035 if (!msg ||
3036 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003037 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
3038 alg == WPA_ALG_BIP_GMAC_128 ||
3039 alg == WPA_ALG_BIP_GMAC_256 ||
3040 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003041 NL80211_ATTR_KEY_DEFAULT_MGMT :
3042 NL80211_ATTR_KEY_DEFAULT))
3043 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003045 struct nlattr *types;
3046
3047 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003048 if (!types ||
3049 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
3050 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003051 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003052 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003053 struct nlattr *types;
3054
3055 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003056 if (!types ||
3057 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
3058 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003059 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003060 }
3061
3062 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3063 if (ret == -ENOENT)
3064 ret = 0;
3065 if (ret)
3066 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
3067 "err=%d %s)", ret, strerror(-ret));
3068 return ret;
3069
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003070fail:
3071 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003072 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 return -ENOBUFS;
3074}
3075
3076
3077static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
3078 int key_idx, int defkey,
3079 const u8 *seq, size_t seq_len,
3080 const u8 *key, size_t key_len)
3081{
3082 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003083 u32 suite;
3084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085 if (!key_attr)
3086 return -1;
3087
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003088 suite = wpa_alg_to_cipher_suite(alg, key_len);
3089 if (!suite)
3090 return -1;
3091
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003092 if (defkey && alg == WPA_ALG_IGTK) {
3093 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
3094 return -1;
3095 } else if (defkey) {
3096 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
3097 return -1;
3098 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003100 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003101 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003102 (seq && seq_len &&
3103 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
3104 nla_put(msg, NL80211_KEY_DATA, key_len, key))
3105 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003106
3107 nla_nest_end(msg, key_attr);
3108
3109 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003110}
3111
3112
3113static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
3114 struct nl_msg *msg)
3115{
3116 int i, privacy = 0;
3117 struct nlattr *nl_keys, *nl_key;
3118
3119 for (i = 0; i < 4; i++) {
3120 if (!params->wep_key[i])
3121 continue;
3122 privacy = 1;
3123 break;
3124 }
3125 if (params->wps == WPS_MODE_PRIVACY)
3126 privacy = 1;
3127 if (params->pairwise_suite &&
3128 params->pairwise_suite != WPA_CIPHER_NONE)
3129 privacy = 1;
3130
3131 if (!privacy)
3132 return 0;
3133
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003134 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3135 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003136
3137 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
3138 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003139 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003140
3141 for (i = 0; i < 4; i++) {
3142 if (!params->wep_key[i])
3143 continue;
3144
3145 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003146 if (!nl_key ||
3147 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
3148 params->wep_key[i]) ||
3149 nla_put_u32(msg, NL80211_KEY_CIPHER,
3150 params->wep_key_len[i] == 5 ?
Paul Stewart092955c2017-02-06 09:13:09 -08003151 RSN_CIPHER_SUITE_WEP40 :
3152 RSN_CIPHER_SUITE_WEP104) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003153 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
3154 (i == params->wep_tx_keyidx &&
3155 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
3156 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003157
3158 nla_nest_end(msg, nl_key);
3159 }
3160 nla_nest_end(msg, nl_keys);
3161
3162 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163}
3164
3165
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003166int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
3167 const u8 *addr, int cmd, u16 reason_code,
3168 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003169{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003170 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171 struct nl_msg *msg;
3172
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003173 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
3174 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
3175 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
3176 (local_state_change &&
3177 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
3178 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003181
3182 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003183 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003184 wpa_dbg(drv->ctx, MSG_DEBUG,
3185 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3186 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003188 return ret;
3189}
3190
3191
3192static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003193 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003195 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003196 int drv_associated = drv->associated;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003197
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003198 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003199 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003200 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003201 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
3202 reason_code, 0);
3203 /*
3204 * For locally generated disconnect, supplicant already generates a
3205 * DEAUTH event, so ignore the event from NL80211.
3206 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003207 drv->ignore_next_local_disconnect = drv_associated && (ret == 0);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003208
3209 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210}
3211
3212
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003213static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
3214 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003215{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003216 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003217 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003218 int drv_associated = drv->associated;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003219
3220 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
3221 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003222 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003223 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003225 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
3227 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003228 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003229 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
3230 reason_code, 0);
3231 /*
3232 * For locally generated deauthenticate, supplicant already generates a
3233 * DEAUTH event, so ignore the event from NL80211.
3234 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003235 drv->ignore_next_local_deauth = drv_associated && (ret == 0);
3236
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003237 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003238}
3239
3240
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003241static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
3242 struct wpa_driver_auth_params *params)
3243{
3244 int i;
3245
3246 drv->auth_freq = params->freq;
3247 drv->auth_alg = params->auth_alg;
3248 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
3249 drv->auth_local_state_change = params->local_state_change;
3250 drv->auth_p2p = params->p2p;
3251
3252 if (params->bssid)
3253 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
3254 else
3255 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
3256
3257 if (params->ssid) {
3258 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
3259 drv->auth_ssid_len = params->ssid_len;
3260 } else
3261 drv->auth_ssid_len = 0;
3262
3263
3264 os_free(drv->auth_ie);
3265 drv->auth_ie = NULL;
3266 drv->auth_ie_len = 0;
3267 if (params->ie) {
3268 drv->auth_ie = os_malloc(params->ie_len);
3269 if (drv->auth_ie) {
3270 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
3271 drv->auth_ie_len = params->ie_len;
3272 }
3273 }
3274
3275 for (i = 0; i < 4; i++) {
3276 if (params->wep_key[i] && params->wep_key_len[i] &&
3277 params->wep_key_len[i] <= 16) {
3278 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
3279 params->wep_key_len[i]);
3280 drv->auth_wep_key_len[i] = params->wep_key_len[i];
3281 } else
3282 drv->auth_wep_key_len[i] = 0;
3283 }
3284}
3285
3286
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003287static void nl80211_unmask_11b_rates(struct i802_bss *bss)
3288{
3289 struct wpa_driver_nl80211_data *drv = bss->drv;
3290
3291 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
3292 return;
3293
3294 /*
3295 * Looks like we failed to unmask 11b rates previously. This could
3296 * happen, e.g., if the interface was down at the point in time when a
3297 * P2P group was terminated.
3298 */
3299 wpa_printf(MSG_DEBUG,
3300 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3301 bss->ifname);
3302 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
3303}
3304
3305
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003306static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg)
3307{
3308 if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
3309 return NL80211_AUTHTYPE_OPEN_SYSTEM;
3310 if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
3311 return NL80211_AUTHTYPE_SHARED_KEY;
3312 if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
3313 return NL80211_AUTHTYPE_NETWORK_EAP;
3314 if (wpa_auth_alg & WPA_AUTH_ALG_FT)
3315 return NL80211_AUTHTYPE_FT;
3316 if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
3317 return NL80211_AUTHTYPE_SAE;
3318 if (wpa_auth_alg & WPA_AUTH_ALG_FILS)
3319 return NL80211_AUTHTYPE_FILS_SK;
3320 if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS)
3321 return NL80211_AUTHTYPE_FILS_SK_PFS;
3322
3323 return NL80211_AUTHTYPE_MAX;
3324}
3325
3326
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003327static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003328 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003330 struct wpa_driver_nl80211_data *drv = bss->drv;
3331 int ret = -1, i;
3332 struct nl_msg *msg;
3333 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003334 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003335 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003336 int is_retry;
3337
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003338 nl80211_unmask_11b_rates(bss);
3339
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003340 is_retry = drv->retry_auth;
3341 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003342 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003343
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003344 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003345 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003346 if (params->bssid)
3347 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
3348 else
3349 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003350 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 nlmode = params->p2p ?
3352 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
3353 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003354 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355 return -1;
3356
3357retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
3359 drv->ifindex);
3360
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003361 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
3362 if (!msg)
3363 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003364
3365 for (i = 0; i < 4; i++) {
3366 if (!params->wep_key[i])
3367 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003368 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003369 NULL, i,
3370 i == params->wep_tx_keyidx, NULL, 0,
3371 params->wep_key[i],
3372 params->wep_key_len[i]);
3373 if (params->wep_tx_keyidx != i)
3374 continue;
3375 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003376 params->wep_key[i], params->wep_key_len[i]))
3377 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003378 }
3379
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003380 if (params->bssid) {
3381 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
3382 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003383 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
3384 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003385 }
3386 if (params->freq) {
3387 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
3389 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003390 }
3391 if (params->ssid) {
3392 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
3393 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003394 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
3395 params->ssid))
3396 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 }
3398 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003399 if (params->ie &&
3400 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
3401 goto fail;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003402 if (params->auth_data) {
3403 wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data,
3404 params->auth_data_len);
3405 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len,
3406 params->auth_data))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003407 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003408 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003409 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003410 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003411 if (type == NL80211_AUTHTYPE_MAX ||
3412 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003413 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003414 if (params->local_state_change) {
3415 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003416 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
3417 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003418 }
3419
3420 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3421 msg = NULL;
3422 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003423 wpa_dbg(drv->ctx, MSG_DEBUG,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003424 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
3425 count, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003426 count++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003427 if ((ret == -EALREADY || ret == -EEXIST) && count == 1 &&
3428 params->bssid && !params->local_state_change) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003429 /*
3430 * mac80211 does not currently accept new
3431 * authentication if we are already authenticated. As a
3432 * workaround, force deauthentication and try again.
3433 */
3434 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
3435 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07003436 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003437 wpa_driver_nl80211_deauthenticate(
3438 bss, params->bssid,
3439 WLAN_REASON_PREV_AUTH_NOT_VALID);
3440 nlmsg_free(msg);
3441 goto retry;
3442 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003443
3444 if (ret == -ENOENT && params->freq && !is_retry) {
3445 /*
3446 * cfg80211 has likely expired the BSS entry even
3447 * though it was previously available in our internal
3448 * BSS table. To recover quickly, start a single
3449 * channel scan on the specified channel.
3450 */
3451 struct wpa_driver_scan_params scan;
3452 int freqs[2];
3453
3454 os_memset(&scan, 0, sizeof(scan));
3455 scan.num_ssids = 1;
3456 if (params->ssid) {
3457 scan.ssids[0].ssid = params->ssid;
3458 scan.ssids[0].ssid_len = params->ssid_len;
3459 }
3460 freqs[0] = params->freq;
3461 freqs[1] = 0;
3462 scan.freqs = freqs;
3463 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3464 "channel scan to refresh cfg80211 BSS "
3465 "entry");
3466 ret = wpa_driver_nl80211_scan(bss, &scan);
3467 if (ret == 0) {
3468 nl80211_copy_auth_params(drv, params);
3469 drv->scan_for_auth = 1;
3470 }
3471 } else if (is_retry) {
3472 /*
3473 * Need to indicate this with an event since the return
3474 * value from the retry is not delivered to core code.
3475 */
3476 union wpa_event_data event;
3477 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3478 "failed");
3479 os_memset(&event, 0, sizeof(event));
3480 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3481 ETH_ALEN);
3482 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3483 &event);
3484 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003485 } else {
3486 wpa_printf(MSG_DEBUG,
3487 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003489
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003490fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003491 nlmsg_free(msg);
3492 return ret;
3493}
3494
3495
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003496int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003497{
3498 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003499 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003500 int i;
3501
3502 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3503
3504 os_memset(&params, 0, sizeof(params));
3505 params.freq = drv->auth_freq;
3506 params.auth_alg = drv->auth_alg;
3507 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3508 params.local_state_change = drv->auth_local_state_change;
3509 params.p2p = drv->auth_p2p;
3510
3511 if (!is_zero_ether_addr(drv->auth_bssid_))
3512 params.bssid = drv->auth_bssid_;
3513
3514 if (drv->auth_ssid_len) {
3515 params.ssid = drv->auth_ssid;
3516 params.ssid_len = drv->auth_ssid_len;
3517 }
3518
3519 params.ie = drv->auth_ie;
3520 params.ie_len = drv->auth_ie_len;
3521
3522 for (i = 0; i < 4; i++) {
3523 if (drv->auth_wep_key_len[i]) {
3524 params.wep_key[i] = drv->auth_wep_key[i];
3525 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3526 }
3527 }
3528
3529 drv->retry_auth = 1;
3530 return wpa_driver_nl80211_authenticate(bss, &params);
3531}
3532
3533
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003534static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3535 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003536 int encrypt, int noack,
3537 unsigned int freq, int no_cck,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003538 int offchanok, unsigned int wait_time,
3539 const u16 *csa_offs,
3540 size_t csa_offs_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003541{
3542 struct wpa_driver_nl80211_data *drv = bss->drv;
3543 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003544 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003545
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003546 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3547 freq = nl80211_get_assoc_freq(drv);
3548 wpa_printf(MSG_DEBUG,
3549 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3550 freq);
3551 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003552 if (freq == 0) {
3553 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3554 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003555 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003556 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003557
Dmitry Shmidt56052862013-10-04 10:23:25 -07003558 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003559 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003560 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003561 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003562 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003563
Dmitry Shmidt56052862013-10-04 10:23:25 -07003564 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003565 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003566 &cookie, no_cck, noack, offchanok,
3567 csa_offs, csa_offs_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003568 if (res == 0 && !noack) {
3569 const struct ieee80211_mgmt *mgmt;
3570 u16 fc;
3571
3572 mgmt = (const struct ieee80211_mgmt *) data;
3573 fc = le_to_host16(mgmt->frame_control);
3574 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3575 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3576 wpa_printf(MSG_MSGDUMP,
3577 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3578 (long long unsigned int)
3579 drv->send_action_cookie,
3580 (long long unsigned int) cookie);
3581 drv->send_action_cookie = cookie;
3582 }
3583 }
3584
3585 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003586}
3587
3588
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003589static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3590 size_t data_len, int noack,
3591 unsigned int freq, int no_cck,
3592 int offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003593 unsigned int wait_time,
3594 const u16 *csa_offs,
3595 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003596{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 struct wpa_driver_nl80211_data *drv = bss->drv;
3598 struct ieee80211_mgmt *mgmt;
3599 int encrypt = 1;
3600 u16 fc;
3601
3602 mgmt = (struct ieee80211_mgmt *) data;
3603 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003604 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3605 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3606 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3607 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003608
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003609 if ((is_sta_interface(drv->nlmode) ||
3610 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3612 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3613 /*
3614 * The use of last_mgmt_freq is a bit of a hack,
3615 * but it works due to the single-threaded nature
3616 * of wpa_supplicant.
3617 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003618 if (freq == 0) {
3619 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3620 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003621 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003622 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003623 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003624 data, data_len, NULL, 1, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003625 1, csa_offs, csa_offs_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003626 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003627
3628 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003629 if (freq == 0) {
3630 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3631 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003632 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003633 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003634 return nl80211_send_frame_cmd(bss, freq,
3635 (int) freq == bss->freq ? 0 :
3636 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003637 data, data_len,
3638 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003639 no_cck, noack, offchanok,
3640 csa_offs, csa_offs_len);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003641 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003643 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3644 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3645 /*
3646 * Only one of the authentication frame types is encrypted.
3647 * In order for static WEP encryption to work properly (i.e.,
3648 * to not encrypt the frame), we need to tell mac80211 about
3649 * the frames that must not be encrypted.
3650 */
3651 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3652 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3653 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3654 encrypt = 0;
3655 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003656
Dmitry Shmidt56052862013-10-04 10:23:25 -07003657 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003658 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003659 noack, freq, no_cck, offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003660 wait_time, csa_offs,
3661 csa_offs_len);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003662}
3663
3664
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003665static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3666{
3667 u8 rates[NL80211_MAX_SUPP_RATES];
3668 u8 rates_len = 0;
3669 int i;
3670
3671 if (!basic_rates)
3672 return 0;
3673
3674 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3675 rates[rates_len++] = basic_rates[i] / 5;
3676
3677 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3678}
3679
3680
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003681static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3682 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003683 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003684{
3685 struct wpa_driver_nl80211_data *drv = bss->drv;
3686 struct nl_msg *msg;
3687
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003688 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3689 (cts >= 0 &&
3690 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3691 (preamble >= 0 &&
3692 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3693 (slot >= 0 &&
3694 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3695 (ht_opmode >= 0 &&
3696 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3697 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003698 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3699 nl80211_put_basic_rates(msg, basic_rates)) {
3700 nlmsg_free(msg);
3701 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003702 }
3703
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003704 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003705}
3706
3707
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003708static int wpa_driver_nl80211_set_acl(void *priv,
3709 struct hostapd_acl_params *params)
3710{
3711 struct i802_bss *bss = priv;
3712 struct wpa_driver_nl80211_data *drv = bss->drv;
3713 struct nl_msg *msg;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003714 struct nl_msg *acl;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003715 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003716 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003717
3718 if (!(drv->capa.max_acl_mac_addrs))
3719 return -ENOTSUP;
3720
3721 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3722 return -ENOTSUP;
3723
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003724 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3725 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3726
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003727 acl = nlmsg_alloc();
3728 if (!acl)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003729 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003730 for (i = 0; i < params->num_mac_acl; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003731 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3732 nlmsg_free(acl);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003733 return -ENOMEM;
3734 }
3735 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003736
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003737 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3738 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3739 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3740 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3741 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
3742 nlmsg_free(msg);
3743 nlmsg_free(acl);
3744 return -ENOMEM;
3745 }
3746 nlmsg_free(acl);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003747
3748 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003749 if (ret) {
3750 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3751 ret, strerror(-ret));
3752 }
3753
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003754 return ret;
3755}
3756
3757
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003758static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3759{
3760 if (beacon_int > 0) {
3761 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3762 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3763 beacon_int);
3764 }
3765
3766 return 0;
3767}
3768
3769
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003770static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period)
3771{
3772 if (dtim_period > 0) {
3773 wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period);
3774 return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
3775 }
3776
3777 return 0;
3778}
3779
3780
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003781#ifdef CONFIG_MESH
3782static int nl80211_set_mesh_config(void *priv,
3783 struct wpa_driver_mesh_bss_params *params)
3784{
3785 struct i802_bss *bss = priv;
3786 struct wpa_driver_nl80211_data *drv = bss->drv;
3787 struct nl_msg *msg;
3788 int ret;
3789
3790 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG);
3791 if (!msg)
3792 return -1;
3793
3794 ret = nl80211_put_mesh_config(msg, params);
3795 if (ret < 0) {
3796 nlmsg_free(msg);
3797 return ret;
3798 }
3799
3800 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3801 if (ret) {
3802 wpa_printf(MSG_ERROR,
3803 "nl80211: Mesh config set failed: %d (%s)",
3804 ret, strerror(-ret));
3805 return ret;
3806 }
3807 return 0;
3808}
3809#endif /* CONFIG_MESH */
3810
3811
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003812static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags,
3813 struct wpa_driver_ap_params *params)
3814{
3815 struct nlattr *bands, *band;
3816 struct nl80211_txrate_vht vht_rate;
3817
3818 if (!params->freq ||
3819 (params->beacon_rate == 0 &&
3820 params->rate_type == BEACON_RATE_LEGACY))
3821 return 0;
3822
3823 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
3824 if (!bands)
3825 return -1;
3826
3827 switch (params->freq->mode) {
3828 case HOSTAPD_MODE_IEEE80211B:
3829 case HOSTAPD_MODE_IEEE80211G:
3830 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
3831 break;
3832 case HOSTAPD_MODE_IEEE80211A:
3833 band = nla_nest_start(msg, NL80211_BAND_5GHZ);
3834 break;
3835 case HOSTAPD_MODE_IEEE80211AD:
3836 band = nla_nest_start(msg, NL80211_BAND_60GHZ);
3837 break;
3838 default:
3839 return 0;
3840 }
3841
3842 if (!band)
3843 return -1;
3844
3845 os_memset(&vht_rate, 0, sizeof(vht_rate));
3846
3847 switch (params->rate_type) {
3848 case BEACON_RATE_LEGACY:
3849 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) {
3850 wpa_printf(MSG_INFO,
3851 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
3852 return -1;
3853 }
3854
3855 if (nla_put_u8(msg, NL80211_TXRATE_LEGACY,
3856 (u8) params->beacon_rate / 5) ||
3857 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
3858 (params->freq->vht_enabled &&
3859 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3860 &vht_rate)))
3861 return -1;
3862
3863 wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)",
3864 params->beacon_rate);
3865 break;
3866 case BEACON_RATE_HT:
3867 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) {
3868 wpa_printf(MSG_INFO,
3869 "nl80211: Driver does not support setting Beacon frame rate (HT)");
3870 return -1;
3871 }
3872 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
3873 nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) ||
3874 (params->freq->vht_enabled &&
3875 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3876 &vht_rate)))
3877 return -1;
3878 wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u",
3879 params->beacon_rate);
3880 break;
3881 case BEACON_RATE_VHT:
3882 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) {
3883 wpa_printf(MSG_INFO,
3884 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
3885 return -1;
3886 }
3887 vht_rate.mcs[0] = BIT(params->beacon_rate);
3888 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL))
3889 return -1;
3890 if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL))
3891 return -1;
3892 if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3893 &vht_rate))
3894 return -1;
3895 wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u",
3896 params->beacon_rate);
3897 break;
3898 }
3899
3900 nla_nest_end(msg, band);
3901 nla_nest_end(msg, bands);
3902
3903 return 0;
3904}
3905
3906
3907static int nl80211_set_multicast_to_unicast(struct i802_bss *bss,
3908 int multicast_to_unicast)
3909{
3910 struct wpa_driver_nl80211_data *drv = bss->drv;
3911 struct nl_msg *msg;
3912 int ret;
3913
3914 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST);
3915 if (!msg ||
3916 (multicast_to_unicast &&
3917 nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) {
3918 wpa_printf(MSG_ERROR,
3919 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
3920 bss->ifname);
3921 nlmsg_free(msg);
3922 return -ENOBUFS;
3923 }
3924
3925 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3926
3927 switch (ret) {
3928 case 0:
3929 wpa_printf(MSG_DEBUG,
3930 "nl80211: multicast to unicast %s on interface %s",
3931 multicast_to_unicast ? "enabled" : "disabled",
3932 bss->ifname);
3933 break;
3934 case -EOPNOTSUPP:
3935 if (!multicast_to_unicast)
3936 break;
3937 wpa_printf(MSG_INFO,
3938 "nl80211: multicast to unicast not supported on interface %s",
3939 bss->ifname);
3940 break;
3941 default:
3942 wpa_printf(MSG_ERROR,
3943 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
3944 multicast_to_unicast ? "enabling" : "disabling",
3945 ret, strerror(-ret), bss->ifname);
3946 break;
3947 }
3948
3949 return ret;
3950}
3951
3952
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003953static int wpa_driver_nl80211_set_ap(void *priv,
3954 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003955{
3956 struct i802_bss *bss = priv;
3957 struct wpa_driver_nl80211_data *drv = bss->drv;
3958 struct nl_msg *msg;
3959 u8 cmd = NL80211_CMD_NEW_BEACON;
3960 int ret;
3961 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003962 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003963 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003964 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003965 u32 ver;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003966#ifdef CONFIG_MESH
3967 struct wpa_driver_mesh_bss_params mesh_params;
3968#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003969
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003970 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003971
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003972 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3973 beacon_set);
3974 if (beacon_set)
3975 cmd = NL80211_CMD_SET_BEACON;
Paul Stewart092955c2017-02-06 09:13:09 -08003976 else if (!drv->device_ap_sme && !drv->use_monitor &&
3977 !nl80211_get_wiphy_data_ap(bss))
3978 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003979
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003980 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3981 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003982 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3983 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003984 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003985 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003986 wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate);
3987 wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003988 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003989 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3990 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003991 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3992 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3993 params->head) ||
3994 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3995 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003996 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003997 nl80211_put_beacon_rate(msg, drv->capa.flags, params) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003998 nl80211_put_dtim_period(msg, params->dtim_period) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003999 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4000 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004001 if (params->proberesp && params->proberesp_len) {
4002 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
4003 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004004 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
4005 params->proberesp))
4006 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004007 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004008 switch (params->hide_ssid) {
4009 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004010 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004011 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4012 NL80211_HIDDEN_SSID_NOT_IN_USE))
4013 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004014 break;
4015 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004016 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004017 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4018 NL80211_HIDDEN_SSID_ZERO_LEN))
4019 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004020 break;
4021 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004022 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004023 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4024 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
4025 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004026 break;
4027 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004028 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004029 if (params->privacy &&
4030 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
4031 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004032 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004033 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
4034 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
4035 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004036 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
4037 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4038 NL80211_AUTHTYPE_SHARED_KEY))
4039 goto fail;
4040 } else {
4041 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4042 NL80211_AUTHTYPE_OPEN_SYSTEM))
4043 goto fail;
4044 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004045
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004046 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004047 ver = 0;
4048 if (params->wpa_version & WPA_PROTO_WPA)
4049 ver |= NL80211_WPA_VERSION_1;
4050 if (params->wpa_version & WPA_PROTO_RSN)
4051 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004052 if (ver &&
4053 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4054 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004055
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004056 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
4057 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004058 num_suites = 0;
4059 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
Paul Stewart092955c2017-02-06 09:13:09 -08004060 suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004061 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
Paul Stewart092955c2017-02-06 09:13:09 -08004062 suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004063 if (num_suites &&
4064 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
4065 suites))
4066 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004067
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004068 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004069 (!params->pairwise_ciphers ||
4070 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
4071 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
4072 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004073 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004074
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004075 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
4076 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004077 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
4078 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004079 if (num_suites &&
4080 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4081 num_suites * sizeof(u32), suites))
4082 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004083
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004084 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
4085 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004086 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004087 if (suite &&
4088 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
4089 goto fail;
4090
Dmitry Shmidte4663042016-04-04 10:07:49 -07004091 if (params->ht_opmode != -1) {
4092 switch (params->smps_mode) {
4093 case HT_CAP_INFO_SMPS_DYNAMIC:
4094 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
4095 smps_mode = NL80211_SMPS_DYNAMIC;
4096 break;
4097 case HT_CAP_INFO_SMPS_STATIC:
4098 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
4099 smps_mode = NL80211_SMPS_STATIC;
4100 break;
4101 default:
4102 /* invalid - fallback to smps off */
4103 case HT_CAP_INFO_SMPS_DISABLED:
4104 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
4105 smps_mode = NL80211_SMPS_OFF;
4106 break;
4107 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004108 if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
Dmitry Shmidte4663042016-04-04 10:07:49 -07004109 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004110 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004111
4112 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004113 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
4114 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004115 if (nla_put(msg, NL80211_ATTR_IE,
4116 wpabuf_len(params->beacon_ies),
4117 wpabuf_head(params->beacon_ies)))
4118 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004119 }
4120 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004121 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
4122 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004123 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
4124 wpabuf_len(params->proberesp_ies),
4125 wpabuf_head(params->proberesp_ies)))
4126 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004127 }
4128 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004129 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
4130 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004131 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
4132 wpabuf_len(params->assocresp_ies),
4133 wpabuf_head(params->assocresp_ies)))
4134 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004135 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004136
Dmitry Shmidt04949592012-07-19 12:16:46 -07004137 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004138 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
4139 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004140 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
4141 params->ap_max_inactivity))
4142 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004143 }
4144
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004145#ifdef CONFIG_P2P
4146 if (params->p2p_go_ctwindow > 0) {
4147 if (drv->p2p_go_ctwindow_supported) {
4148 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
4149 params->p2p_go_ctwindow);
4150 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
4151 params->p2p_go_ctwindow))
4152 goto fail;
4153 } else {
4154 wpa_printf(MSG_INFO,
4155 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4156 }
4157 }
4158#endif /* CONFIG_P2P */
4159
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004160 if (params->pbss) {
4161 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
4162 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
4163 goto fail;
4164 }
4165
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004166 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4167 if (ret) {
4168 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
4169 ret, strerror(-ret));
4170 } else {
4171 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004172 nl80211_set_bss(bss, params->cts_protect, params->preamble,
4173 params->short_slot_time, params->ht_opmode,
4174 params->isolate, params->basic_rates);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004175 nl80211_set_multicast_to_unicast(bss,
4176 params->multicast_to_unicast);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004177 if (beacon_set && params->freq &&
4178 params->freq->bandwidth != bss->bandwidth) {
4179 wpa_printf(MSG_DEBUG,
4180 "nl80211: Update BSS %s bandwidth: %d -> %d",
4181 bss->ifname, bss->bandwidth,
4182 params->freq->bandwidth);
4183 ret = nl80211_set_channel(bss, params->freq, 1);
4184 if (ret) {
4185 wpa_printf(MSG_DEBUG,
4186 "nl80211: Frequency set failed: %d (%s)",
4187 ret, strerror(-ret));
4188 } else {
4189 wpa_printf(MSG_DEBUG,
4190 "nl80211: Frequency set succeeded for ht2040 coex");
4191 bss->bandwidth = params->freq->bandwidth;
4192 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004193 } else if (!beacon_set && params->freq) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004194 /*
4195 * cfg80211 updates the driver on frequence change in AP
4196 * mode only at the point when beaconing is started, so
4197 * set the initial value here.
4198 */
4199 bss->bandwidth = params->freq->bandwidth;
4200 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004201 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004202
4203#ifdef CONFIG_MESH
4204 if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) {
4205 os_memset(&mesh_params, 0, sizeof(mesh_params));
4206 mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
4207 mesh_params.ht_opmode = params->ht_opmode;
4208 ret = nl80211_set_mesh_config(priv, &mesh_params);
4209 if (ret < 0)
4210 return ret;
4211 }
4212#endif /* CONFIG_MESH */
4213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004214 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004215fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004216 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004217 return -ENOBUFS;
4218}
4219
4220
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004221static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004222 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004223{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004224 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004225 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
4226 return -ENOBUFS;
4227
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004228 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
4229 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
4230
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004231 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004232 enum nl80211_chan_width cw;
4233
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004234 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004235 switch (freq->bandwidth) {
4236 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004237 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004238 break;
4239 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004240 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004241 break;
4242 case 80:
4243 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004244 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004245 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004246 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004247 break;
4248 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004249 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004250 break;
4251 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004252 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004253 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004254
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004255 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
4256 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
4257 freq->center_freq1);
4258 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
4259 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004260 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
4261 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
4262 freq->center_freq1) ||
4263 (freq->center_freq2 &&
4264 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
4265 freq->center_freq2)))
4266 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004267 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004268 enum nl80211_channel_type ct;
4269
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004270 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
4271 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004272 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004273 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004274 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004275 break;
4276 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004277 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278 break;
4279 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004280 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004281 break;
4282 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004283
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004284 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004285 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
4286 return -ENOBUFS;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004287 } else {
4288 wpa_printf(MSG_DEBUG, " * channel_type=%d",
4289 NL80211_CHAN_NO_HT);
4290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
4291 NL80211_CHAN_NO_HT))
4292 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004294 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004295}
4296
4297
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004298static int nl80211_set_channel(struct i802_bss *bss,
4299 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004300{
4301 struct wpa_driver_nl80211_data *drv = bss->drv;
4302 struct nl_msg *msg;
4303 int ret;
4304
4305 wpa_printf(MSG_DEBUG,
4306 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4307 freq->freq, freq->ht_enabled, freq->vht_enabled,
4308 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004309
4310 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
4311 NL80211_CMD_SET_WIPHY);
4312 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
4313 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004314 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004315 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004316
4317 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004318 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004319 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004320 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004321 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004323 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004324 return -1;
4325}
4326
4327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004328static u32 sta_flags_nl80211(int flags)
4329{
4330 u32 f = 0;
4331
4332 if (flags & WPA_STA_AUTHORIZED)
4333 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
4334 if (flags & WPA_STA_WMM)
4335 f |= BIT(NL80211_STA_FLAG_WME);
4336 if (flags & WPA_STA_SHORT_PREAMBLE)
4337 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
4338 if (flags & WPA_STA_MFP)
4339 f |= BIT(NL80211_STA_FLAG_MFP);
4340 if (flags & WPA_STA_TDLS_PEER)
4341 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004342 if (flags & WPA_STA_AUTHENTICATED)
4343 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004344 if (flags & WPA_STA_ASSOCIATED)
4345 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004346
4347 return f;
4348}
4349
4350
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004351#ifdef CONFIG_MESH
4352static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
4353{
4354 switch (state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004355 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004356 return NL80211_PLINK_LISTEN;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004357 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004358 return NL80211_PLINK_OPN_SNT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004359 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004360 return NL80211_PLINK_OPN_RCVD;
4361 case PLINK_CNF_RCVD:
4362 return NL80211_PLINK_CNF_RCVD;
4363 case PLINK_ESTAB:
4364 return NL80211_PLINK_ESTAB;
4365 case PLINK_HOLDING:
4366 return NL80211_PLINK_HOLDING;
4367 case PLINK_BLOCKED:
4368 return NL80211_PLINK_BLOCKED;
4369 default:
4370 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
4371 state);
4372 }
4373 return -1;
4374}
4375#endif /* CONFIG_MESH */
4376
4377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378static int wpa_driver_nl80211_sta_add(void *priv,
4379 struct hostapd_sta_add_params *params)
4380{
4381 struct i802_bss *bss = priv;
4382 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004383 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004384 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385 int ret = -ENOBUFS;
4386
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004387 if ((params->flags & WPA_STA_TDLS_PEER) &&
4388 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
4389 return -EOPNOTSUPP;
4390
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004391 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
4392 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004393 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
4394 NL80211_CMD_NEW_STATION);
4395 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
4396 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004397
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004398 /*
4399 * Set the below properties only in one of the following cases:
4400 * 1. New station is added, already associated.
4401 * 2. Set WPA_STA_TDLS_PEER station.
4402 * 3. Set an already added unassociated station, if driver supports
4403 * full AP client state. (Set these properties after station became
4404 * associated will be rejected by the driver).
4405 */
4406 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4407 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4408 (params->flags & WPA_STA_ASSOCIATED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004409 wpa_hexdump(MSG_DEBUG, " * supported rates",
4410 params->supp_rates, params->supp_rates_len);
4411 wpa_printf(MSG_DEBUG, " * capability=0x%x",
4412 params->capability);
4413 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
4414 params->supp_rates_len, params->supp_rates) ||
4415 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
4416 params->capability))
4417 goto fail;
4418
4419 if (params->ht_capabilities) {
4420 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
4421 (u8 *) params->ht_capabilities,
4422 sizeof(*params->ht_capabilities));
4423 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
4424 sizeof(*params->ht_capabilities),
4425 params->ht_capabilities))
4426 goto fail;
4427 }
4428
4429 if (params->vht_capabilities) {
4430 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
4431 (u8 *) params->vht_capabilities,
4432 sizeof(*params->vht_capabilities));
4433 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
4434 sizeof(*params->vht_capabilities),
4435 params->vht_capabilities))
4436 goto fail;
4437 }
4438
4439 if (params->ext_capab) {
4440 wpa_hexdump(MSG_DEBUG, " * ext_capab",
4441 params->ext_capab, params->ext_capab_len);
4442 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
4443 params->ext_capab_len, params->ext_capab))
4444 goto fail;
4445 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004446
4447 if (is_ap_interface(drv->nlmode) &&
4448 nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS,
4449 params->support_p2p_ps ?
4450 NL80211_P2P_PS_SUPPORTED :
4451 NL80211_P2P_PS_UNSUPPORTED))
4452 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004453 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004454 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004455 if (params->aid) {
4456 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004457 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
4458 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004459 } else {
4460 /*
4461 * cfg80211 validates that AID is non-zero, so we have
4462 * to make this a non-zero value for the TDLS case where
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004463 * a dummy STA entry is used for now and for a station
4464 * that is still not associated.
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004465 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004466 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
4467 (params->flags & WPA_STA_TDLS_PEER) ?
4468 "TDLS" : "UNASSOC_STA");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004469 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
4470 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004471 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004472 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4473 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004474 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4475 params->listen_interval))
4476 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004477 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
4478 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004479 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
4480 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004481 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4482 (params->flags & WPA_STA_ASSOCIATED)) {
4483 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
4484 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4485 params->listen_interval);
4486 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
4487 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4488 params->listen_interval))
4489 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004490 }
4491
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004492 if (params->vht_opmode_enabled) {
4493 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004494 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
4495 params->vht_opmode))
4496 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004497 }
4498
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004499 if (params->supp_channels) {
4500 wpa_hexdump(MSG_DEBUG, " * supported channels",
4501 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004502 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
4503 params->supp_channels_len, params->supp_channels))
4504 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004505 }
4506
4507 if (params->supp_oper_classes) {
4508 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
4509 params->supp_oper_classes,
4510 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004511 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
4512 params->supp_oper_classes_len,
4513 params->supp_oper_classes))
4514 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004515 }
4516
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004517 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004518 upd.set = sta_flags_nl80211(params->flags);
4519 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004520
4521 /*
4522 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4523 * flags, as nl80211 driver moves a new station, by default, into
4524 * associated state.
4525 *
4526 * On the other hand, if the driver supports that feature and the
4527 * station is added in unauthenticated state, set the
4528 * authenticated/associated bits in the mask to prevent moving this
4529 * station to associated state before it is actually associated.
4530 *
4531 * This is irrelevant for mesh mode where the station is added to the
4532 * driver as authenticated already, and ASSOCIATED isn't part of the
4533 * nl80211 API.
4534 */
4535 if (!is_mesh_interface(drv->nlmode)) {
4536 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
4537 wpa_printf(MSG_DEBUG,
4538 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4539 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
4540 BIT(NL80211_STA_FLAG_AUTHENTICATED));
4541 } else if (!params->set &&
4542 !(params->flags & WPA_STA_TDLS_PEER)) {
4543 if (!(params->flags & WPA_STA_AUTHENTICATED))
4544 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
4545 if (!(params->flags & WPA_STA_ASSOCIATED))
4546 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
4547 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004548#ifdef CONFIG_MESH
4549 } else {
4550 if (params->plink_state == PLINK_ESTAB && params->peer_aid) {
4551 ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID,
4552 params->peer_aid);
4553 if (ret)
4554 goto fail;
4555 }
4556#endif /* CONFIG_MESH */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004557 }
4558
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004559 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
4560 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004561 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4562 goto fail;
4563
4564#ifdef CONFIG_MESH
4565 if (params->plink_state &&
4566 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
4567 sta_plink_state_nl80211(params->plink_state)))
4568 goto fail;
4569#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004570
4571 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004572 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
4573
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004574 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004575 if (!wme ||
4576 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
4577 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
4578 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
4579 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
4580 WMM_QOSINFO_STA_SP_MASK))
4581 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004582 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004583 }
4584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004585 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004586 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004587 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004588 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
4589 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
4590 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004591 if (ret == -EEXIST)
4592 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004593fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004594 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004595 return ret;
4596}
4597
4598
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004599static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
4600{
4601#ifdef CONFIG_LIBNL3_ROUTE
4602 struct wpa_driver_nl80211_data *drv = bss->drv;
4603 struct rtnl_neigh *rn;
4604 struct nl_addr *nl_addr;
4605 int err;
4606
4607 rn = rtnl_neigh_alloc();
4608 if (!rn)
4609 return;
4610
4611 rtnl_neigh_set_family(rn, AF_BRIDGE);
4612 rtnl_neigh_set_ifindex(rn, bss->ifindex);
4613 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
4614 if (!nl_addr) {
4615 rtnl_neigh_put(rn);
4616 return;
4617 }
4618 rtnl_neigh_set_lladdr(rn, nl_addr);
4619
4620 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
4621 if (err < 0) {
4622 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
4623 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
4624 bss->ifindex, nl_geterror(err));
4625 } else {
4626 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
4627 MACSTR, MAC2STR(addr));
4628 }
4629
4630 nl_addr_put(nl_addr);
4631 rtnl_neigh_put(rn);
4632#endif /* CONFIG_LIBNL3_ROUTE */
4633}
4634
4635
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004636static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
4637 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004638{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004639 struct wpa_driver_nl80211_data *drv = bss->drv;
4640 struct nl_msg *msg;
4641 int ret;
4642
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004643 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
4644 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
4645 (deauth == 0 &&
4646 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4647 WLAN_FC_STYPE_DISASSOC)) ||
4648 (deauth == 1 &&
4649 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4650 WLAN_FC_STYPE_DEAUTH)) ||
4651 (reason_code &&
4652 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
4653 nlmsg_free(msg);
4654 return -ENOBUFS;
4655 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004656
4657 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004658 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4659 " --> %d (%s)",
4660 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004661
4662 if (drv->rtnl_sk)
4663 rtnl_neigh_delete_fdb_entry(bss, addr);
4664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004665 if (ret == -ENOENT)
4666 return 0;
4667 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004668}
4669
4670
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004671void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004672{
4673 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004674 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004675
4676 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
4677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004678 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004679 dl_list_for_each(drv2, &drv->global->interfaces,
4680 struct wpa_driver_nl80211_data, list)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004681 {
4682 del_ifidx(drv2, ifidx, IFIDX_ANY);
4683 /* Remove all bridges learned for this iface */
4684 del_ifidx(drv2, IFIDX_ANY, ifidx);
4685 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004686
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004687 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004688 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
4689 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004690 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
4691}
4692
4693
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004694const char * nl80211_iftype_str(enum nl80211_iftype mode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004695{
4696 switch (mode) {
4697 case NL80211_IFTYPE_ADHOC:
4698 return "ADHOC";
4699 case NL80211_IFTYPE_STATION:
4700 return "STATION";
4701 case NL80211_IFTYPE_AP:
4702 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004703 case NL80211_IFTYPE_AP_VLAN:
4704 return "AP_VLAN";
4705 case NL80211_IFTYPE_WDS:
4706 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004707 case NL80211_IFTYPE_MONITOR:
4708 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004709 case NL80211_IFTYPE_MESH_POINT:
4710 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004711 case NL80211_IFTYPE_P2P_CLIENT:
4712 return "P2P_CLIENT";
4713 case NL80211_IFTYPE_P2P_GO:
4714 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004715 case NL80211_IFTYPE_P2P_DEVICE:
4716 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004717 default:
4718 return "unknown";
4719 }
4720}
4721
4722
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004723static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
4724 const char *ifname,
4725 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004726 const u8 *addr, int wds,
4727 int (*handler)(struct nl_msg *, void *),
4728 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004730 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004731 int ifidx;
4732 int ret = -ENOBUFS;
4733
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004734 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
4735 iftype, nl80211_iftype_str(iftype));
4736
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004737 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
4738 if (!msg ||
4739 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
4740 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
4741 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004742
4743 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004744 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004745
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004746 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004747 if (!flags ||
4748 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
4749 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004750
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004751 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004752 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004753 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
4754 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004755 }
4756
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004757 /*
4758 * Tell cfg80211 that the interface belongs to the socket that created
4759 * it, and the interface should be deleted when the socket is closed.
4760 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004761 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
4762 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004763
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004764 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004765 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004766 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004767 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004768 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004769 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4770 ifname, ret, strerror(-ret));
4771 return ret;
4772 }
4773
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004774 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4775 return 0;
4776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004777 ifidx = if_nametoindex(ifname);
4778 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4779 ifname, ifidx);
4780
4781 if (ifidx <= 0)
4782 return -1;
4783
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004784 /*
4785 * Some virtual interfaces need to process EAPOL packets and events on
4786 * the parent interface. This is used mainly with hostapd.
4787 */
4788 if (drv->hostapd ||
4789 iftype == NL80211_IFTYPE_AP_VLAN ||
4790 iftype == NL80211_IFTYPE_WDS ||
4791 iftype == NL80211_IFTYPE_MONITOR) {
4792 /* start listening for EAPOL on this interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004793 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004794 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004795
4796 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004797 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004798 nl80211_remove_iface(drv, ifidx);
4799 return -1;
4800 }
4801
4802 return ifidx;
4803}
4804
4805
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004806int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4807 const char *ifname, enum nl80211_iftype iftype,
4808 const u8 *addr, int wds,
4809 int (*handler)(struct nl_msg *, void *),
4810 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004811{
4812 int ret;
4813
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004814 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4815 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004816
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004817 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004818 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004819 if (use_existing) {
4820 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4821 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004822 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4823 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4824 addr) < 0 &&
4825 (linux_set_iface_flags(drv->global->ioctl_sock,
4826 ifname, 0) < 0 ||
4827 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4828 addr) < 0 ||
4829 linux_set_iface_flags(drv->global->ioctl_sock,
4830 ifname, 1) < 0))
4831 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004832 return -ENFILE;
4833 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004834 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4835
4836 /* Try to remove the interface that was already there. */
4837 nl80211_remove_iface(drv, if_nametoindex(ifname));
4838
4839 /* Try to create the interface again */
4840 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004841 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004842 }
4843
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004844 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4845 wpa_printf(MSG_DEBUG,
4846 "nl80211: Interface %s created for P2P - disable 11b rates",
4847 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004848 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004849 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004850
4851 return ret;
4852}
4853
4854
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004855static int nl80211_setup_ap(struct i802_bss *bss)
4856{
4857 struct wpa_driver_nl80211_data *drv = bss->drv;
4858
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004859 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4860 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004861
4862 /*
4863 * Disable Probe Request reporting unless we need it in this way for
4864 * devices that include the AP SME, in the other case (unless using
4865 * monitor iface) we'll get it through the nl_mgmt socket instead.
4866 */
4867 if (!drv->device_ap_sme)
4868 wpa_driver_nl80211_probe_req_report(bss, 0);
4869
4870 if (!drv->device_ap_sme && !drv->use_monitor)
4871 if (nl80211_mgmt_subscribe_ap(bss))
4872 return -1;
4873
4874 if (drv->device_ap_sme && !drv->use_monitor)
4875 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004876 wpa_printf(MSG_DEBUG,
4877 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004878
4879 if (!drv->device_ap_sme && drv->use_monitor &&
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004880 nl80211_create_monitor_interface(drv) &&
4881 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004882 return -1;
4883
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004884 if (drv->device_ap_sme &&
4885 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4886 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4887 "Probe Request frame reporting in AP mode");
4888 /* Try to survive without this */
4889 }
4890
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004891 return 0;
4892}
4893
4894
4895static void nl80211_teardown_ap(struct i802_bss *bss)
4896{
4897 struct wpa_driver_nl80211_data *drv = bss->drv;
4898
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004899 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4900 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004901 if (drv->device_ap_sme) {
4902 wpa_driver_nl80211_probe_req_report(bss, 0);
4903 if (!drv->use_monitor)
4904 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4905 } else if (drv->use_monitor)
4906 nl80211_remove_monitor_interface(drv);
4907 else
4908 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4909
Paul Stewart092955c2017-02-06 09:13:09 -08004910 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004911 bss->beacon_set = 0;
4912}
4913
4914
4915static int nl80211_send_eapol_data(struct i802_bss *bss,
4916 const u8 *addr, const u8 *data,
4917 size_t data_len)
4918{
4919 struct sockaddr_ll ll;
4920 int ret;
4921
4922 if (bss->drv->eapol_tx_sock < 0) {
4923 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4924 return -1;
4925 }
4926
4927 os_memset(&ll, 0, sizeof(ll));
4928 ll.sll_family = AF_PACKET;
4929 ll.sll_ifindex = bss->ifindex;
4930 ll.sll_protocol = htons(ETH_P_PAE);
4931 ll.sll_halen = ETH_ALEN;
4932 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4933 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4934 (struct sockaddr *) &ll, sizeof(ll));
4935 if (ret < 0)
4936 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4937 strerror(errno));
4938
4939 return ret;
4940}
4941
4942
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004943static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4944
4945static int wpa_driver_nl80211_hapd_send_eapol(
4946 void *priv, const u8 *addr, const u8 *data,
4947 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4948{
4949 struct i802_bss *bss = priv;
4950 struct wpa_driver_nl80211_data *drv = bss->drv;
4951 struct ieee80211_hdr *hdr;
4952 size_t len;
4953 u8 *pos;
4954 int res;
4955 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004956
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004957 if (drv->device_ap_sme || !drv->use_monitor)
4958 return nl80211_send_eapol_data(bss, addr, data, data_len);
4959
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004960 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4961 data_len;
4962 hdr = os_zalloc(len);
4963 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004964 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4965 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004966 return -1;
4967 }
4968
4969 hdr->frame_control =
4970 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4971 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4972 if (encrypt)
4973 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4974 if (qos) {
4975 hdr->frame_control |=
4976 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4977 }
4978
4979 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4980 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4981 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4982 pos = (u8 *) (hdr + 1);
4983
4984 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004985 /* Set highest priority in QoS header */
4986 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987 pos[1] = 0;
4988 pos += 2;
4989 }
4990
4991 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4992 pos += sizeof(rfc1042_header);
4993 WPA_PUT_BE16(pos, ETH_P_PAE);
4994 pos += 2;
4995 memcpy(pos, data, data_len);
4996
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004997 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004998 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004999 if (res < 0) {
5000 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
5001 "failed: %d (%s)",
5002 (unsigned long) len, errno, strerror(errno));
5003 }
5004 os_free(hdr);
5005
5006 return res;
5007}
5008
5009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005010static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005011 unsigned int total_flags,
5012 unsigned int flags_or,
5013 unsigned int flags_and)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005014{
5015 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005016 struct nl_msg *msg;
5017 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005018 struct nl80211_sta_flag_update upd;
5019
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005020 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
5021 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
5022 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
5023 !!(total_flags & WPA_STA_AUTHORIZED));
5024
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005025 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5026 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
5027 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005028
5029 /*
5030 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5031 * can be removed eventually.
5032 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005033 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005034 if (!flags ||
5035 ((total_flags & WPA_STA_AUTHORIZED) &&
5036 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
5037 ((total_flags & WPA_STA_WMM) &&
5038 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
5039 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
5040 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
5041 ((total_flags & WPA_STA_MFP) &&
5042 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
5043 ((total_flags & WPA_STA_TDLS_PEER) &&
5044 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
5045 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005046
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005047 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005048
5049 os_memset(&upd, 0, sizeof(upd));
5050 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
5051 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005052 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
5053 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005054
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005055 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5056fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005057 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005058 return -ENOBUFS;
5059}
5060
5061
5062static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
5063 struct wpa_driver_associate_params *params)
5064{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005065 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005066
5067 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005068 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
5069 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005070 nlmode = NL80211_IFTYPE_P2P_GO;
5071 } else
5072 nlmode = NL80211_IFTYPE_AP;
5073
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005074 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005075 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005076 nl80211_remove_monitor_interface(drv);
5077 return -1;
5078 }
5079
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005080 if (params->freq.freq &&
5081 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005082 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005083 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005084 nl80211_remove_monitor_interface(drv);
5085 return -1;
5086 }
5087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005088 return 0;
5089}
5090
5091
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005092static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
5093 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094{
5095 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005096 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005097
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005098 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005099 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005100 if (ret) {
5101 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
5102 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005103 } else {
5104 wpa_printf(MSG_DEBUG,
5105 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005106 }
5107
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005108 if (reset_mode &&
5109 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07005110 NL80211_IFTYPE_STATION)) {
5111 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5112 "station mode");
5113 }
5114
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005115 return ret;
5116}
5117
5118
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005119static int nl80211_ht_vht_overrides(struct nl_msg *msg,
5120 struct wpa_driver_associate_params *params)
5121{
5122 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
5123 return -1;
5124
5125 if (params->htcaps && params->htcaps_mask) {
5126 int sz = sizeof(struct ieee80211_ht_capabilities);
5127 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
5128 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
5129 params->htcaps_mask, sz);
5130 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
5131 params->htcaps) ||
5132 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
5133 params->htcaps_mask))
5134 return -1;
5135 }
5136
5137#ifdef CONFIG_VHT_OVERRIDES
5138 if (params->disable_vht) {
5139 wpa_printf(MSG_DEBUG, " * VHT disabled");
5140 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
5141 return -1;
5142 }
5143
5144 if (params->vhtcaps && params->vhtcaps_mask) {
5145 int sz = sizeof(struct ieee80211_vht_capabilities);
5146 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
5147 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
5148 params->vhtcaps_mask, sz);
5149 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
5150 params->vhtcaps) ||
5151 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
5152 params->vhtcaps_mask))
5153 return -1;
5154 }
5155#endif /* CONFIG_VHT_OVERRIDES */
5156
5157 return 0;
5158}
5159
5160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005161static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
5162 struct wpa_driver_associate_params *params)
5163{
5164 struct nl_msg *msg;
5165 int ret = -1;
5166 int count = 0;
5167
5168 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
5169
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005170 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005171 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5172 "IBSS mode");
5173 return -1;
5174 }
5175
5176retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005177 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
5178 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
5179 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005180
5181 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
5182 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005183 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
5184 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005185 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5186 drv->ssid_len = params->ssid_len;
5187
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005188 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
5189 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005190 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005191
5192 ret = nl80211_set_conn_keys(params, msg);
5193 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005194 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005195
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005196 if (params->bssid && params->fixed_bssid) {
5197 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
5198 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005199 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5200 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005201 }
5202
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005203 if (params->fixed_freq) {
5204 wpa_printf(MSG_DEBUG, " * fixed_freq");
5205 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
5206 goto fail;
5207 }
5208
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005209 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5210 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5211 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
5212 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005213 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005214 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5215 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005216 }
5217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005218 if (params->wpa_ie) {
5219 wpa_hexdump(MSG_DEBUG,
5220 " * Extra IEs for Beacon/Probe Response frames",
5221 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005222 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
5223 params->wpa_ie))
5224 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005225 }
5226
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08005227 ret = nl80211_ht_vht_overrides(msg, params);
5228 if (ret < 0)
5229 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005230
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005231 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5232 msg = NULL;
5233 if (ret) {
5234 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
5235 ret, strerror(-ret));
5236 count++;
5237 if (ret == -EALREADY && count == 1) {
5238 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
5239 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005240 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005241 nlmsg_free(msg);
5242 goto retry;
5243 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005244 } else {
5245 wpa_printf(MSG_DEBUG,
5246 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005247 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005248
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005249fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005250 nlmsg_free(msg);
5251 return ret;
5252}
5253
5254
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005255static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv,
5256 struct wpa_driver_associate_params *params,
5257 struct nl_msg *msg)
5258{
5259 if (params->fils_erp_username_len) {
5260 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username",
5261 params->fils_erp_username,
5262 params->fils_erp_username_len);
5263 if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME,
5264 params->fils_erp_username_len,
5265 params->fils_erp_username))
5266 return -1;
5267 }
5268
5269 if (params->fils_erp_realm_len) {
5270 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm",
5271 params->fils_erp_realm,
5272 params->fils_erp_realm_len);
5273 if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM,
5274 params->fils_erp_realm_len, params->fils_erp_realm))
5275 return -1;
5276 }
5277
5278 wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u",
5279 params->fils_erp_next_seq_num);
5280 if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
5281 params->fils_erp_next_seq_num))
5282 return -1;
5283
5284 if (params->fils_erp_rrk_len) {
5285 wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)",
5286 (unsigned long) params->fils_erp_rrk_len);
5287 if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK,
5288 params->fils_erp_rrk_len, params->fils_erp_rrk))
5289 return -1;
5290 }
5291
5292 return 0;
5293}
5294
5295
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005296static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
5297 struct wpa_driver_associate_params *params,
5298 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005299{
Paul Stewart092955c2017-02-06 09:13:09 -08005300 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
5301 return -1;
5302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005303 if (params->bssid) {
5304 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
5305 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005306 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5307 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005308 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005309
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005310 if (params->bssid_hint) {
5311 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
5312 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005313 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
5314 params->bssid_hint))
5315 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005316 }
5317
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005318 if (params->freq.freq) {
5319 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
5321 params->freq.freq))
5322 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005323 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005324 } else
5325 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005326
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005327 if (params->freq_hint) {
5328 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
5330 params->freq_hint))
5331 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005332 }
5333
Dmitry Shmidt04949592012-07-19 12:16:46 -07005334 if (params->bg_scan_period >= 0) {
5335 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
5336 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005337 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
5338 params->bg_scan_period))
5339 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005340 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005342 if (params->ssid) {
5343 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
5344 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005345 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
5346 params->ssid))
5347 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005348 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005349 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005350 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5351 drv->ssid_len = params->ssid_len;
5352 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005354 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005355 if (params->wpa_ie &&
5356 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
5357 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005358
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005359 if (params->wpa_proto) {
5360 enum nl80211_wpa_versions ver = 0;
5361
5362 if (params->wpa_proto & WPA_PROTO_WPA)
5363 ver |= NL80211_WPA_VERSION_1;
5364 if (params->wpa_proto & WPA_PROTO_RSN)
5365 ver |= NL80211_WPA_VERSION_2;
5366
5367 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005368 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
5369 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005370 }
5371
5372 if (params->pairwise_suite != WPA_CIPHER_NONE) {
5373 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
5374 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005375 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
5376 cipher))
5377 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005378 }
5379
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005380 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
5381 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
5382 /*
5383 * This is likely to work even though many drivers do not
5384 * advertise support for operations without GTK.
5385 */
5386 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5387 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005388 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
5389 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005390 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
5391 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005392 }
5393
5394 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5395 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5396 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
5397 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07005398 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005399 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
5400 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005401 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005402 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005403 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
5404 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 ||
5405 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 ||
5406 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07005407 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 ||
5408 params->key_mgmt_suite == WPA_KEY_MGMT_OWE ||
5409 params->key_mgmt_suite == WPA_KEY_MGMT_DPP) {
Paul Stewart092955c2017-02-06 09:13:09 -08005410 int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005411
5412 switch (params->key_mgmt_suite) {
5413 case WPA_KEY_MGMT_CCKM:
Paul Stewart092955c2017-02-06 09:13:09 -08005414 mgmt = RSN_AUTH_KEY_MGMT_CCKM;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005415 break;
5416 case WPA_KEY_MGMT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005417 mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005418 break;
5419 case WPA_KEY_MGMT_FT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005420 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005421 break;
5422 case WPA_KEY_MGMT_FT_PSK:
Paul Stewart092955c2017-02-06 09:13:09 -08005423 mgmt = RSN_AUTH_KEY_MGMT_FT_PSK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005424 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005425 case WPA_KEY_MGMT_IEEE8021X_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005426 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005427 break;
5428 case WPA_KEY_MGMT_PSK_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005429 mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005430 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005431 case WPA_KEY_MGMT_OSEN:
Paul Stewart092955c2017-02-06 09:13:09 -08005432 mgmt = RSN_AUTH_KEY_MGMT_OSEN;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005433 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005434 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
Paul Stewart092955c2017-02-06 09:13:09 -08005435 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005436 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005437 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
Paul Stewart092955c2017-02-06 09:13:09 -08005438 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005439 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005440 case WPA_KEY_MGMT_FILS_SHA256:
5441 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256;
5442 break;
5443 case WPA_KEY_MGMT_FILS_SHA384:
5444 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384;
5445 break;
5446 case WPA_KEY_MGMT_FT_FILS_SHA256:
5447 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
5448 break;
5449 case WPA_KEY_MGMT_FT_FILS_SHA384:
5450 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
5451 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005452 case WPA_KEY_MGMT_OWE:
5453 mgmt = RSN_AUTH_KEY_MGMT_OWE;
5454 break;
5455 case WPA_KEY_MGMT_DPP:
5456 mgmt = RSN_AUTH_KEY_MGMT_DPP;
5457 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005458 case WPA_KEY_MGMT_PSK:
5459 default:
Paul Stewart092955c2017-02-06 09:13:09 -08005460 mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005461 break;
5462 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07005463 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005464 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
5465 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005466 }
5467
Roshan Pius3a1667e2018-07-03 15:17:14 -07005468 /* Add PSK in case of 4-way handshake offload */
5469 if (params->psk &&
5470 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) {
5471 wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32);
5472 if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk))
5473 return -1;
5474 }
5475
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005476 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5477 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005478
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005479 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
5480 (params->pairwise_suite == WPA_CIPHER_NONE ||
5481 params->pairwise_suite == WPA_CIPHER_WEP104 ||
5482 params->pairwise_suite == WPA_CIPHER_WEP40) &&
5483 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
5484 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
5485 return -1;
5486
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005487 if (params->rrm_used) {
5488 u32 drv_rrm_flags = drv->capa.rrm_flags;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005489 if ((!((drv_rrm_flags &
5490 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) &&
5491 (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) &&
5492 !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005493 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
5494 return -1;
5495 }
5496
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005497 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005498 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005499
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005500 if (params->p2p)
5501 wpa_printf(MSG_DEBUG, " * P2P group");
5502
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005503 if (params->pbss) {
5504 wpa_printf(MSG_DEBUG, " * PBSS");
5505 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
5506 return -1;
5507 }
5508
Dmitry Shmidte4663042016-04-04 10:07:49 -07005509 drv->connect_reassoc = 0;
5510 if (params->prev_bssid) {
5511 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
5512 MAC2STR(params->prev_bssid));
5513 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
5514 params->prev_bssid))
5515 return -1;
5516 drv->connect_reassoc = 1;
5517 }
5518
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005519 if ((params->auth_alg & WPA_AUTH_ALG_FILS) &&
5520 nl80211_put_fils_connect_params(drv, params, msg) != 0)
5521 return -1;
5522
Roshan Pius3a1667e2018-07-03 15:17:14 -07005523 if ((params->auth_alg & WPA_AUTH_ALG_SAE) &&
5524 (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) &&
5525 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
5526 return -1;
5527
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005528 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005529}
5530
5531
5532static int wpa_driver_nl80211_try_connect(
5533 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005534 struct wpa_driver_associate_params *params,
5535 struct nl_handle *nl_connect)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005536{
5537 struct nl_msg *msg;
5538 enum nl80211_auth_type type;
5539 int ret;
5540 int algs;
5541
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005542#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005543 if (params->req_key_mgmt_offload && params->psk &&
5544 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5545 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
5546 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
5547 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
5548 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
5549 if (ret)
5550 return ret;
5551 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005552#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005553
5554 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
5555 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005556 if (!msg)
5557 return -1;
5558
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005559 ret = nl80211_connect_common(drv, params, msg);
5560 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005561 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005562
Roshan Pius3a1667e2018-07-03 15:17:14 -07005563 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5564 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5565 goto fail;
5566
5567 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL &&
5568 (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) &&
5569 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL))
5570 goto fail;
5571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005572 algs = 0;
5573 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
5574 algs++;
5575 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
5576 algs++;
5577 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
5578 algs++;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005579 if (params->auth_alg & WPA_AUTH_ALG_FILS)
5580 algs++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005581 if (params->auth_alg & WPA_AUTH_ALG_FT)
5582 algs++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005583 if (algs > 1) {
5584 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
5585 "selection");
5586 goto skip_auth_type;
5587 }
5588
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005589 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005590 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005591 if (type == NL80211_AUTHTYPE_MAX ||
5592 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005593 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005594
5595skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005596 ret = nl80211_set_conn_keys(params, msg);
5597 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005598 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005599
Roshan Pius3a1667e2018-07-03 15:17:14 -07005600 if (nl_connect)
5601 ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL);
5602 else
5603 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5604
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005605 msg = NULL;
5606 if (ret) {
5607 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
5608 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005609 } else {
5610 wpa_printf(MSG_DEBUG,
5611 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005612 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005613
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005614fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005615 nlmsg_free(msg);
5616 return ret;
5617
5618}
5619
5620
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005621static int wpa_driver_nl80211_connect(
5622 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005623 struct wpa_driver_associate_params *params,
5624 struct nl_handle *nl_connect)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005625{
Jithu Jancea7c60b42014-12-03 18:54:40 +05305626 int ret;
5627
5628 /* Store the connection attempted bssid for future use */
5629 if (params->bssid)
5630 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
5631 else
5632 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
5633
Roshan Pius3a1667e2018-07-03 15:17:14 -07005634 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005635 if (ret == -EALREADY) {
5636 /*
5637 * cfg80211 does not currently accept new connections if
5638 * we are already connected. As a workaround, force
5639 * disconnection and try again.
5640 */
5641 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
5642 "disconnecting before reassociation "
5643 "attempt");
5644 if (wpa_driver_nl80211_disconnect(
5645 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
5646 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005647 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005648 }
5649 return ret;
5650}
5651
5652
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653static int wpa_driver_nl80211_associate(
5654 void *priv, struct wpa_driver_associate_params *params)
5655{
5656 struct i802_bss *bss = priv;
5657 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005658 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005659 struct nl_msg *msg;
5660
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005661 nl80211_unmask_11b_rates(bss);
5662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005663 if (params->mode == IEEE80211_MODE_AP)
5664 return wpa_driver_nl80211_ap(drv, params);
5665
5666 if (params->mode == IEEE80211_MODE_IBSS)
5667 return wpa_driver_nl80211_ibss(drv, params);
5668
5669 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005670 enum nl80211_iftype nlmode = params->p2p ?
5671 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005672 struct nl_handle *nl_connect = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005673
5674 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005675 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005676 if (params->auth_alg & WPA_AUTH_ALG_SAE)
5677 nl_connect = bss->nl_connect;
5678 return wpa_driver_nl80211_connect(drv, params, nl_connect);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005679 }
5680
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005681 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005682
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005683 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
5684 drv->ifindex);
5685 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005686 if (!msg)
5687 return -1;
5688
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005689 ret = nl80211_connect_common(drv, params, msg);
5690 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005691 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692
Roshan Pius3a1667e2018-07-03 15:17:14 -07005693 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5694 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5695 goto fail;
5696
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005697 if (params->fils_kek) {
5698 wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)",
5699 (unsigned int) params->fils_kek_len);
5700 if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len,
5701 params->fils_kek))
5702 goto fail;
5703 }
5704 if (params->fils_nonces) {
5705 wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)",
5706 params->fils_nonces,
5707 params->fils_nonces_len);
5708 if (nla_put(msg, NL80211_ATTR_FILS_NONCES,
5709 params->fils_nonces_len, params->fils_nonces))
5710 goto fail;
5711 }
5712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005713 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5714 msg = NULL;
5715 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005716 wpa_dbg(drv->ctx, MSG_DEBUG,
5717 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5718 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005719 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005720 } else {
5721 wpa_printf(MSG_DEBUG,
5722 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005723 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005724
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005725fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005726 nlmsg_free(msg);
5727 return ret;
5728}
5729
5730
5731static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005732 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005733{
5734 struct nl_msg *msg;
5735 int ret = -ENOBUFS;
5736
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005737 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
5738 ifindex, mode, nl80211_iftype_str(mode));
5739
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005740 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
5741 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
5742 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005743
5744 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005745 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005746 if (!ret)
5747 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005748fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005749 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005750 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
5751 " %d (%s)", ifindex, mode, ret, strerror(-ret));
5752 return ret;
5753}
5754
5755
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005756static int wpa_driver_nl80211_set_mode_impl(
5757 struct i802_bss *bss,
5758 enum nl80211_iftype nlmode,
5759 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005760{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005761 struct wpa_driver_nl80211_data *drv = bss->drv;
5762 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005763 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005764 int was_ap = is_ap_interface(drv->nlmode);
5765 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005766 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005767
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005768 if (TEST_FAIL())
5769 return -1;
5770
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005771 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5772 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
5773 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005774
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005775 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005776 drv->nlmode = nlmode;
5777 ret = 0;
5778 goto done;
5779 }
5780
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005781 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005782 return -1;
5783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005784 if (nlmode == drv->nlmode) {
5785 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
5786 "requested mode - ignore error");
5787 ret = 0;
5788 goto done; /* Already in the requested mode */
5789 }
5790
5791 /* mac80211 doesn't allow mode changes while the device is up, so
5792 * take the device down, try to set the mode again, and bring the
5793 * device back up.
5794 */
5795 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
5796 "interface down");
5797 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005798 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005799 if (res == -EACCES || res == -ENODEV)
5800 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005801 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005802 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
5803 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005804 os_sleep(0, 100000);
5805 continue;
5806 }
5807
5808 /*
5809 * Setting the mode will fail for some drivers if the phy is
5810 * on a frequency that the mode is disallowed in.
5811 */
5812 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005813 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005814 if (res) {
5815 wpa_printf(MSG_DEBUG,
5816 "nl80211: Failed to set frequency on interface");
5817 }
5818 }
5819
5820 /* Try to set the mode again while the interface is down */
5821 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5822 if (mode_switch_res == -EBUSY) {
5823 wpa_printf(MSG_DEBUG,
5824 "nl80211: Delaying mode set while interface going down");
5825 os_sleep(0, 100000);
5826 continue;
5827 }
5828 ret = mode_switch_res;
5829 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005830 }
5831
5832 if (!ret) {
5833 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
5834 "interface is down");
5835 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005836 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005837 }
5838
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005839 /* Bring the interface back up */
5840 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
5841 if (res != 0) {
5842 wpa_printf(MSG_DEBUG,
5843 "nl80211: Failed to set interface up after switching mode");
5844 ret = -1;
5845 }
5846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005847done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005848 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005849 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
5850 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005851 return ret;
5852 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005853
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005854 if (is_p2p_net_interface(nlmode)) {
5855 wpa_printf(MSG_DEBUG,
5856 "nl80211: Interface %s mode change to P2P - disable 11b rates",
5857 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005858 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005859 } else if (drv->disabled_11b_rates) {
5860 wpa_printf(MSG_DEBUG,
5861 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
5862 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005863 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005864 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005865
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005866 if (is_ap_interface(nlmode)) {
5867 nl80211_mgmt_unsubscribe(bss, "start AP");
5868 /* Setup additional AP mode functionality if needed */
5869 if (nl80211_setup_ap(bss))
5870 return -1;
5871 } else if (was_ap) {
5872 /* Remove additional AP mode functionality */
5873 nl80211_teardown_ap(bss);
5874 } else {
5875 nl80211_mgmt_unsubscribe(bss, "mode change");
5876 }
5877
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005878 if (is_mesh_interface(nlmode) &&
5879 nl80211_mgmt_subscribe_mesh(bss))
5880 return -1;
5881
Dmitry Shmidt04949592012-07-19 12:16:46 -07005882 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005883 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005884 nl80211_mgmt_subscribe_non_ap(bss) < 0)
5885 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
5886 "frame processing - ignore for now");
5887
5888 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005889}
5890
5891
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005892int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
5893 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005894{
5895 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
5896}
5897
5898
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005899static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
5900 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005901{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005902 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005903 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005904}
5905
5906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005907static int wpa_driver_nl80211_get_capa(void *priv,
5908 struct wpa_driver_capa *capa)
5909{
5910 struct i802_bss *bss = priv;
5911 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005913 if (!drv->has_capability)
5914 return -1;
5915 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005916 if (drv->extended_capa && drv->extended_capa_mask) {
5917 capa->extended_capa = drv->extended_capa;
5918 capa->extended_capa_mask = drv->extended_capa_mask;
5919 capa->extended_capa_len = drv->extended_capa_len;
5920 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005921
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005922 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005923}
5924
5925
5926static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5927{
5928 struct i802_bss *bss = priv;
5929 struct wpa_driver_nl80211_data *drv = bss->drv;
5930
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005931 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5932 bss->ifname, drv->operstate, state,
5933 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005935 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005936 state ? IF_OPER_UP : IF_OPER_DORMANT);
5937}
5938
5939
5940static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5941{
5942 struct i802_bss *bss = priv;
5943 struct wpa_driver_nl80211_data *drv = bss->drv;
5944 struct nl_msg *msg;
5945 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005946 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005947
5948 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5949 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5950 return 0;
5951 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005952
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005953 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5954 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5955
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005956 os_memset(&upd, 0, sizeof(upd));
5957 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5958 if (authorized)
5959 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005960
5961 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5962 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5963 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5964 nlmsg_free(msg);
5965 return -ENOBUFS;
5966 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005967
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005968 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005969 if (!ret)
5970 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005971 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5972 ret, strerror(-ret));
5973 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974}
5975
5976
Jouni Malinen75ecf522011-06-27 15:19:46 -07005977/* Set kernel driver on given frequency (MHz) */
5978static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005979{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005980 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005981 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005982}
5983
5984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005985static inline int min_int(int a, int b)
5986{
5987 if (a < b)
5988 return a;
5989 return b;
5990}
5991
5992
5993static int get_key_handler(struct nl_msg *msg, void *arg)
5994{
5995 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5996 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5997
5998 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5999 genlmsg_attrlen(gnlh, 0), NULL);
6000
6001 /*
6002 * TODO: validate the key index and mac address!
6003 * Otherwise, there's a race condition as soon as
6004 * the kernel starts sending key notifications.
6005 */
6006
6007 if (tb[NL80211_ATTR_KEY_SEQ])
6008 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
6009 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
6010 return NL_SKIP;
6011}
6012
6013
6014static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
6015 int idx, u8 *seq)
6016{
6017 struct i802_bss *bss = priv;
6018 struct wpa_driver_nl80211_data *drv = bss->drv;
6019 struct nl_msg *msg;
6020
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006021 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
6022 NL80211_CMD_GET_KEY);
6023 if (!msg ||
6024 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
6025 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
6026 nlmsg_free(msg);
6027 return -ENOBUFS;
6028 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006029
6030 memset(seq, 0, 6);
6031
6032 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006033}
6034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035
6036static int i802_set_rts(void *priv, int rts)
6037{
6038 struct i802_bss *bss = priv;
6039 struct wpa_driver_nl80211_data *drv = bss->drv;
6040 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006041 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006042 u32 val;
6043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006044 if (rts >= 2347)
6045 val = (u32) -1;
6046 else
6047 val = rts;
6048
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006049 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6050 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6051 nlmsg_free(msg);
6052 return -ENOBUFS;
6053 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006054
6055 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6056 if (!ret)
6057 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006058 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
6059 "%d (%s)", rts, ret, strerror(-ret));
6060 return ret;
6061}
6062
6063
6064static int i802_set_frag(void *priv, int frag)
6065{
6066 struct i802_bss *bss = priv;
6067 struct wpa_driver_nl80211_data *drv = bss->drv;
6068 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006069 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006070 u32 val;
6071
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006072 if (frag >= 2346)
6073 val = (u32) -1;
6074 else
6075 val = frag;
6076
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006077 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6078 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
6079 nlmsg_free(msg);
6080 return -ENOBUFS;
6081 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006082
6083 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6084 if (!ret)
6085 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006086 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
6087 "%d: %d (%s)", frag, ret, strerror(-ret));
6088 return ret;
6089}
6090
6091
6092static int i802_flush(void *priv)
6093{
6094 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006095 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006096 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006097
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006098 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
6099 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006100
6101 /*
6102 * XXX: FIX! this needs to flush all VLANs too
6103 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006104 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
6105 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006106 if (res) {
6107 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
6108 "(%s)", res, strerror(-res));
6109 }
6110 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006111}
6112
6113
6114static int get_sta_handler(struct nl_msg *msg, void *arg)
6115{
6116 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6117 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6118 struct hostap_sta_driver_data *data = arg;
6119 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
6120 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
6121 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
6122 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
6123 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
6124 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
6125 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006126 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006127 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
6128 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006129 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Roshan Pius3a1667e2018-07-03 15:17:14 -07006130 [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006131 };
6132 struct nlattr *rate[NL80211_RATE_INFO_MAX + 1];
6133 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
6134 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
6135 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
6136 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
6137 [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 },
6138 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
6139 [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006140 };
6141
6142 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6143 genlmsg_attrlen(gnlh, 0), NULL);
6144
6145 /*
6146 * TODO: validate the interface and mac address!
6147 * Otherwise, there's a race condition as soon as
6148 * the kernel starts sending station notifications.
6149 */
6150
6151 if (!tb[NL80211_ATTR_STA_INFO]) {
6152 wpa_printf(MSG_DEBUG, "sta stats missing!");
6153 return NL_SKIP;
6154 }
6155 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
6156 tb[NL80211_ATTR_STA_INFO],
6157 stats_policy)) {
6158 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
6159 return NL_SKIP;
6160 }
6161
6162 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
6163 data->inactive_msec =
6164 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006165 /* For backwards compatibility, fetch the 32-bit counters first. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006166 if (stats[NL80211_STA_INFO_RX_BYTES])
6167 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
6168 if (stats[NL80211_STA_INFO_TX_BYTES])
6169 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006170 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
6171 stats[NL80211_STA_INFO_TX_BYTES64]) {
6172 /*
6173 * The driver supports 64-bit counters, so use them to override
6174 * the 32-bit values.
6175 */
6176 data->rx_bytes =
6177 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
6178 data->tx_bytes =
6179 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
6180 data->bytes_64bit = 1;
6181 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006182 if (stats[NL80211_STA_INFO_RX_PACKETS])
6183 data->rx_packets =
6184 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
6185 if (stats[NL80211_STA_INFO_TX_PACKETS])
6186 data->tx_packets =
6187 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006188 if (stats[NL80211_STA_INFO_TX_FAILED])
6189 data->tx_retry_failed =
6190 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006191 if (stats[NL80211_STA_INFO_SIGNAL])
6192 data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006193 if (stats[NL80211_STA_INFO_ACK_SIGNAL]) {
6194 data->last_ack_rssi =
6195 nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]);
6196 data->flags |= STA_DRV_DATA_LAST_ACK_RSSI;
6197 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006198
6199 if (stats[NL80211_STA_INFO_TX_BITRATE] &&
6200 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6201 stats[NL80211_STA_INFO_TX_BITRATE],
6202 rate_policy) == 0) {
6203 if (rate[NL80211_RATE_INFO_BITRATE32])
6204 data->current_tx_rate =
6205 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6206 else if (rate[NL80211_RATE_INFO_BITRATE])
6207 data->current_tx_rate =
6208 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6209
6210 if (rate[NL80211_RATE_INFO_MCS]) {
6211 data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6212 data->flags |= STA_DRV_DATA_TX_MCS;
6213 }
6214 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6215 data->tx_vhtmcs =
6216 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6217 data->flags |= STA_DRV_DATA_TX_VHT_MCS;
6218 }
6219 if (rate[NL80211_RATE_INFO_SHORT_GI])
6220 data->flags |= STA_DRV_DATA_TX_SHORT_GI;
6221 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6222 data->tx_vht_nss =
6223 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6224 data->flags |= STA_DRV_DATA_TX_VHT_NSS;
6225 }
6226 }
6227
6228 if (stats[NL80211_STA_INFO_RX_BITRATE] &&
6229 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6230 stats[NL80211_STA_INFO_RX_BITRATE],
6231 rate_policy) == 0) {
6232 if (rate[NL80211_RATE_INFO_BITRATE32])
6233 data->current_rx_rate =
6234 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6235 else if (rate[NL80211_RATE_INFO_BITRATE])
6236 data->current_rx_rate =
6237 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6238
6239 if (rate[NL80211_RATE_INFO_MCS]) {
6240 data->rx_mcs =
6241 nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6242 data->flags |= STA_DRV_DATA_RX_MCS;
6243 }
6244 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6245 data->rx_vhtmcs =
6246 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6247 data->flags |= STA_DRV_DATA_RX_VHT_MCS;
6248 }
6249 if (rate[NL80211_RATE_INFO_SHORT_GI])
6250 data->flags |= STA_DRV_DATA_RX_SHORT_GI;
6251 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6252 data->rx_vht_nss =
6253 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6254 data->flags |= STA_DRV_DATA_RX_VHT_NSS;
6255 }
6256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006257
6258 return NL_SKIP;
6259}
6260
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006261static int i802_read_sta_data(struct i802_bss *bss,
6262 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006263 const u8 *addr)
6264{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006265 struct nl_msg *msg;
6266
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006267 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
6268 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6269 nlmsg_free(msg);
6270 return -ENOBUFS;
6271 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006272
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006273 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006274}
6275
6276
6277static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
6278 int cw_min, int cw_max, int burst_time)
6279{
6280 struct i802_bss *bss = priv;
6281 struct wpa_driver_nl80211_data *drv = bss->drv;
6282 struct nl_msg *msg;
6283 struct nlattr *txq, *params;
6284
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006285 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006286 if (!msg)
6287 return -1;
6288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006289 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
6290 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006291 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006292
6293 /* We are only sending parameters for a single TXQ at a time */
6294 params = nla_nest_start(msg, 1);
6295 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006296 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006297
6298 switch (queue) {
6299 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006300 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
6301 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302 break;
6303 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006304 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
6305 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006306 break;
6307 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006308 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
6309 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310 break;
6311 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006312 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
6313 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006314 break;
6315 }
6316 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6317 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006318 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
6319 (burst_time * 100 + 16) / 32) ||
6320 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
6321 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
6322 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
6323 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006324
6325 nla_nest_end(msg, params);
6326
6327 nla_nest_end(msg, txq);
6328
6329 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
6330 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006331 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006332fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006333 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006334 return -1;
6335}
6336
6337
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006338static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006339 const char *ifname, int vlan_id)
6340{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006341 struct wpa_driver_nl80211_data *drv = bss->drv;
6342 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006343 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006344
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006345 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6346 ", ifname=%s[%d], vlan_id=%d)",
6347 bss->ifname, if_nametoindex(bss->ifname),
6348 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006349 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6350 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
6351 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
6352 nlmsg_free(msg);
6353 return -ENOBUFS;
6354 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006355
6356 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6357 if (ret < 0) {
6358 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6359 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
6360 MAC2STR(addr), ifname, vlan_id, ret,
6361 strerror(-ret));
6362 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006363 return ret;
6364}
6365
6366
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006367static int i802_get_inact_sec(void *priv, const u8 *addr)
6368{
6369 struct hostap_sta_driver_data data;
6370 int ret;
6371
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08006372 os_memset(&data, 0, sizeof(data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006373 data.inactive_msec = (unsigned long) -1;
6374 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006375 if (ret == -ENOENT)
6376 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006377 if (ret || data.inactive_msec == (unsigned long) -1)
6378 return -1;
6379 return data.inactive_msec / 1000;
6380}
6381
6382
6383static int i802_sta_clear_stats(void *priv, const u8 *addr)
6384{
6385#if 0
6386 /* TODO */
6387#endif
6388 return 0;
6389}
6390
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006391
6392static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
6393 int reason)
6394{
6395 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006396 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006397 struct ieee80211_mgmt mgmt;
Dmitry Shmidt29333592017-01-09 12:27:11 -08006398 u8 channel;
6399
6400 if (ieee80211_freq_to_chan(bss->freq, &channel) ==
6401 HOSTAPD_MODE_IEEE80211AD) {
6402 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6403 * disassociate the STA instead. */
6404 return i802_sta_disassoc(priv, own_addr, addr, reason);
6405 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006406
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006407 if (is_mesh_interface(drv->nlmode))
6408 return -1;
6409
Dmitry Shmidt04949592012-07-19 12:16:46 -07006410 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006411 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006413 memset(&mgmt, 0, sizeof(mgmt));
6414 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6415 WLAN_FC_STYPE_DEAUTH);
6416 memcpy(mgmt.da, addr, ETH_ALEN);
6417 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6418 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6419 mgmt.u.deauth.reason_code = host_to_le16(reason);
6420 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6421 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006422 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006423 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006424}
6425
6426
6427static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
6428 int reason)
6429{
6430 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006431 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006432 struct ieee80211_mgmt mgmt;
6433
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006434 if (is_mesh_interface(drv->nlmode))
6435 return -1;
6436
Dmitry Shmidt04949592012-07-19 12:16:46 -07006437 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006438 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006439
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006440 memset(&mgmt, 0, sizeof(mgmt));
6441 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6442 WLAN_FC_STYPE_DISASSOC);
6443 memcpy(mgmt.da, addr, ETH_ALEN);
6444 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6445 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6446 mgmt.u.disassoc.reason_code = host_to_le16(reason);
6447 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6448 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006449 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006450 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006451}
6452
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006453
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006454static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
6455{
6456 char buf[200], *pos, *end;
6457 int i, res;
6458
6459 pos = buf;
6460 end = pos + sizeof(buf);
6461
6462 for (i = 0; i < drv->num_if_indices; i++) {
6463 if (!drv->if_indices[i])
6464 continue;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006465 res = os_snprintf(pos, end - pos, " %d(%d)",
6466 drv->if_indices[i],
6467 drv->if_indices_reason[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006468 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006469 break;
6470 pos += res;
6471 }
6472 *pos = '\0';
6473
6474 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
6475 drv->num_if_indices, buf);
6476}
6477
6478
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006479static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6480 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006481{
6482 int i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006483 int *old, *old_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006484
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006485 wpa_printf(MSG_DEBUG,
6486 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6487 ifidx, ifidx_reason);
6488 if (have_ifidx(drv, ifidx, ifidx_reason)) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006489 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
6490 ifidx);
6491 return;
6492 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006493 for (i = 0; i < drv->num_if_indices; i++) {
6494 if (drv->if_indices[i] == 0) {
6495 drv->if_indices[i] = ifidx;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006496 drv->if_indices_reason[i] = ifidx_reason;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006497 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006498 return;
6499 }
6500 }
6501
6502 if (drv->if_indices != drv->default_if_indices)
6503 old = drv->if_indices;
6504 else
6505 old = NULL;
6506
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006507 if (drv->if_indices_reason != drv->default_if_indices_reason)
6508 old_reason = drv->if_indices_reason;
6509 else
6510 old_reason = NULL;
6511
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006512 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
6513 sizeof(int));
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006514 drv->if_indices_reason = os_realloc_array(old_reason,
6515 drv->num_if_indices + 1,
6516 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006517 if (!drv->if_indices) {
6518 if (!old)
6519 drv->if_indices = drv->default_if_indices;
6520 else
6521 drv->if_indices = old;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006522 }
6523 if (!drv->if_indices_reason) {
6524 if (!old_reason)
6525 drv->if_indices_reason = drv->default_if_indices_reason;
6526 else
Dmitry Shmidte4663042016-04-04 10:07:49 -07006527 drv->if_indices_reason = old_reason;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006528 }
6529 if (!drv->if_indices || !drv->if_indices_reason) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07006530 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
6531 "interfaces");
6532 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
6533 return;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006534 }
6535 if (!old)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006536 os_memcpy(drv->if_indices, drv->default_if_indices,
6537 sizeof(drv->default_if_indices));
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006538 if (!old_reason)
6539 os_memcpy(drv->if_indices_reason,
6540 drv->default_if_indices_reason,
6541 sizeof(drv->default_if_indices_reason));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006542 drv->if_indices[drv->num_if_indices] = ifidx;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006543 drv->if_indices_reason[drv->num_if_indices] = ifidx_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006544 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006545 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006546}
6547
6548
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006549static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6550 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006551{
6552 int i;
6553
6554 for (i = 0; i < drv->num_if_indices; i++) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006555 if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) &&
6556 (drv->if_indices_reason[i] == ifidx_reason ||
6557 ifidx_reason == IFIDX_ANY)) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07006558 drv->if_indices[i] = 0;
6559 break;
6560 }
6561 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006562 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006563}
6564
6565
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006566static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6567 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006568{
6569 int i;
6570
6571 for (i = 0; i < drv->num_if_indices; i++)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006572 if (drv->if_indices[i] == ifidx &&
6573 (drv->if_indices_reason[i] == ifidx_reason ||
6574 ifidx_reason == IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07006575 return 1;
6576
6577 return 0;
6578}
6579
6580
6581static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006582 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006583{
6584 struct i802_bss *bss = priv;
6585 struct wpa_driver_nl80211_data *drv = bss->drv;
6586 char name[IFNAMSIZ + 1];
Roshan Pius3a1667e2018-07-03 15:17:14 -07006587 union wpa_event_data event;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006588 int ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006589
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006590 ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
6591 if (ret >= (int) sizeof(name))
6592 wpa_printf(MSG_WARNING,
6593 "nl80211: WDS interface name was truncated");
6594 else if (ret < 0)
6595 return ret;
6596
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006597 if (ifname_wds)
6598 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
6599
Jouni Malinen75ecf522011-06-27 15:19:46 -07006600 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
6601 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
6602 if (val) {
6603 if (!if_nametoindex(name)) {
6604 if (nl80211_create_iface(drv, name,
6605 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006606 bss->addr, 1, NULL, NULL, 0) <
6607 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006608 return -1;
6609 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006610 linux_br_add_if(drv->global->ioctl_sock,
6611 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006612 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006613
6614 os_memset(&event, 0, sizeof(event));
6615 event.wds_sta_interface.sta_addr = addr;
6616 event.wds_sta_interface.ifname = name;
6617 event.wds_sta_interface.istatus = INTERFACE_ADDED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07006618 wpa_supplicant_event(bss->ctx,
Roshan Pius3a1667e2018-07-03 15:17:14 -07006619 EVENT_WDS_STA_INTERFACE_STATUS,
6620 &event);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006621 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006622 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
6623 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
6624 "interface %s up", name);
6625 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006626 return i802_set_sta_vlan(priv, addr, name, 0);
6627 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006628 if (bridge_ifname)
6629 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
6630 name);
6631
Jouni Malinen75ecf522011-06-27 15:19:46 -07006632 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08006633 nl80211_remove_iface(drv, if_nametoindex(name));
Roshan Pius3a1667e2018-07-03 15:17:14 -07006634 os_memset(&event, 0, sizeof(event));
6635 event.wds_sta_interface.sta_addr = addr;
6636 event.wds_sta_interface.ifname = name;
6637 event.wds_sta_interface.istatus = INTERFACE_REMOVED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07006638 wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS,
Roshan Pius3a1667e2018-07-03 15:17:14 -07006639 &event);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08006640 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006641 }
6642}
6643
6644
6645static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
6646{
6647 struct wpa_driver_nl80211_data *drv = eloop_ctx;
6648 struct sockaddr_ll lladdr;
6649 unsigned char buf[3000];
6650 int len;
6651 socklen_t fromlen = sizeof(lladdr);
6652
6653 len = recvfrom(sock, buf, sizeof(buf), 0,
6654 (struct sockaddr *)&lladdr, &fromlen);
6655 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006656 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
6657 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006658 return;
6659 }
6660
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006661 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07006662 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
6663}
6664
6665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006666static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
6667 struct i802_bss *bss,
6668 const char *brname, const char *ifname)
6669{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006670 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006671 char in_br[IFNAMSIZ];
6672
6673 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006674 br_ifindex = if_nametoindex(brname);
6675 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006676 /*
6677 * Bridge was configured, but the bridge device does
6678 * not exist. Try to add it now.
6679 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006680 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006681 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
6682 "bridge interface %s: %s",
6683 brname, strerror(errno));
6684 return -1;
6685 }
6686 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006687 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006688 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006689 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006690 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006691
6692 if (linux_br_get(in_br, ifname) == 0) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07006693 if (os_strcmp(in_br, brname) == 0) {
6694 bss->already_in_bridge = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006695 return 0; /* already in the bridge */
Hai Shalomc9e41a12018-07-31 14:41:42 -07006696 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006697
6698 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
6699 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006700 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
6701 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006702 wpa_printf(MSG_ERROR, "nl80211: Failed to "
6703 "remove interface %s from bridge "
6704 "%s: %s",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006705 ifname, in_br, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006706 return -1;
6707 }
6708 }
6709
6710 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
6711 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006712 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006713 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
6714 "into bridge %s: %s",
6715 ifname, brname, strerror(errno));
6716 return -1;
6717 }
6718 bss->added_if_into_bridge = 1;
6719
6720 return 0;
6721}
6722
6723
6724static void *i802_init(struct hostapd_data *hapd,
6725 struct wpa_init_params *params)
6726{
6727 struct wpa_driver_nl80211_data *drv;
6728 struct i802_bss *bss;
6729 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006730 char master_ifname[IFNAMSIZ];
6731 int ifindex, br_ifindex = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006732 int br_added = 0;
6733
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08006734 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
6735 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006736 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006737 if (bss == NULL)
6738 return NULL;
6739
6740 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006741
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006742 if (linux_br_get(master_ifname, params->ifname) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006743 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006744 params->ifname, master_ifname);
6745 br_ifindex = if_nametoindex(master_ifname);
6746 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
6747 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
6748 linux_master_get(master_ifname, params->ifname) == 0) {
6749 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
6750 params->ifname, master_ifname);
6751 /* start listening for EAPOL on the master interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006752 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006753
6754 /* check if master itself is under bridge */
6755 if (linux_br_get(master_ifname, master_ifname) == 0) {
6756 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
6757 master_ifname);
6758 br_ifindex = if_nametoindex(master_ifname);
6759 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
6760 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006761 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006762 master_ifname[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006763 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006765 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006767 for (i = 0; i < params->num_bridge; i++) {
6768 if (params->bridge[i]) {
6769 ifindex = if_nametoindex(params->bridge[i]);
6770 if (ifindex)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006771 add_ifidx(drv, ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006772 if (ifindex == br_ifindex)
6773 br_added = 1;
6774 }
6775 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006776
6777 /* start listening for EAPOL on the default AP interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006778 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006779
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006780 if (params->num_bridge && params->bridge[0]) {
6781 if (i802_check_bridge(drv, bss, params->bridge[0],
6782 params->ifname) < 0)
6783 goto failed;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006784 if (os_strcmp(params->bridge[0], master_ifname) != 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006785 br_added = 1;
6786 }
6787
6788 if (!br_added && br_ifindex &&
6789 (params->num_bridge == 0 || !params->bridge[0]))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006790 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006791
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006792#ifdef CONFIG_LIBNL3_ROUTE
Hai Shalomc9e41a12018-07-31 14:41:42 -07006793 if (bss->added_if_into_bridge || bss->already_in_bridge) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006794 drv->rtnl_sk = nl_socket_alloc();
6795 if (drv->rtnl_sk == NULL) {
6796 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
6797 goto failed;
6798 }
6799
6800 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
6801 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
6802 strerror(errno));
6803 goto failed;
6804 }
6805 }
6806#endif /* CONFIG_LIBNL3_ROUTE */
6807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006808 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
6809 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006810 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
6811 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006812 goto failed;
6813 }
6814
6815 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
6816 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006817 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006818 goto failed;
6819 }
6820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006821 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
6822 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006823 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006824 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006825
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006826 memcpy(bss->addr, params->own_addr, ETH_ALEN);
6827
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006828 return bss;
6829
6830failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006831 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006832 return NULL;
6833}
6834
6835
6836static void i802_deinit(void *priv)
6837{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006838 struct i802_bss *bss = priv;
6839 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006840}
6841
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006842
6843static enum nl80211_iftype wpa_driver_nl80211_if_type(
6844 enum wpa_driver_if_type type)
6845{
6846 switch (type) {
6847 case WPA_IF_STATION:
6848 return NL80211_IFTYPE_STATION;
6849 case WPA_IF_P2P_CLIENT:
6850 case WPA_IF_P2P_GROUP:
6851 return NL80211_IFTYPE_P2P_CLIENT;
6852 case WPA_IF_AP_VLAN:
6853 return NL80211_IFTYPE_AP_VLAN;
6854 case WPA_IF_AP_BSS:
6855 return NL80211_IFTYPE_AP;
6856 case WPA_IF_P2P_GO:
6857 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006858 case WPA_IF_P2P_DEVICE:
6859 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006860 case WPA_IF_MESH:
6861 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006862 default:
6863 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006864 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006865}
6866
6867
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006868static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
6869{
6870 struct wpa_driver_nl80211_data *drv;
6871 dl_list_for_each(drv, &global->interfaces,
6872 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006873 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006874 return 1;
6875 }
6876 return 0;
6877}
6878
6879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006880static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006881{
6882 unsigned int idx;
6883
6884 if (!drv->global)
6885 return -1;
6886
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006887 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006888 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006889 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006890 new_addr[0] ^= idx << 2;
6891 if (!nl80211_addr_in_use(drv->global, new_addr))
6892 break;
6893 }
6894 if (idx == 64)
6895 return -1;
6896
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006897 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006898 MACSTR, MAC2STR(new_addr));
6899
6900 return 0;
6901}
6902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006903
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006904struct wdev_info {
6905 u64 wdev_id;
6906 int wdev_id_set;
6907 u8 macaddr[ETH_ALEN];
6908};
6909
6910static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
6911{
6912 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6913 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6914 struct wdev_info *wi = arg;
6915
6916 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6917 genlmsg_attrlen(gnlh, 0), NULL);
6918 if (tb[NL80211_ATTR_WDEV]) {
6919 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
6920 wi->wdev_id_set = 1;
6921 }
6922
6923 if (tb[NL80211_ATTR_MAC])
6924 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
6925 ETH_ALEN);
6926
6927 return NL_SKIP;
6928}
6929
6930
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006931static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
6932 const char *ifname, const u8 *addr,
6933 void *bss_ctx, void **drv_priv,
6934 char *force_ifname, u8 *if_addr,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006935 const char *bridge, int use_existing,
6936 int setup_ap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006937{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006938 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006939 struct i802_bss *bss = priv;
6940 struct wpa_driver_nl80211_data *drv = bss->drv;
6941 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006942 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006943
6944 if (addr)
6945 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006946 nlmode = wpa_driver_nl80211_if_type(type);
6947 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
6948 struct wdev_info p2pdev_info;
6949
6950 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
6951 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
6952 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006953 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006954 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
6955 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
6956 ifname);
6957 return -1;
6958 }
6959
6960 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
6961 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
6962 if (!is_zero_ether_addr(p2pdev_info.macaddr))
6963 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
6964 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
6965 ifname,
6966 (long long unsigned int) p2pdev_info.wdev_id);
6967 } else {
6968 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006969 0, NULL, NULL, use_existing);
6970 if (use_existing && ifidx == -ENFILE) {
6971 added = 0;
6972 ifidx = if_nametoindex(ifname);
6973 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006974 return -1;
6975 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006976 }
6977
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006978 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006979 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006980 os_memcpy(if_addr, bss->addr, ETH_ALEN);
6981 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006982 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006983 if (added)
6984 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006985 return -1;
6986 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006987 }
6988
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006989 if (!addr &&
6990 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006991 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
6992 type == WPA_IF_STATION)) {
6993 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006994 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006995
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006996 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006997 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07006998 if (added)
6999 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007000 return -1;
7001 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007002 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007003 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007004 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007005 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007006 if (added)
7007 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007008 return -1;
7009 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007010 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007011 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007012 if (added)
7013 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007014 return -1;
7015 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007016 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007017 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007018 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007019
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007020 if (type == WPA_IF_AP_BSS && setup_ap) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007021 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
7022 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007023 if (added)
7024 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007025 return -1;
7026 }
7027
7028 if (bridge &&
7029 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
7030 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
7031 "interface %s to a bridge %s",
7032 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007033 if (added)
7034 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007035 os_free(new_bss);
7036 return -1;
7037 }
7038
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007039 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
7040 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007041 if (added)
7042 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007043 os_free(new_bss);
7044 return -1;
7045 }
7046 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007047 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007048 new_bss->ifindex = ifidx;
7049 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007050 new_bss->next = drv->first_bss->next;
7051 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007052 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007053 new_bss->added_if = added;
7054 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007055 if (drv_priv)
7056 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007057 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007058
7059 /* Subscribe management frames for this WPA_IF_AP_BSS */
7060 if (nl80211_setup_ap(new_bss))
7061 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007062 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007063
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007064 if (drv->global)
7065 drv->global->if_add_ifindex = ifidx;
7066
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007067 /*
7068 * Some virtual interfaces need to process EAPOL packets and events on
7069 * the parent interface. This is used mainly with hostapd.
7070 */
7071 if (ifidx > 0 &&
7072 (drv->hostapd ||
7073 nlmode == NL80211_IFTYPE_AP_VLAN ||
7074 nlmode == NL80211_IFTYPE_WDS ||
7075 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007076 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007077
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007078 return 0;
7079}
7080
7081
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007082static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007083 enum wpa_driver_if_type type,
7084 const char *ifname)
7085{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007086 struct wpa_driver_nl80211_data *drv = bss->drv;
7087 int ifindex = if_nametoindex(ifname);
7088
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007089 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
7090 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007091 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07007092 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007093 else if (ifindex > 0 && !bss->added_if) {
7094 struct wpa_driver_nl80211_data *drv2;
7095 dl_list_for_each(drv2, &drv->global->interfaces,
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007096 struct wpa_driver_nl80211_data, list) {
7097 del_ifidx(drv2, ifindex, IFIDX_ANY);
7098 del_ifidx(drv2, IFIDX_ANY, ifindex);
7099 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007100 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007101
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007102 if (type != WPA_IF_AP_BSS)
7103 return 0;
7104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007105 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007106 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
7107 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007108 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7109 "interface %s from bridge %s: %s",
7110 bss->ifname, bss->brname, strerror(errno));
7111 }
7112 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007113 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007114 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7115 "bridge %s: %s",
7116 bss->brname, strerror(errno));
7117 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007118
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007119 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007120 struct i802_bss *tbss;
7121
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007122 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
7123 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007124 if (tbss->next == bss) {
7125 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007126 /* Unsubscribe management frames */
7127 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007128 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007129 if (!bss->added_if)
7130 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007131 os_free(bss);
7132 bss = NULL;
7133 break;
7134 }
7135 }
7136 if (bss)
7137 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
7138 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007139 } else {
7140 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
7141 nl80211_teardown_ap(bss);
7142 if (!bss->added_if && !drv->first_bss->next)
Paul Stewart092955c2017-02-06 09:13:09 -08007143 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007144 nl80211_destroy_bss(bss);
7145 if (!bss->added_if)
7146 i802_set_iface_flags(bss, 0);
7147 if (drv->first_bss->next) {
7148 drv->first_bss = drv->first_bss->next;
7149 drv->ctx = drv->first_bss->ctx;
7150 os_free(bss);
7151 } else {
7152 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
7153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007154 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007155
7156 return 0;
7157}
7158
7159
7160static int cookie_handler(struct nl_msg *msg, void *arg)
7161{
7162 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7163 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7164 u64 *cookie = arg;
7165 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7166 genlmsg_attrlen(gnlh, 0), NULL);
7167 if (tb[NL80211_ATTR_COOKIE])
7168 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
7169 return NL_SKIP;
7170}
7171
7172
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007173static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007174 unsigned int freq, unsigned int wait,
7175 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007176 u64 *cookie_out, int no_cck, int no_ack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007177 int offchanok, const u16 *csa_offs,
7178 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007179{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007180 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007181 struct nl_msg *msg;
7182 u64 cookie;
7183 int ret = -1;
7184
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007185 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007186 "no_ack=%d offchanok=%d",
7187 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007188 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007189
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007190 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
7191 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
7192 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
7193 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7194 drv->test_use_roc_tx) &&
7195 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
7196 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
7197 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007198 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
7199 csa_offs_len * sizeof(u16), csa_offs)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007200 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
7201 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007202
7203 cookie = 0;
7204 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7205 msg = NULL;
7206 if (ret) {
7207 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007208 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
7209 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007210 } else {
7211 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
7212 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
7213 (long long unsigned int) cookie);
7214
7215 if (cookie_out)
7216 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007217
7218 if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) {
7219 wpa_printf(MSG_DEBUG,
7220 "nl80211: Drop oldest pending send action cookie 0x%llx",
7221 (long long unsigned int)
7222 drv->send_action_cookies[0]);
7223 os_memmove(&drv->send_action_cookies[0],
7224 &drv->send_action_cookies[1],
7225 (MAX_SEND_ACTION_COOKIES - 1) *
7226 sizeof(u64));
7227 drv->num_send_action_cookies--;
7228 }
7229 drv->send_action_cookies[drv->num_send_action_cookies] = cookie;
7230 drv->num_send_action_cookies++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007231 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007232
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007233fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007234 nlmsg_free(msg);
7235 return ret;
7236}
7237
7238
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007239static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
7240 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007241 unsigned int wait_time,
7242 const u8 *dst, const u8 *src,
7243 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007244 const u8 *data, size_t data_len,
7245 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007246{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007247 struct wpa_driver_nl80211_data *drv = bss->drv;
7248 int ret = -1;
7249 u8 *buf;
7250 struct ieee80211_hdr *hdr;
7251
7252 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007253 "freq=%u MHz wait=%d ms no_cck=%d)",
7254 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007255
7256 buf = os_zalloc(24 + data_len);
7257 if (buf == NULL)
7258 return ret;
7259 os_memcpy(buf + 24, data, data_len);
7260 hdr = (struct ieee80211_hdr *) buf;
7261 hdr->frame_control =
7262 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
7263 os_memcpy(hdr->addr1, dst, ETH_ALEN);
7264 os_memcpy(hdr->addr2, src, ETH_ALEN);
7265 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
7266
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007267 if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) {
7268 wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR,
7269 MAC2STR(src));
7270 os_memcpy(bss->rand_addr, src, ETH_ALEN);
7271 } else {
7272 os_memset(bss->rand_addr, 0, ETH_ALEN);
7273 }
7274
Dmitry Shmidt56052862013-10-04 10:23:25 -07007275 if (is_ap_interface(drv->nlmode) &&
7276 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7277 (int) freq == bss->freq || drv->device_ap_sme ||
7278 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007279 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
7280 0, freq, no_cck, 1,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007281 wait_time, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007282 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007283 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007284 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007285 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007286 no_cck, 0, 1, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007287
7288 os_free(buf);
7289 return ret;
7290}
7291
7292
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007293static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007294{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007295 struct wpa_driver_nl80211_data *drv = bss->drv;
7296 struct nl_msg *msg;
7297 int ret;
7298
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08007299 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007300 (long long unsigned int) cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007301 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007302 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007303 nlmsg_free(msg);
7304 return;
7305 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007306
7307 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007308 if (ret)
7309 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
7310 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007311}
7312
7313
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007314static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
7315{
7316 struct i802_bss *bss = priv;
7317 struct wpa_driver_nl80211_data *drv = bss->drv;
7318 unsigned int i;
7319 u64 cookie;
7320
7321 /* Cancel the last pending TX cookie */
7322 nl80211_frame_wait_cancel(bss, drv->send_action_cookie);
7323
7324 /*
7325 * Cancel the other pending TX cookies, if any. This is needed since
7326 * the driver may keep a list of all pending offchannel TX operations
7327 * and free up the radio only once they have expired or cancelled.
7328 */
7329 for (i = drv->num_send_action_cookies; i > 0; i--) {
7330 cookie = drv->send_action_cookies[i - 1];
7331 if (cookie != drv->send_action_cookie)
7332 nl80211_frame_wait_cancel(bss, cookie);
7333 }
7334 drv->num_send_action_cookies = 0;
7335}
7336
7337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007338static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
7339 unsigned int duration)
7340{
7341 struct i802_bss *bss = priv;
7342 struct wpa_driver_nl80211_data *drv = bss->drv;
7343 struct nl_msg *msg;
7344 int ret;
7345 u64 cookie;
7346
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007347 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
7348 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
7349 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
7350 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007351 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007352 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007353
7354 cookie = 0;
7355 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7356 if (ret == 0) {
7357 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
7358 "0x%llx for freq=%u MHz duration=%u",
7359 (long long unsigned int) cookie, freq, duration);
7360 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007361 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007362 return 0;
7363 }
7364 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
7365 "(freq=%d duration=%u): %d (%s)",
7366 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007367 return -1;
7368}
7369
7370
7371static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
7372{
7373 struct i802_bss *bss = priv;
7374 struct wpa_driver_nl80211_data *drv = bss->drv;
7375 struct nl_msg *msg;
7376 int ret;
7377
7378 if (!drv->pending_remain_on_chan) {
7379 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
7380 "to cancel");
7381 return -1;
7382 }
7383
7384 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
7385 "0x%llx",
7386 (long long unsigned int) drv->remain_on_chan_cookie);
7387
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007388 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
7389 if (!msg ||
7390 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
7391 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007392 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007393 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007394
7395 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7396 if (ret == 0)
7397 return 0;
7398 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
7399 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007400 return -1;
7401}
7402
7403
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007404static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007405{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007406 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007408 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007409 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07007410 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
7411 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007412 /*
7413 * Do not disable Probe Request reporting that was
7414 * enabled in nl80211_setup_ap().
7415 */
7416 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
7417 "Probe Request reporting nl_preq=%p while "
7418 "in AP mode", bss->nl_preq);
7419 } else if (bss->nl_preq) {
7420 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
7421 "reporting nl_preq=%p", bss->nl_preq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07007422 nl80211_destroy_eloop_handle(&bss->nl_preq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007423 }
7424 return 0;
7425 }
7426
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007427 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007428 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007429 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007430 return 0;
7431 }
7432
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007433 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
7434 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007435 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007436 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
7437 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007438
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007439 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007440 (WLAN_FC_TYPE_MGMT << 2) |
7441 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007442 NULL, 0) < 0)
7443 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07007444
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007445 nl80211_register_eloop_read(&bss->nl_preq,
7446 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007447 bss->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007448
7449 return 0;
7450
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007451 out_err:
7452 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007453 return -1;
7454}
7455
7456
7457static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
7458 int ifindex, int disabled)
7459{
7460 struct nl_msg *msg;
7461 struct nlattr *bands, *band;
7462 int ret;
7463
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007464 wpa_printf(MSG_DEBUG,
7465 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7466 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
7467 "no NL80211_TXRATE_LEGACY constraint");
7468
7469 msg = nl80211_ifindex_msg(drv, ifindex, 0,
7470 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007471 if (!msg)
7472 return -1;
7473
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007474 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
7475 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007476 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007477
7478 /*
7479 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7480 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7481 * rates. All 5 GHz rates are left enabled.
7482 */
7483 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007484 if (!band ||
7485 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
7486 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7487 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007488 nla_nest_end(msg, band);
7489
7490 nla_nest_end(msg, bands);
7491
7492 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007493 if (ret) {
7494 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
7495 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007496 } else
7497 drv->disabled_11b_rates = disabled;
7498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007499 return ret;
7500
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007501fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007502 nlmsg_free(msg);
7503 return -1;
7504}
7505
7506
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007507static int wpa_driver_nl80211_deinit_ap(void *priv)
7508{
7509 struct i802_bss *bss = priv;
7510 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007511 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007512 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08007513 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007514 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007515
7516 /*
7517 * If the P2P GO interface was dynamically added, then it is
7518 * possible that the interface change to station is not possible.
7519 */
7520 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
7521 return 0;
7522
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007523 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007524}
7525
7526
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007527static int wpa_driver_nl80211_stop_ap(void *priv)
7528{
7529 struct i802_bss *bss = priv;
7530 struct wpa_driver_nl80211_data *drv = bss->drv;
7531 if (!is_ap_interface(drv->nlmode))
7532 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08007533 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007534 bss->beacon_set = 0;
7535 return 0;
7536}
7537
7538
Dmitry Shmidt04949592012-07-19 12:16:46 -07007539static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
7540{
7541 struct i802_bss *bss = priv;
7542 struct wpa_driver_nl80211_data *drv = bss->drv;
7543 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
7544 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007545
7546 /*
7547 * If the P2P Client interface was dynamically added, then it is
7548 * possible that the interface change to station is not possible.
7549 */
7550 if (bss->if_dynamic)
7551 return 0;
7552
Dmitry Shmidt04949592012-07-19 12:16:46 -07007553 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
7554}
7555
7556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007557static void wpa_driver_nl80211_resume(void *priv)
7558{
7559 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007560 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007561
7562 if (i802_set_iface_flags(bss, 1))
7563 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007564
7565 if (is_p2p_net_interface(nlmode))
7566 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007567}
7568
7569
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007570static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
7571{
7572 struct i802_bss *bss = priv;
7573 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007574 struct nl_msg *msg;
7575 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007576
7577 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
7578 "hysteresis=%d", threshold, hysteresis);
7579
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007580 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
7581 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
7582 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
7583 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
7584 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007585 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007586 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007587 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007588
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007589 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007590}
7591
7592
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007593static int get_channel_width(struct nl_msg *msg, void *arg)
7594{
7595 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7596 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7597 struct wpa_signal_info *sig_change = arg;
7598
7599 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7600 genlmsg_attrlen(gnlh, 0), NULL);
7601
7602 sig_change->center_frq1 = -1;
7603 sig_change->center_frq2 = -1;
7604 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
7605
7606 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
7607 sig_change->chanwidth = convert2width(
7608 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
7609 if (tb[NL80211_ATTR_CENTER_FREQ1])
7610 sig_change->center_frq1 =
7611 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
7612 if (tb[NL80211_ATTR_CENTER_FREQ2])
7613 sig_change->center_frq2 =
7614 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
7615 }
7616
7617 return NL_SKIP;
7618}
7619
7620
7621static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
7622 struct wpa_signal_info *sig)
7623{
7624 struct nl_msg *msg;
7625
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007626 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007627 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007628}
7629
7630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007631static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
7632{
7633 struct i802_bss *bss = priv;
7634 struct wpa_driver_nl80211_data *drv = bss->drv;
7635 int res;
7636
7637 os_memset(si, 0, sizeof(*si));
7638 res = nl80211_get_link_signal(drv, si);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007639 if (res) {
7640 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
7641 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
7642 return res;
7643 si->current_signal = 0;
7644 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007645
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007646 res = nl80211_get_channel_width(drv, si);
7647 if (res != 0)
7648 return res;
7649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007650 return nl80211_get_link_noise(drv, si);
7651}
7652
7653
7654static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
7655 int encrypt)
7656{
7657 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007658 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007659 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007660}
7661
7662
7663static int nl80211_set_param(void *priv, const char *param)
7664{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007665 struct i802_bss *bss = priv;
7666 struct wpa_driver_nl80211_data *drv = bss->drv;
7667
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007668 if (param == NULL)
7669 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007670 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007671
7672#ifdef CONFIG_P2P
7673 if (os_strstr(param, "use_p2p_group_interface=1")) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007674 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
7675 "interface");
7676 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
7677 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
7678 }
7679#endif /* CONFIG_P2P */
7680
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007681 if (os_strstr(param, "use_monitor=1"))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007682 drv->use_monitor = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007683
7684 if (os_strstr(param, "force_connect_cmd=1")) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007685 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007686 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007687 }
7688
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007689 if (os_strstr(param, "force_bss_selection=1"))
7690 drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
7691
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08007692 if (os_strstr(param, "no_offchannel_tx=1")) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08007693 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
7694 drv->test_use_roc_tx = 1;
7695 }
7696
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007697 return 0;
7698}
7699
7700
Dmitry Shmidte4663042016-04-04 10:07:49 -07007701static void * nl80211_global_init(void *ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007702{
7703 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007704 struct netlink_config *cfg;
7705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007706 global = os_zalloc(sizeof(*global));
7707 if (global == NULL)
7708 return NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -07007709 global->ctx = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007710 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007711 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007712 global->if_add_ifindex = -1;
7713
7714 cfg = os_zalloc(sizeof(*cfg));
7715 if (cfg == NULL)
7716 goto err;
7717
7718 cfg->ctx = global;
7719 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
7720 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
7721 global->netlink = netlink_init(cfg);
7722 if (global->netlink == NULL) {
7723 os_free(cfg);
7724 goto err;
7725 }
7726
7727 if (wpa_driver_nl80211_init_nl_global(global) < 0)
7728 goto err;
7729
7730 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
7731 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007732 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
7733 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007734 goto err;
7735 }
7736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007737 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007738
7739err:
7740 nl80211_global_deinit(global);
7741 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007742}
7743
7744
7745static void nl80211_global_deinit(void *priv)
7746{
7747 struct nl80211_global *global = priv;
7748 if (global == NULL)
7749 return;
7750 if (!dl_list_empty(&global->interfaces)) {
7751 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
7752 "nl80211_global_deinit",
7753 dl_list_len(&global->interfaces));
7754 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007755
7756 if (global->netlink)
7757 netlink_deinit(global->netlink);
7758
7759 nl_destroy_handles(&global->nl);
7760
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007761 if (global->nl_event)
Roshan Pius3a1667e2018-07-03 15:17:14 -07007762 nl80211_destroy_eloop_handle(&global->nl_event, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007763
7764 nl_cb_put(global->nl_cb);
7765
7766 if (global->ioctl_sock >= 0)
7767 close(global->ioctl_sock);
7768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007769 os_free(global);
7770}
7771
7772
7773static const char * nl80211_get_radio_name(void *priv)
7774{
7775 struct i802_bss *bss = priv;
7776 struct wpa_driver_nl80211_data *drv = bss->drv;
7777 return drv->phyname;
7778}
7779
7780
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007781static int nl80211_pmkid(struct i802_bss *bss, int cmd,
7782 struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007783{
7784 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007785 const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */
Jouni Malinen75ecf522011-06-27 15:19:46 -07007786
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007787 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007788 (params->pmkid &&
7789 nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) ||
7790 (params->bssid &&
7791 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) ||
7792 (params->ssid_len &&
7793 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
7794 (params->fils_cache_id &&
7795 nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2,
7796 params->fils_cache_id)) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07007797 (params->pmk_len && params->pmk_len <= PMK_MAX_LEN &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007798 nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007799 nlmsg_free(msg);
7800 return -ENOBUFS;
7801 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07007802
7803 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07007804}
7805
7806
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007807static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007808{
7809 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007810 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007811
7812 if (params->bssid)
7813 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR,
7814 MAC2STR(params->bssid));
7815 else if (params->fils_cache_id && params->ssid_len) {
7816 wpa_printf(MSG_DEBUG,
7817 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
7818 params->fils_cache_id[0], params->fils_cache_id[1],
7819 wpa_ssid_txt(params->ssid, params->ssid_len));
7820 }
7821
Roshan Pius3a1667e2018-07-03 15:17:14 -07007822 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params);
7823 if (ret < 0) {
7824 wpa_printf(MSG_DEBUG,
7825 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
7826 ret, strerror(-ret));
7827 }
7828
7829 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007830}
7831
7832
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007833static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007834{
7835 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007836 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007837
7838 if (params->bssid)
7839 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
7840 MAC2STR(params->bssid));
7841 else if (params->fils_cache_id && params->ssid_len) {
7842 wpa_printf(MSG_DEBUG,
7843 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
7844 params->fils_cache_id[0], params->fils_cache_id[1],
7845 wpa_ssid_txt(params->ssid, params->ssid_len));
7846 }
7847
Roshan Pius3a1667e2018-07-03 15:17:14 -07007848 ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params);
7849 if (ret < 0) {
7850 wpa_printf(MSG_DEBUG,
7851 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
7852 ret, strerror(-ret));
7853 }
7854
7855 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007856}
7857
7858
7859static int nl80211_flush_pmkid(void *priv)
7860{
7861 struct i802_bss *bss = priv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007862 struct nl_msg *msg;
7863
Jouni Malinen75ecf522011-06-27 15:19:46 -07007864 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007865 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA);
7866 if (!msg)
7867 return -ENOBUFS;
7868 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07007869}
7870
7871
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007872static void clean_survey_results(struct survey_results *survey_results)
7873{
7874 struct freq_survey *survey, *tmp;
7875
7876 if (dl_list_empty(&survey_results->survey_list))
7877 return;
7878
7879 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
7880 struct freq_survey, list) {
7881 dl_list_del(&survey->list);
7882 os_free(survey);
7883 }
7884}
7885
7886
7887static void add_survey(struct nlattr **sinfo, u32 ifidx,
7888 struct dl_list *survey_list)
7889{
7890 struct freq_survey *survey;
7891
7892 survey = os_zalloc(sizeof(struct freq_survey));
7893 if (!survey)
7894 return;
7895
7896 survey->ifidx = ifidx;
7897 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
7898 survey->filled = 0;
7899
7900 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
7901 survey->nf = (int8_t)
7902 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
7903 survey->filled |= SURVEY_HAS_NF;
7904 }
7905
7906 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
7907 survey->channel_time =
7908 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
7909 survey->filled |= SURVEY_HAS_CHAN_TIME;
7910 }
7911
7912 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
7913 survey->channel_time_busy =
7914 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
7915 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
7916 }
7917
7918 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
7919 survey->channel_time_rx =
7920 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
7921 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
7922 }
7923
7924 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
7925 survey->channel_time_tx =
7926 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
7927 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
7928 }
7929
7930 wpa_printf(MSG_DEBUG, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
7931 survey->freq,
7932 survey->nf,
7933 (unsigned long int) survey->channel_time,
7934 (unsigned long int) survey->channel_time_busy,
7935 (unsigned long int) survey->channel_time_tx,
7936 (unsigned long int) survey->channel_time_rx,
7937 survey->filled);
7938
7939 dl_list_add_tail(survey_list, &survey->list);
7940}
7941
7942
7943static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
7944 unsigned int freq_filter)
7945{
7946 if (!freq_filter)
7947 return 1;
7948
7949 return freq_filter == surveyed_freq;
7950}
7951
7952
7953static int survey_handler(struct nl_msg *msg, void *arg)
7954{
7955 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7956 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7957 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
7958 struct survey_results *survey_results;
7959 u32 surveyed_freq = 0;
7960 u32 ifidx;
7961
7962 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
7963 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
7964 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
7965 };
7966
7967 survey_results = (struct survey_results *) arg;
7968
7969 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7970 genlmsg_attrlen(gnlh, 0), NULL);
7971
Dmitry Shmidt97672262014-02-03 13:02:54 -08007972 if (!tb[NL80211_ATTR_IFINDEX])
7973 return NL_SKIP;
7974
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007975 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
7976
7977 if (!tb[NL80211_ATTR_SURVEY_INFO])
7978 return NL_SKIP;
7979
7980 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
7981 tb[NL80211_ATTR_SURVEY_INFO],
7982 survey_policy))
7983 return NL_SKIP;
7984
7985 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
7986 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
7987 return NL_SKIP;
7988 }
7989
7990 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
7991
7992 if (!check_survey_ok(sinfo, surveyed_freq,
7993 survey_results->freq_filter))
7994 return NL_SKIP;
7995
7996 if (survey_results->freq_filter &&
7997 survey_results->freq_filter != surveyed_freq) {
7998 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
7999 surveyed_freq);
8000 return NL_SKIP;
8001 }
8002
8003 add_survey(sinfo, ifidx, &survey_results->survey_list);
8004
8005 return NL_SKIP;
8006}
8007
8008
8009static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
8010{
8011 struct i802_bss *bss = priv;
8012 struct wpa_driver_nl80211_data *drv = bss->drv;
8013 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008014 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008015 union wpa_event_data data;
8016 struct survey_results *survey_results;
8017
8018 os_memset(&data, 0, sizeof(data));
8019 survey_results = &data.survey_results;
8020
8021 dl_list_init(&survey_results->survey_list);
8022
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008023 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008024 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008025 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008026
8027 if (freq)
8028 data.survey_results.freq_filter = freq;
8029
8030 do {
8031 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
8032 err = send_and_recv_msgs(drv, msg, survey_handler,
8033 survey_results);
8034 } while (err > 0);
8035
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008036 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008037 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008038 else
8039 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008040
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008041 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008042 return err;
8043}
8044
8045
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008046static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
8047 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008048 const u8 *replay_ctr)
8049{
8050 struct i802_bss *bss = priv;
8051 struct wpa_driver_nl80211_data *drv = bss->drv;
8052 struct nlattr *replay_nested;
8053 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008054 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008055
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008056 if (!drv->set_rekey_offload)
8057 return;
8058
8059 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008060 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
8061 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008062 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008063 (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008064 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
8065 replay_ctr)) {
8066 nl80211_nlmsg_clear(msg);
8067 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008068 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008069 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008070
8071 nla_nest_end(msg, replay_nested);
8072
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008073 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
8074 if (ret == -EOPNOTSUPP) {
8075 wpa_printf(MSG_DEBUG,
8076 "nl80211: Driver does not support rekey offload");
8077 drv->set_rekey_offload = 0;
8078 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008079}
8080
8081
8082static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
8083 const u8 *addr, int qos)
8084{
8085 /* send data frame to poll STA and check whether
8086 * this frame is ACKed */
8087 struct {
8088 struct ieee80211_hdr hdr;
8089 u16 qos_ctl;
8090 } STRUCT_PACKED nulldata;
8091 size_t size;
8092
8093 /* Send data frame to poll STA and check whether this frame is ACKed */
8094
8095 os_memset(&nulldata, 0, sizeof(nulldata));
8096
8097 if (qos) {
8098 nulldata.hdr.frame_control =
8099 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8100 WLAN_FC_STYPE_QOS_NULL);
8101 size = sizeof(nulldata);
8102 } else {
8103 nulldata.hdr.frame_control =
8104 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8105 WLAN_FC_STYPE_NULLFUNC);
8106 size = sizeof(struct ieee80211_hdr);
8107 }
8108
8109 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
8110 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
8111 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
8112 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
8113
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008114 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008115 0, 0, NULL, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008116 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
8117 "send poll frame");
8118}
8119
8120static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
8121 int qos)
8122{
8123 struct i802_bss *bss = priv;
8124 struct wpa_driver_nl80211_data *drv = bss->drv;
8125 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008126 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008127
8128 if (!drv->poll_command_supported) {
8129 nl80211_send_null_frame(bss, own_addr, addr, qos);
8130 return;
8131 }
8132
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008133 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
8134 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8135 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008136 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008137 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008138
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008139 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8140 if (ret < 0) {
8141 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
8142 MACSTR " failed: ret=%d (%s)",
8143 MAC2STR(addr), ret, strerror(-ret));
8144 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008145}
8146
8147
8148static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
8149{
8150 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008151 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008152
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008153 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
8154 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
8155 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
8156 nlmsg_free(msg);
8157 return -ENOBUFS;
8158 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07008159
8160 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
8161 if (ret < 0) {
8162 wpa_printf(MSG_DEBUG,
8163 "nl80211: Setting PS state %s failed: %d (%s)",
8164 enabled ? "enabled" : "disabled",
8165 ret, strerror(-ret));
8166 }
8167 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008168}
8169
8170
8171static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
8172 int ctwindow)
8173{
8174 struct i802_bss *bss = priv;
8175
8176 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
8177 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
8178
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008179 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08008180#ifdef ANDROID_P2P
8181 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008182#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008183 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008184#endif /* ANDROID_P2P */
8185 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008186
8187 if (legacy_ps == -1)
8188 return 0;
8189 if (legacy_ps != 0 && legacy_ps != 1)
8190 return -1; /* Not yet supported */
8191
8192 return nl80211_set_power_save(bss, legacy_ps);
8193}
8194
8195
Dmitry Shmidt051af732013-10-22 13:52:46 -07008196static int nl80211_start_radar_detection(void *priv,
8197 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008198{
8199 struct i802_bss *bss = priv;
8200 struct wpa_driver_nl80211_data *drv = bss->drv;
8201 struct nl_msg *msg;
8202 int ret;
8203
Dmitry Shmidt051af732013-10-22 13:52:46 -07008204 wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
8205 freq->freq, freq->ht_enabled, freq->vht_enabled,
8206 freq->bandwidth, freq->center_freq1, freq->center_freq2);
8207
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008208 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
8209 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
8210 "detection");
8211 return -1;
8212 }
8213
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008214 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
8215 nl80211_put_freq_params(msg, freq) < 0) {
8216 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008217 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008218 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008219
8220 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8221 if (ret == 0)
8222 return 0;
8223 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
8224 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008225 return -1;
8226}
8227
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008228#ifdef CONFIG_TDLS
8229
8230static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
8231 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07008232 u32 peer_capab, int initiator, const u8 *buf,
8233 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008234{
8235 struct i802_bss *bss = priv;
8236 struct wpa_driver_nl80211_data *drv = bss->drv;
8237 struct nl_msg *msg;
8238
8239 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8240 return -EOPNOTSUPP;
8241
8242 if (!dst)
8243 return -EINVAL;
8244
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008245 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
8246 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
8247 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
8248 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
8249 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
8250 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008251 if (peer_capab) {
8252 /*
8253 * The internal enum tdls_peer_capability definition is
8254 * currently identical with the nl80211 enum
8255 * nl80211_tdls_peer_capability, so no conversion is needed
8256 * here.
8257 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008258 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
8259 peer_capab))
8260 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008261 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008262 if ((initiator &&
8263 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
8264 nla_put(msg, NL80211_ATTR_IE, len, buf))
8265 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008266
8267 return send_and_recv_msgs(drv, msg, NULL, NULL);
8268
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008269fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008270 nlmsg_free(msg);
8271 return -ENOBUFS;
8272}
8273
8274
8275static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
8276{
8277 struct i802_bss *bss = priv;
8278 struct wpa_driver_nl80211_data *drv = bss->drv;
8279 struct nl_msg *msg;
8280 enum nl80211_tdls_operation nl80211_oper;
Paul Stewart092955c2017-02-06 09:13:09 -08008281 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008282
8283 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8284 return -EOPNOTSUPP;
8285
8286 switch (oper) {
8287 case TDLS_DISCOVERY_REQ:
8288 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
8289 break;
8290 case TDLS_SETUP:
8291 nl80211_oper = NL80211_TDLS_SETUP;
8292 break;
8293 case TDLS_TEARDOWN:
8294 nl80211_oper = NL80211_TDLS_TEARDOWN;
8295 break;
8296 case TDLS_ENABLE_LINK:
8297 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
8298 break;
8299 case TDLS_DISABLE_LINK:
8300 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
8301 break;
8302 case TDLS_ENABLE:
8303 return 0;
8304 case TDLS_DISABLE:
8305 return 0;
8306 default:
8307 return -EINVAL;
8308 }
8309
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008310 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
8311 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
8312 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
8313 nlmsg_free(msg);
8314 return -ENOBUFS;
8315 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008316
Paul Stewart092955c2017-02-06 09:13:09 -08008317 res = send_and_recv_msgs(drv, msg, NULL, NULL);
8318 wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8319 " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res,
8320 strerror(-res));
8321 return res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008322}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008323
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008324
8325static int
8326nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
8327 const struct hostapd_freq_params *params)
8328{
8329 struct i802_bss *bss = priv;
8330 struct wpa_driver_nl80211_data *drv = bss->drv;
8331 struct nl_msg *msg;
8332 int ret = -ENOBUFS;
8333
8334 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8335 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8336 return -EOPNOTSUPP;
8337
8338 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
8339 " oper_class=%u freq=%u",
8340 MAC2STR(addr), oper_class, params->freq);
8341 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
8342 if (!msg ||
8343 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8344 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
8345 (ret = nl80211_put_freq_params(msg, params))) {
8346 nlmsg_free(msg);
8347 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
8348 return ret;
8349 }
8350
8351 return send_and_recv_msgs(drv, msg, NULL, NULL);
8352}
8353
8354
8355static int
8356nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
8357{
8358 struct i802_bss *bss = priv;
8359 struct wpa_driver_nl80211_data *drv = bss->drv;
8360 struct nl_msg *msg;
8361
8362 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8363 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8364 return -EOPNOTSUPP;
8365
8366 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
8367 MAC2STR(addr));
8368 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
8369 if (!msg ||
8370 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8371 nlmsg_free(msg);
8372 wpa_printf(MSG_DEBUG,
8373 "nl80211: Could not build TDLS cancel chan switch");
8374 return -ENOBUFS;
8375 }
8376
8377 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008378}
8379
8380#endif /* CONFIG TDLS */
8381
8382
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008383static int driver_nl80211_set_key(const char *ifname, void *priv,
8384 enum wpa_alg alg, const u8 *addr,
8385 int key_idx, int set_tx,
8386 const u8 *seq, size_t seq_len,
8387 const u8 *key, size_t key_len)
8388{
8389 struct i802_bss *bss = priv;
8390 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
8391 set_tx, seq, seq_len, key, key_len);
8392}
8393
8394
8395static int driver_nl80211_scan2(void *priv,
8396 struct wpa_driver_scan_params *params)
8397{
8398 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008399#ifdef CONFIG_DRIVER_NL80211_QCA
8400 struct wpa_driver_nl80211_data *drv = bss->drv;
8401
8402 /*
8403 * Do a vendor specific scan if possible. If only_new_results is
8404 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8405 * cannot be achieved through a vendor scan. The below condition may
8406 * need to be modified if new scan flags are added in the future whose
8407 * functionality can only be achieved through a normal scan.
8408 */
8409 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
8410 return wpa_driver_nl80211_vendor_scan(bss, params);
8411#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008412 return wpa_driver_nl80211_scan(bss, params);
8413}
8414
8415
8416static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
8417 int reason_code)
8418{
8419 struct i802_bss *bss = priv;
8420 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
8421}
8422
8423
8424static int driver_nl80211_authenticate(void *priv,
8425 struct wpa_driver_auth_params *params)
8426{
8427 struct i802_bss *bss = priv;
8428 return wpa_driver_nl80211_authenticate(bss, params);
8429}
8430
8431
8432static void driver_nl80211_deinit(void *priv)
8433{
8434 struct i802_bss *bss = priv;
8435 wpa_driver_nl80211_deinit(bss);
8436}
8437
8438
8439static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
8440 const char *ifname)
8441{
8442 struct i802_bss *bss = priv;
8443 return wpa_driver_nl80211_if_remove(bss, type, ifname);
8444}
8445
8446
8447static int driver_nl80211_send_mlme(void *priv, const u8 *data,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07008448 size_t data_len, int noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008449 unsigned int freq,
8450 const u16 *csa_offs, size_t csa_offs_len)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008451{
8452 struct i802_bss *bss = priv;
8453 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008454 freq, 0, 0, 0, csa_offs,
8455 csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008456}
8457
8458
8459static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
8460{
8461 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008462 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008463}
8464
8465
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008466static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
8467 const char *ifname, int vlan_id)
8468{
8469 struct i802_bss *bss = priv;
8470 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
8471}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008472
8473
8474static int driver_nl80211_read_sta_data(void *priv,
8475 struct hostap_sta_driver_data *data,
8476 const u8 *addr)
8477{
8478 struct i802_bss *bss = priv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08008479
8480 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008481 return i802_read_sta_data(bss, data, addr);
8482}
8483
8484
8485static int driver_nl80211_send_action(void *priv, unsigned int freq,
8486 unsigned int wait_time,
8487 const u8 *dst, const u8 *src,
8488 const u8 *bssid,
8489 const u8 *data, size_t data_len,
8490 int no_cck)
8491{
8492 struct i802_bss *bss = priv;
8493 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
8494 bssid, data, data_len, no_cck);
8495}
8496
8497
8498static int driver_nl80211_probe_req_report(void *priv, int report)
8499{
8500 struct i802_bss *bss = priv;
8501 return wpa_driver_nl80211_probe_req_report(bss, report);
8502}
8503
8504
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008505static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
8506 const u8 *ies, size_t ies_len)
8507{
8508 int ret;
8509 struct nl_msg *msg;
8510 struct i802_bss *bss = priv;
8511 struct wpa_driver_nl80211_data *drv = bss->drv;
8512 u16 mdid = WPA_GET_LE16(md);
8513
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008514 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008515 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
8516 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
8517 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
8518 nlmsg_free(msg);
8519 return -ENOBUFS;
8520 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008521
8522 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8523 if (ret) {
8524 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
8525 "err=%d (%s)", ret, strerror(-ret));
8526 }
8527
8528 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008529}
8530
8531
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008532static const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008533{
8534 struct i802_bss *bss = priv;
8535 struct wpa_driver_nl80211_data *drv = bss->drv;
8536
8537 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
8538 return NULL;
8539
8540 return bss->addr;
8541}
8542
8543
Dmitry Shmidt56052862013-10-04 10:23:25 -07008544static const char * scan_state_str(enum scan_states scan_state)
8545{
8546 switch (scan_state) {
8547 case NO_SCAN:
8548 return "NO_SCAN";
8549 case SCAN_REQUESTED:
8550 return "SCAN_REQUESTED";
8551 case SCAN_STARTED:
8552 return "SCAN_STARTED";
8553 case SCAN_COMPLETED:
8554 return "SCAN_COMPLETED";
8555 case SCAN_ABORTED:
8556 return "SCAN_ABORTED";
8557 case SCHED_SCAN_STARTED:
8558 return "SCHED_SCAN_STARTED";
8559 case SCHED_SCAN_STOPPED:
8560 return "SCHED_SCAN_STOPPED";
8561 case SCHED_SCAN_RESULTS:
8562 return "SCHED_SCAN_RESULTS";
8563 }
8564
8565 return "??";
8566}
8567
8568
8569static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
8570{
8571 struct i802_bss *bss = priv;
8572 struct wpa_driver_nl80211_data *drv = bss->drv;
8573 int res;
8574 char *pos, *end;
8575
8576 pos = buf;
8577 end = buf + buflen;
8578
8579 res = os_snprintf(pos, end - pos,
8580 "ifindex=%d\n"
8581 "ifname=%s\n"
8582 "brname=%s\n"
8583 "addr=" MACSTR "\n"
8584 "freq=%d\n"
Hai Shalomc9e41a12018-07-31 14:41:42 -07008585 "%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008586 bss->ifindex,
8587 bss->ifname,
8588 bss->brname,
8589 MAC2STR(bss->addr),
8590 bss->freq,
8591 bss->beacon_set ? "beacon_set=1\n" : "",
8592 bss->added_if_into_bridge ?
8593 "added_if_into_bridge=1\n" : "",
Hai Shalomc9e41a12018-07-31 14:41:42 -07008594 bss->already_in_bridge ? "already_in_bridge=1\n" : "",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008595 bss->added_bridge ? "added_bridge=1\n" : "",
8596 bss->in_deinit ? "in_deinit=1\n" : "",
8597 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008598 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008599 return pos - buf;
8600 pos += res;
8601
8602 if (bss->wdev_id_set) {
8603 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
8604 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008605 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008606 return pos - buf;
8607 pos += res;
8608 }
8609
8610 res = os_snprintf(pos, end - pos,
8611 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008612 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07008613 "drv_ifindex=%d\n"
8614 "operstate=%d\n"
8615 "scan_state=%s\n"
8616 "auth_bssid=" MACSTR "\n"
8617 "auth_attempt_bssid=" MACSTR "\n"
8618 "bssid=" MACSTR "\n"
8619 "prev_bssid=" MACSTR "\n"
8620 "associated=%d\n"
8621 "assoc_freq=%u\n"
8622 "monitor_sock=%d\n"
8623 "monitor_ifidx=%d\n"
8624 "monitor_refcount=%d\n"
8625 "last_mgmt_freq=%u\n"
8626 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008627 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008628 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008629 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07008630 drv->ifindex,
8631 drv->operstate,
8632 scan_state_str(drv->scan_state),
8633 MAC2STR(drv->auth_bssid),
8634 MAC2STR(drv->auth_attempt_bssid),
8635 MAC2STR(drv->bssid),
8636 MAC2STR(drv->prev_bssid),
8637 drv->associated,
8638 drv->assoc_freq,
8639 drv->monitor_sock,
8640 drv->monitor_ifidx,
8641 drv->monitor_refcount,
8642 drv->last_mgmt_freq,
8643 drv->eapol_tx_sock,
8644 drv->ignore_if_down_event ?
8645 "ignore_if_down_event=1\n" : "",
8646 drv->scan_complete_events ?
8647 "scan_complete_events=1\n" : "",
8648 drv->disabled_11b_rates ?
8649 "disabled_11b_rates=1\n" : "",
8650 drv->pending_remain_on_chan ?
8651 "pending_remain_on_chan=1\n" : "",
8652 drv->in_interface_list ? "in_interface_list=1\n" : "",
8653 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
8654 drv->poll_command_supported ?
8655 "poll_command_supported=1\n" : "",
8656 drv->data_tx_status ? "data_tx_status=1\n" : "",
8657 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
8658 drv->retry_auth ? "retry_auth=1\n" : "",
8659 drv->use_monitor ? "use_monitor=1\n" : "",
8660 drv->ignore_next_local_disconnect ?
8661 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008662 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008663 "ignore_next_local_deauth=1\n" : "");
8664 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008665 return pos - buf;
8666 pos += res;
8667
8668 if (drv->has_capability) {
8669 res = os_snprintf(pos, end - pos,
8670 "capa.key_mgmt=0x%x\n"
8671 "capa.enc=0x%x\n"
8672 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008673 "capa.flags=0x%llx\n"
8674 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07008675 "capa.max_scan_ssids=%d\n"
8676 "capa.max_sched_scan_ssids=%d\n"
8677 "capa.sched_scan_supported=%d\n"
8678 "capa.max_match_sets=%d\n"
8679 "capa.max_remain_on_chan=%u\n"
8680 "capa.max_stations=%u\n"
8681 "capa.probe_resp_offloads=0x%x\n"
8682 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008683 "capa.num_multichan_concurrent=%u\n"
8684 "capa.mac_addr_rand_sched_scan_supported=%d\n"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008685 "capa.mac_addr_rand_scan_supported=%d\n"
8686 "capa.conc_capab=%u\n"
8687 "capa.max_conc_chan_2_4=%u\n"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008688 "capa.max_conc_chan_5_0=%u\n"
8689 "capa.max_sched_scan_plans=%u\n"
8690 "capa.max_sched_scan_plan_interval=%u\n"
8691 "capa.max_sched_scan_plan_iterations=%u\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008692 drv->capa.key_mgmt,
8693 drv->capa.enc,
8694 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008695 (unsigned long long) drv->capa.flags,
8696 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07008697 drv->capa.max_scan_ssids,
8698 drv->capa.max_sched_scan_ssids,
8699 drv->capa.sched_scan_supported,
8700 drv->capa.max_match_sets,
8701 drv->capa.max_remain_on_chan,
8702 drv->capa.max_stations,
8703 drv->capa.probe_resp_offloads,
8704 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008705 drv->capa.num_multichan_concurrent,
8706 drv->capa.mac_addr_rand_sched_scan_supported,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008707 drv->capa.mac_addr_rand_scan_supported,
8708 drv->capa.conc_capab,
8709 drv->capa.max_conc_chan_2_4,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008710 drv->capa.max_conc_chan_5_0,
8711 drv->capa.max_sched_scan_plans,
8712 drv->capa.max_sched_scan_plan_interval,
8713 drv->capa.max_sched_scan_plan_iterations);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008714 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008715 return pos - buf;
8716 pos += res;
8717 }
8718
8719 return pos - buf;
8720}
8721
8722
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008723static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
8724{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008725 if ((settings->head &&
8726 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
8727 settings->head_len, settings->head)) ||
8728 (settings->tail &&
8729 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
8730 settings->tail_len, settings->tail)) ||
8731 (settings->beacon_ies &&
8732 nla_put(msg, NL80211_ATTR_IE,
8733 settings->beacon_ies_len, settings->beacon_ies)) ||
8734 (settings->proberesp_ies &&
8735 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
8736 settings->proberesp_ies_len, settings->proberesp_ies)) ||
8737 (settings->assocresp_ies &&
8738 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
8739 settings->assocresp_ies_len, settings->assocresp_ies)) ||
8740 (settings->probe_resp &&
8741 nla_put(msg, NL80211_ATTR_PROBE_RESP,
8742 settings->probe_resp_len, settings->probe_resp)))
8743 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008744
8745 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008746}
8747
8748
8749static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
8750{
8751 struct nl_msg *msg;
8752 struct i802_bss *bss = priv;
8753 struct wpa_driver_nl80211_data *drv = bss->drv;
8754 struct nlattr *beacon_csa;
8755 int ret = -ENOBUFS;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008756 int csa_off_len = 0;
8757 int i;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008758
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08008759 wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008760 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08008761 settings->freq_params.freq, settings->freq_params.bandwidth,
8762 settings->freq_params.center_freq1,
8763 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008764
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008765 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008766 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
8767 return -EOPNOTSUPP;
8768 }
8769
Roshan Pius3a1667e2018-07-03 15:17:14 -07008770 if (drv->nlmode != NL80211_IFTYPE_AP &&
8771 drv->nlmode != NL80211_IFTYPE_P2P_GO &&
8772 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008773 return -EOPNOTSUPP;
8774
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008775 /*
8776 * Remove empty counters, assuming Probe Response and Beacon frame
8777 * counters match. This implementation assumes that there are only two
8778 * counters.
8779 */
8780 if (settings->counter_offset_beacon[0] &&
8781 !settings->counter_offset_beacon[1]) {
8782 csa_off_len = 1;
8783 } else if (settings->counter_offset_beacon[1] &&
8784 !settings->counter_offset_beacon[0]) {
8785 csa_off_len = 1;
8786 settings->counter_offset_beacon[0] =
8787 settings->counter_offset_beacon[1];
8788 settings->counter_offset_presp[0] =
8789 settings->counter_offset_presp[1];
8790 } else if (settings->counter_offset_beacon[1] &&
8791 settings->counter_offset_beacon[0]) {
8792 csa_off_len = 2;
8793 } else {
8794 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
8795 return -EINVAL;
8796 }
8797
8798 /* Check CSA counters validity */
8799 if (drv->capa.max_csa_counters &&
8800 csa_off_len > drv->capa.max_csa_counters) {
8801 wpa_printf(MSG_ERROR,
8802 "nl80211: Too many CSA counters provided");
8803 return -EINVAL;
8804 }
8805
8806 if (!settings->beacon_csa.tail)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008807 return -EINVAL;
8808
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008809 for (i = 0; i < csa_off_len; i++) {
8810 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
8811 u16 csa_c_off_presp = settings->counter_offset_presp[i];
8812
8813 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
8814 (settings->beacon_csa.tail[csa_c_off_bcn] !=
8815 settings->cs_count))
8816 return -EINVAL;
8817
8818 if (settings->beacon_csa.probe_resp &&
8819 ((settings->beacon_csa.probe_resp_len <=
8820 csa_c_off_presp) ||
8821 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
8822 settings->cs_count)))
8823 return -EINVAL;
8824 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008825
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008826 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
8827 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
8828 settings->cs_count) ||
8829 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
8830 (settings->block_tx &&
8831 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008832 goto error;
8833
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008834 /* beacon_after params */
8835 ret = set_beacon_data(msg, &settings->beacon_after);
8836 if (ret)
8837 goto error;
8838
8839 /* beacon_csa params */
8840 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
8841 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008842 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008843
8844 ret = set_beacon_data(msg, &settings->beacon_csa);
8845 if (ret)
8846 goto error;
8847
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008848 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
8849 csa_off_len * sizeof(u16),
8850 settings->counter_offset_beacon) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008851 (settings->beacon_csa.probe_resp &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008852 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
8853 csa_off_len * sizeof(u16),
8854 settings->counter_offset_presp)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008855 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008856
8857 nla_nest_end(msg, beacon_csa);
8858 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8859 if (ret) {
8860 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
8861 ret, strerror(-ret));
8862 }
8863 return ret;
8864
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008865fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008866 ret = -ENOBUFS;
8867error:
8868 nlmsg_free(msg);
8869 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
8870 return ret;
8871}
8872
8873
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008874static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
8875 u8 user_priority, u16 admitted_time)
8876{
8877 struct i802_bss *bss = priv;
8878 struct wpa_driver_nl80211_data *drv = bss->drv;
8879 struct nl_msg *msg;
8880 int ret;
8881
8882 wpa_printf(MSG_DEBUG,
8883 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
8884 tsid, admitted_time, user_priority);
8885
8886 if (!is_sta_interface(drv->nlmode))
8887 return -ENOTSUP;
8888
8889 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
8890 if (!msg ||
8891 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
8892 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8893 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
8894 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
8895 nlmsg_free(msg);
8896 return -ENOBUFS;
8897 }
8898
8899 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8900 if (ret)
8901 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
8902 ret, strerror(-ret));
8903 return ret;
8904}
8905
8906
8907static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
8908{
8909 struct i802_bss *bss = priv;
8910 struct wpa_driver_nl80211_data *drv = bss->drv;
8911 struct nl_msg *msg;
8912 int ret;
8913
8914 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
8915
8916 if (!is_sta_interface(drv->nlmode))
8917 return -ENOTSUP;
8918
8919 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
8920 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
8921 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8922 nlmsg_free(msg);
8923 return -ENOBUFS;
8924 }
8925
8926 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8927 if (ret)
8928 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
8929 ret, strerror(-ret));
8930 return ret;
8931}
8932
8933
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008934#ifdef CONFIG_TESTING_OPTIONS
8935static int cmd_reply_handler(struct nl_msg *msg, void *arg)
8936{
8937 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8938 struct wpabuf *buf = arg;
8939
8940 if (!buf)
8941 return NL_SKIP;
8942
8943 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
8944 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
8945 return NL_SKIP;
8946 }
8947
8948 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
8949 genlmsg_attrlen(gnlh, 0));
8950
8951 return NL_SKIP;
8952}
8953#endif /* CONFIG_TESTING_OPTIONS */
8954
8955
8956static int vendor_reply_handler(struct nl_msg *msg, void *arg)
8957{
8958 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8959 struct nlattr *nl_vendor_reply, *nl;
8960 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8961 struct wpabuf *buf = arg;
8962 int rem;
8963
8964 if (!buf)
8965 return NL_SKIP;
8966
8967 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8968 genlmsg_attrlen(gnlh, 0), NULL);
8969 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
8970
8971 if (!nl_vendor_reply)
8972 return NL_SKIP;
8973
8974 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
8975 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
8976 return NL_SKIP;
8977 }
8978
8979 nla_for_each_nested(nl, nl_vendor_reply, rem) {
8980 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
8981 }
8982
8983 return NL_SKIP;
8984}
8985
8986
8987static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
8988 unsigned int subcmd, const u8 *data,
8989 size_t data_len, struct wpabuf *buf)
8990{
8991 struct i802_bss *bss = priv;
8992 struct wpa_driver_nl80211_data *drv = bss->drv;
8993 struct nl_msg *msg;
8994 int ret;
8995
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008996#ifdef CONFIG_TESTING_OPTIONS
8997 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008998 msg = nlmsg_alloc();
8999 if (!msg)
9000 return -ENOMEM;
9001
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009002 nl80211_cmd(drv, msg, 0, subcmd);
9003 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
9004 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009005 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009006 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
9007 if (ret)
9008 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
9009 ret);
9010 return ret;
9011 }
9012#endif /* CONFIG_TESTING_OPTIONS */
9013
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009014 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
9015 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
9016 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
9017 (data &&
9018 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
9019 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009020
9021 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
9022 if (ret)
9023 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
9024 ret);
9025 return ret;
9026
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009027fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009028 nlmsg_free(msg);
9029 return -ENOBUFS;
9030}
9031
9032
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009033static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
9034 u8 qos_map_set_len)
9035{
9036 struct i802_bss *bss = priv;
9037 struct wpa_driver_nl80211_data *drv = bss->drv;
9038 struct nl_msg *msg;
9039 int ret;
9040
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009041 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
9042 qos_map_set, qos_map_set_len);
9043
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009044 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
9045 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
9046 nlmsg_free(msg);
9047 return -ENOBUFS;
9048 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009049
9050 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9051 if (ret)
9052 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
9053
9054 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009055}
9056
9057
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009058static int nl80211_set_wowlan(void *priv,
9059 const struct wowlan_triggers *triggers)
9060{
9061 struct i802_bss *bss = priv;
9062 struct wpa_driver_nl80211_data *drv = bss->drv;
9063 struct nl_msg *msg;
9064 struct nlattr *wowlan_triggers;
9065 int ret;
9066
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009067 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
9068
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07009069 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009070 !(wowlan_triggers = nla_nest_start(msg,
9071 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
9072 (triggers->any &&
9073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
9074 (triggers->disconnect &&
9075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
9076 (triggers->magic_pkt &&
9077 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
9078 (triggers->gtk_rekey_failure &&
9079 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
9080 (triggers->eap_identity_req &&
9081 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
9082 (triggers->four_way_handshake &&
9083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
9084 (triggers->rfkill_release &&
9085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
9086 nlmsg_free(msg);
9087 return -ENOBUFS;
9088 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009089
9090 nla_nest_end(msg, wowlan_triggers);
9091
9092 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9093 if (ret)
9094 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
9095
9096 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009097}
9098
9099
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009100#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009101static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
9102{
9103 struct i802_bss *bss = priv;
9104 struct wpa_driver_nl80211_data *drv = bss->drv;
9105 struct nl_msg *msg;
9106 struct nlattr *params;
9107
9108 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
9109
9110 if (!drv->roaming_vendor_cmd_avail) {
9111 wpa_printf(MSG_DEBUG,
9112 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
9113 return -1;
9114 }
9115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009116 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9117 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9118 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9119 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
9120 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9121 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
9122 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
9123 QCA_ROAMING_NOT_ALLOWED) ||
9124 (bssid &&
9125 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
9126 nlmsg_free(msg);
9127 return -1;
9128 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009129 nla_nest_end(msg, params);
9130
9131 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009132}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009133
9134
Roshan Pius3a1667e2018-07-03 15:17:14 -07009135static int nl80211_disable_fils(void *priv, int disable)
9136{
9137 struct i802_bss *bss = priv;
9138 struct wpa_driver_nl80211_data *drv = bss->drv;
9139 struct nl_msg *msg;
9140 struct nlattr *params;
9141
9142 wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable);
9143
9144 if (!drv->set_wifi_conf_vendor_cmd_avail)
9145 return -1;
9146
9147 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9148 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9149 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9150 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
9151 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9152 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS,
9153 disable)) {
9154 nlmsg_free(msg);
9155 return -1;
9156 }
9157 nla_nest_end(msg, params);
9158
9159 return send_and_recv_msgs(drv, msg, NULL, NULL);
9160}
9161
9162
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009163/* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
9164#define WPA_SUPPLICANT_CLIENT_ID 1
9165
9166static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid,
9167 const u8 *bssid)
9168{
9169 struct i802_bss *bss = priv;
9170 struct wpa_driver_nl80211_data *drv = bss->drv;
9171 struct nl_msg *msg;
9172 struct nlattr *params, *nlbssids, *attr;
9173 unsigned int i;
9174
9175 wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)",
9176 num_bssid);
9177
9178 if (!drv->roam_vendor_cmd_avail)
9179 return -1;
9180
9181 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9182 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9183 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9184 QCA_NL80211_VENDOR_SUBCMD_ROAM) ||
9185 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9186 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
9187 QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) ||
9188 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID,
9189 WPA_SUPPLICANT_CLIENT_ID) ||
9190 nla_put_u32(msg,
9191 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
9192 num_bssid))
9193 goto fail;
9194
9195 nlbssids = nla_nest_start(
9196 msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
9197 if (!nlbssids)
9198 goto fail;
9199
9200 for (i = 0; i < num_bssid; i++) {
9201 attr = nla_nest_start(msg, i);
9202 if (!attr)
9203 goto fail;
9204 if (nla_put(msg,
9205 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
9206 ETH_ALEN, &bssid[i * ETH_ALEN]))
9207 goto fail;
9208 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i,
9209 MAC2STR(&bssid[i * ETH_ALEN]));
9210 nla_nest_end(msg, attr);
9211 }
9212 nla_nest_end(msg, nlbssids);
9213 nla_nest_end(msg, params);
9214
9215 return send_and_recv_msgs(drv, msg, NULL, NULL);
9216
9217fail:
9218 nlmsg_free(msg);
9219 return -1;
9220}
9221
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009222#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009223
9224
9225static int nl80211_set_mac_addr(void *priv, const u8 *addr)
9226{
9227 struct i802_bss *bss = priv;
9228 struct wpa_driver_nl80211_data *drv = bss->drv;
9229 int new_addr = addr != NULL;
9230
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009231 if (TEST_FAIL())
9232 return -1;
9233
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009234 if (!addr)
9235 addr = drv->perm_addr;
9236
9237 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
9238 return -1;
9239
9240 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
9241 {
9242 wpa_printf(MSG_DEBUG,
9243 "nl80211: failed to set_mac_addr for %s to " MACSTR,
9244 bss->ifname, MAC2STR(addr));
9245 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
9246 1) < 0) {
9247 wpa_printf(MSG_DEBUG,
9248 "nl80211: Could not restore interface UP after failed set_mac_addr");
9249 }
9250 return -1;
9251 }
9252
9253 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
9254 bss->ifname, MAC2STR(addr));
9255 drv->addr_changed = new_addr;
9256 os_memcpy(bss->addr, addr, ETH_ALEN);
9257
9258 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
9259 {
9260 wpa_printf(MSG_DEBUG,
9261 "nl80211: Could not restore interface UP after set_mac_addr");
9262 }
9263
9264 return 0;
9265}
9266
9267
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009268#ifdef CONFIG_MESH
9269
9270static int wpa_driver_nl80211_init_mesh(void *priv)
9271{
9272 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
9273 wpa_printf(MSG_INFO,
9274 "nl80211: Failed to set interface into mesh mode");
9275 return -1;
9276 }
9277 return 0;
9278}
9279
9280
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009281static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
9282 size_t mesh_id_len)
9283{
9284 if (mesh_id) {
9285 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
9286 mesh_id, mesh_id_len);
9287 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
9288 }
9289
9290 return 0;
9291}
9292
9293
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009294static int nl80211_put_mesh_config(struct nl_msg *msg,
9295 struct wpa_driver_mesh_bss_params *params)
9296{
9297 struct nlattr *container;
9298
9299 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
9300 if (!container)
9301 return -1;
9302
9303 if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07009304 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
9305 params->auto_plinks)) ||
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009306 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
9307 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009308 params->max_peer_links)) ||
9309 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) &&
9310 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
9311 params->rssi_threshold)))
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009312 return -1;
9313
9314 /*
9315 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9316 * the timer could disconnect stations even in that case.
9317 */
9318 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) &&
9319 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
9320 params->peer_link_timeout)) {
9321 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
9322 return -1;
9323 }
9324
9325 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) &&
9326 nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) {
9327 wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE");
9328 return -1;
9329 }
9330
9331 nla_nest_end(msg, container);
9332
9333 return 0;
9334}
9335
9336
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009337static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009338 struct wpa_driver_mesh_join_params *params)
9339{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009340 struct wpa_driver_nl80211_data *drv = bss->drv;
9341 struct nl_msg *msg;
9342 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08009343 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009344
9345 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
9346 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009347 if (!msg ||
9348 nl80211_put_freq_params(msg, &params->freq) ||
9349 nl80211_put_basic_rates(msg, params->basic_rates) ||
9350 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009351 nl80211_put_beacon_int(msg, params->beacon_int) ||
9352 nl80211_put_dtim_period(msg, params->dtim_period))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009353 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009354
9355 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
9356
9357 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
9358 if (!container)
9359 goto fail;
9360
9361 if (params->ies) {
9362 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
9363 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
9364 params->ies))
9365 goto fail;
9366 }
9367 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
9368 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
9369 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
9370 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
9371 goto fail;
9372 }
9373 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
9374 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
9375 goto fail;
9376 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
9377 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
9378 goto fail;
9379 nla_nest_end(msg, container);
9380
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009381 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
9382 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT;
9383 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS;
9384 if (nl80211_put_mesh_config(msg, &params->conf) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009385 goto fail;
9386
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009387 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9388 msg = NULL;
9389 if (ret) {
9390 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
9391 ret, strerror(-ret));
9392 goto fail;
9393 }
9394 ret = 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07009395 drv->assoc_freq = bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009396 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
9397
9398fail:
9399 nlmsg_free(msg);
9400 return ret;
9401}
9402
9403
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009404static int
9405wpa_driver_nl80211_join_mesh(void *priv,
9406 struct wpa_driver_mesh_join_params *params)
9407{
9408 struct i802_bss *bss = priv;
9409 int ret, timeout;
9410
9411 timeout = params->conf.peer_link_timeout;
9412
9413 /* Disable kernel inactivity timer */
9414 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
9415 params->conf.peer_link_timeout = 0;
9416
9417 ret = nl80211_join_mesh(bss, params);
9418 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
9419 wpa_printf(MSG_DEBUG,
9420 "nl80211: Mesh join retry for peer_link_timeout");
9421 /*
9422 * Old kernel does not support setting
9423 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
9424 * into future from peer_link_timeout.
9425 */
9426 params->conf.peer_link_timeout = timeout + 60;
9427 ret = nl80211_join_mesh(priv, params);
9428 }
9429
9430 params->conf.peer_link_timeout = timeout;
9431 return ret;
9432}
9433
9434
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009435static int wpa_driver_nl80211_leave_mesh(void *priv)
9436{
9437 struct i802_bss *bss = priv;
9438 struct wpa_driver_nl80211_data *drv = bss->drv;
9439 struct nl_msg *msg;
9440 int ret;
9441
9442 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
9443 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
9444 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9445 if (ret) {
9446 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
9447 ret, strerror(-ret));
9448 } else {
9449 wpa_printf(MSG_DEBUG,
9450 "nl80211: mesh leave request send successfully");
9451 }
9452
9453 if (wpa_driver_nl80211_set_mode(drv->first_bss,
9454 NL80211_IFTYPE_STATION)) {
9455 wpa_printf(MSG_INFO,
9456 "nl80211: Failed to set interface into station mode");
9457 }
9458 return ret;
9459}
9460
9461#endif /* CONFIG_MESH */
9462
9463
9464static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
9465 const u8 *ipaddr, int prefixlen,
9466 const u8 *addr)
9467{
9468#ifdef CONFIG_LIBNL3_ROUTE
9469 struct i802_bss *bss = priv;
9470 struct wpa_driver_nl80211_data *drv = bss->drv;
9471 struct rtnl_neigh *rn;
9472 struct nl_addr *nl_ipaddr = NULL;
9473 struct nl_addr *nl_lladdr = NULL;
9474 int family, addrsize;
9475 int res;
9476
9477 if (!ipaddr || prefixlen == 0 || !addr)
9478 return -EINVAL;
9479
9480 if (bss->br_ifindex == 0) {
9481 wpa_printf(MSG_DEBUG,
9482 "nl80211: bridge must be set before adding an ip neigh to it");
9483 return -1;
9484 }
9485
9486 if (!drv->rtnl_sk) {
9487 wpa_printf(MSG_DEBUG,
9488 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9489 return -1;
9490 }
9491
9492 if (version == 4) {
9493 family = AF_INET;
9494 addrsize = 4;
9495 } else if (version == 6) {
9496 family = AF_INET6;
9497 addrsize = 16;
9498 } else {
9499 return -EINVAL;
9500 }
9501
9502 rn = rtnl_neigh_alloc();
9503 if (rn == NULL)
9504 return -ENOMEM;
9505
9506 /* set the destination ip address for neigh */
9507 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
9508 if (nl_ipaddr == NULL) {
9509 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
9510 res = -ENOMEM;
9511 goto errout;
9512 }
9513 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
9514 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
9515 if (res) {
9516 wpa_printf(MSG_DEBUG,
9517 "nl80211: neigh set destination addr failed");
9518 goto errout;
9519 }
9520
9521 /* set the corresponding lladdr for neigh */
9522 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
9523 if (nl_lladdr == NULL) {
9524 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
9525 res = -ENOMEM;
9526 goto errout;
9527 }
9528 rtnl_neigh_set_lladdr(rn, nl_lladdr);
9529
9530 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
9531 rtnl_neigh_set_state(rn, NUD_PERMANENT);
9532
9533 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
9534 if (res) {
9535 wpa_printf(MSG_DEBUG,
9536 "nl80211: Adding bridge ip neigh failed: %s",
9537 strerror(errno));
9538 }
9539errout:
9540 if (nl_lladdr)
9541 nl_addr_put(nl_lladdr);
9542 if (nl_ipaddr)
9543 nl_addr_put(nl_ipaddr);
9544 if (rn)
9545 rtnl_neigh_put(rn);
9546 return res;
9547#else /* CONFIG_LIBNL3_ROUTE */
9548 return -1;
9549#endif /* CONFIG_LIBNL3_ROUTE */
9550}
9551
9552
9553static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
9554 const u8 *ipaddr)
9555{
9556#ifdef CONFIG_LIBNL3_ROUTE
9557 struct i802_bss *bss = priv;
9558 struct wpa_driver_nl80211_data *drv = bss->drv;
9559 struct rtnl_neigh *rn;
9560 struct nl_addr *nl_ipaddr;
9561 int family, addrsize;
9562 int res;
9563
9564 if (!ipaddr)
9565 return -EINVAL;
9566
9567 if (version == 4) {
9568 family = AF_INET;
9569 addrsize = 4;
9570 } else if (version == 6) {
9571 family = AF_INET6;
9572 addrsize = 16;
9573 } else {
9574 return -EINVAL;
9575 }
9576
9577 if (bss->br_ifindex == 0) {
9578 wpa_printf(MSG_DEBUG,
9579 "nl80211: bridge must be set to delete an ip neigh");
9580 return -1;
9581 }
9582
9583 if (!drv->rtnl_sk) {
9584 wpa_printf(MSG_DEBUG,
9585 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9586 return -1;
9587 }
9588
9589 rn = rtnl_neigh_alloc();
9590 if (rn == NULL)
9591 return -ENOMEM;
9592
9593 /* set the destination ip address for neigh */
9594 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
9595 if (nl_ipaddr == NULL) {
9596 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
9597 res = -ENOMEM;
9598 goto errout;
9599 }
9600 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
9601 if (res) {
9602 wpa_printf(MSG_DEBUG,
9603 "nl80211: neigh set destination addr failed");
9604 goto errout;
9605 }
9606
9607 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
9608
9609 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
9610 if (res) {
9611 wpa_printf(MSG_DEBUG,
9612 "nl80211: Deleting bridge ip neigh failed: %s",
9613 strerror(errno));
9614 }
9615errout:
9616 if (nl_ipaddr)
9617 nl_addr_put(nl_ipaddr);
9618 if (rn)
9619 rtnl_neigh_put(rn);
9620 return res;
9621#else /* CONFIG_LIBNL3_ROUTE */
9622 return -1;
9623#endif /* CONFIG_LIBNL3_ROUTE */
9624}
9625
9626
9627static int linux_write_system_file(const char *path, unsigned int val)
9628{
9629 char buf[50];
9630 int fd, len;
9631
9632 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
9633 if (os_snprintf_error(sizeof(buf), len))
9634 return -1;
9635
9636 fd = open(path, O_WRONLY);
9637 if (fd < 0)
9638 return -1;
9639
9640 if (write(fd, buf, len) < 0) {
9641 wpa_printf(MSG_DEBUG,
9642 "nl80211: Failed to write Linux system file: %s with the value of %d",
9643 path, val);
9644 close(fd);
9645 return -1;
9646 }
9647 close(fd);
9648
9649 return 0;
9650}
9651
9652
9653static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
9654{
9655 switch (attr) {
9656 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07009657 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009658 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
9659 return "hairpin_mode";
9660 }
9661
9662 return NULL;
9663}
9664
9665
9666static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
9667 unsigned int val)
9668{
9669 struct i802_bss *bss = priv;
9670 char path[128];
9671 const char *attr_txt;
9672
9673 attr_txt = drv_br_port_attr_str(attr);
9674 if (attr_txt == NULL)
9675 return -EINVAL;
9676
9677 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
9678 bss->ifname, attr_txt);
9679
9680 if (linux_write_system_file(path, val))
9681 return -1;
9682
9683 return 0;
9684}
9685
9686
9687static const char * drv_br_net_param_str(enum drv_br_net_param param)
9688{
9689 switch (param) {
9690 case DRV_BR_NET_PARAM_GARP_ACCEPT:
9691 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -07009692 default:
9693 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009694 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009695}
9696
9697
9698static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
9699 unsigned int val)
9700{
9701 struct i802_bss *bss = priv;
9702 char path[128];
9703 const char *param_txt;
9704 int ip_version = 4;
9705
Dmitry Shmidt83474442015-04-15 13:47:09 -07009706 if (param == DRV_BR_MULTICAST_SNOOPING) {
9707 os_snprintf(path, sizeof(path),
9708 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
9709 bss->brname);
9710 goto set_val;
9711 }
9712
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009713 param_txt = drv_br_net_param_str(param);
9714 if (param_txt == NULL)
9715 return -EINVAL;
9716
9717 switch (param) {
9718 case DRV_BR_NET_PARAM_GARP_ACCEPT:
9719 ip_version = 4;
9720 break;
9721 default:
9722 return -EINVAL;
9723 }
9724
9725 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
9726 ip_version, bss->brname, param_txt);
9727
Dmitry Shmidt83474442015-04-15 13:47:09 -07009728set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009729 if (linux_write_system_file(path, val))
9730 return -1;
9731
9732 return 0;
9733}
9734
9735
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009736#ifdef CONFIG_DRIVER_NL80211_QCA
9737
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009738static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
9739{
9740 switch (hw_mode) {
9741 case HOSTAPD_MODE_IEEE80211B:
9742 return QCA_ACS_MODE_IEEE80211B;
9743 case HOSTAPD_MODE_IEEE80211G:
9744 return QCA_ACS_MODE_IEEE80211G;
9745 case HOSTAPD_MODE_IEEE80211A:
9746 return QCA_ACS_MODE_IEEE80211A;
9747 case HOSTAPD_MODE_IEEE80211AD:
9748 return QCA_ACS_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07009749 case HOSTAPD_MODE_IEEE80211ANY:
9750 return QCA_ACS_MODE_IEEE80211ANY;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009751 default:
9752 return -1;
9753 }
9754}
9755
9756
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009757static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
9758{
9759 int i, len, ret;
9760 u32 *freqs;
9761
9762 if (!freq_list)
9763 return 0;
9764 len = int_array_len(freq_list);
9765 freqs = os_malloc(sizeof(u32) * len);
9766 if (!freqs)
9767 return -1;
9768 for (i = 0; i < len; i++)
9769 freqs[i] = freq_list[i];
9770 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
9771 sizeof(u32) * len, freqs);
9772 os_free(freqs);
9773 return ret;
9774}
9775
9776
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009777static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
9778{
9779 struct i802_bss *bss = priv;
9780 struct wpa_driver_nl80211_data *drv = bss->drv;
9781 struct nl_msg *msg;
9782 struct nlattr *data;
9783 int ret;
9784 int mode;
9785
9786 mode = hw_mode_to_qca_acs(params->hw_mode);
9787 if (mode < 0)
9788 return -1;
9789
9790 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9791 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9792 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9793 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
9794 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9795 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
9796 (params->ht_enabled &&
9797 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
9798 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009799 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
9800 (params->vht_enabled &&
9801 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
9802 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
9803 params->ch_width) ||
9804 (params->ch_list_len &&
9805 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009806 params->ch_list)) ||
9807 add_acs_freq_list(msg, params->freq_list)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009808 nlmsg_free(msg);
9809 return -ENOBUFS;
9810 }
9811 nla_nest_end(msg, data);
9812
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009813 wpa_printf(MSG_DEBUG,
9814 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
9815 params->hw_mode, params->ht_enabled, params->ht40_enabled,
9816 params->vht_enabled, params->ch_width, params->ch_list_len);
9817
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009818 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9819 if (ret) {
9820 wpa_printf(MSG_DEBUG,
9821 "nl80211: Failed to invoke driver ACS function: %s",
9822 strerror(errno));
9823 }
9824 return ret;
9825}
9826
9827
Ravi Joshie6ccb162015-07-16 17:45:41 -07009828static int nl80211_set_band(void *priv, enum set_band band)
9829{
9830 struct i802_bss *bss = priv;
9831 struct wpa_driver_nl80211_data *drv = bss->drv;
9832 struct nl_msg *msg;
9833 struct nlattr *data;
9834 int ret;
9835 enum qca_set_band qca_band;
9836
9837 if (!drv->setband_vendor_cmd_avail)
9838 return -1;
9839
9840 switch (band) {
9841 case WPA_SETBAND_AUTO:
9842 qca_band = QCA_SETBAND_AUTO;
9843 break;
9844 case WPA_SETBAND_5G:
9845 qca_band = QCA_SETBAND_5G;
9846 break;
9847 case WPA_SETBAND_2G:
9848 qca_band = QCA_SETBAND_2G;
9849 break;
9850 default:
9851 return -1;
9852 }
9853
9854 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9855 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9856 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9857 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
9858 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9859 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
9860 nlmsg_free(msg);
9861 return -ENOBUFS;
9862 }
9863 nla_nest_end(msg, data);
9864
9865 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9866 if (ret) {
9867 wpa_printf(MSG_DEBUG,
9868 "nl80211: Driver setband function failed: %s",
9869 strerror(errno));
9870 }
9871 return ret;
9872}
9873
9874
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009875struct nl80211_pcl {
9876 unsigned int num;
9877 unsigned int *freq_list;
9878};
9879
9880static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
9881{
9882 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9883 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9884 struct nl80211_pcl *param = arg;
9885 struct nlattr *nl_vend, *attr;
9886 enum qca_iface_type iface_type;
9887 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
9888 unsigned int num, max_num;
9889 u32 *freqs;
9890
9891 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9892 genlmsg_attrlen(gnlh, 0), NULL);
9893
9894 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
9895 if (!nl_vend)
9896 return NL_SKIP;
9897
9898 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
9899 nla_data(nl_vend), nla_len(nl_vend), NULL);
9900
9901 attr = tb_vendor[
9902 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
9903 if (!attr) {
9904 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
9905 param->num = 0;
9906 return NL_SKIP;
9907 }
9908
9909 iface_type = (enum qca_iface_type) nla_get_u32(attr);
9910 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
9911 iface_type);
9912
9913 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
9914 if (!attr) {
9915 wpa_printf(MSG_ERROR,
9916 "nl80211: preferred_freq_list couldn't be found");
9917 param->num = 0;
9918 return NL_SKIP;
9919 }
9920
9921 /*
9922 * param->num has the maximum number of entries for which there
9923 * is room in the freq_list provided by the caller.
9924 */
9925 freqs = nla_data(attr);
9926 max_num = nla_len(attr) / sizeof(u32);
9927 if (max_num > param->num)
9928 max_num = param->num;
9929 for (num = 0; num < max_num; num++)
9930 param->freq_list[num] = freqs[num];
9931 param->num = num;
9932
9933 return NL_SKIP;
9934}
9935
9936
9937static int nl80211_get_pref_freq_list(void *priv,
9938 enum wpa_driver_if_type if_type,
9939 unsigned int *num,
9940 unsigned int *freq_list)
9941{
9942 struct i802_bss *bss = priv;
9943 struct wpa_driver_nl80211_data *drv = bss->drv;
9944 struct nl_msg *msg;
9945 int ret;
9946 unsigned int i;
9947 struct nlattr *params;
9948 struct nl80211_pcl param;
9949 enum qca_iface_type iface_type;
9950
9951 if (!drv->get_pref_freq_list)
9952 return -1;
9953
9954 switch (if_type) {
9955 case WPA_IF_STATION:
9956 iface_type = QCA_IFACE_TYPE_STA;
9957 break;
9958 case WPA_IF_AP_BSS:
9959 iface_type = QCA_IFACE_TYPE_AP;
9960 break;
9961 case WPA_IF_P2P_GO:
9962 iface_type = QCA_IFACE_TYPE_P2P_GO;
9963 break;
9964 case WPA_IF_P2P_CLIENT:
9965 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
9966 break;
9967 case WPA_IF_IBSS:
9968 iface_type = QCA_IFACE_TYPE_IBSS;
9969 break;
9970 case WPA_IF_TDLS:
9971 iface_type = QCA_IFACE_TYPE_TDLS;
9972 break;
9973 default:
9974 return -1;
9975 }
9976
9977 param.num = *num;
9978 param.freq_list = freq_list;
9979
9980 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9981 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
9982 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9983 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9984 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
9985 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9986 nla_put_u32(msg,
9987 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
9988 iface_type)) {
9989 wpa_printf(MSG_ERROR,
9990 "%s: err in adding vendor_cmd and vendor_data",
9991 __func__);
9992 nlmsg_free(msg);
9993 return -1;
9994 }
9995 nla_nest_end(msg, params);
9996
9997 os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
9998 ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
9999 if (ret) {
10000 wpa_printf(MSG_ERROR,
10001 "%s: err in send_and_recv_msgs", __func__);
10002 return ret;
10003 }
10004
10005 *num = param.num;
10006
10007 for (i = 0; i < *num; i++) {
10008 wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
10009 i, freq_list[i]);
10010 }
10011
10012 return 0;
10013}
10014
10015
10016static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
10017{
10018 struct i802_bss *bss = priv;
10019 struct wpa_driver_nl80211_data *drv = bss->drv;
10020 struct nl_msg *msg;
10021 int ret;
10022 struct nlattr *params;
10023
10024 if (!drv->set_prob_oper_freq)
10025 return -1;
10026
10027 wpa_printf(MSG_DEBUG,
10028 "nl80211: Set P2P probable operating freq %u for ifindex %d",
10029 freq, bss->ifindex);
10030
10031 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10032 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10033 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10034 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
10035 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10036 nla_put_u32(msg,
10037 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
10038 QCA_IFACE_TYPE_P2P_CLIENT) ||
10039 nla_put_u32(msg,
10040 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
10041 freq)) {
10042 wpa_printf(MSG_ERROR,
10043 "%s: err in adding vendor_cmd and vendor_data",
10044 __func__);
10045 nlmsg_free(msg);
10046 return -1;
10047 }
10048 nla_nest_end(msg, params);
10049
10050 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10051 msg = NULL;
10052 if (ret) {
10053 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
10054 __func__);
10055 return ret;
10056 }
10057 nlmsg_free(msg);
10058 return 0;
10059}
10060
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010061
10062static int nl80211_p2p_lo_start(void *priv, unsigned int freq,
10063 unsigned int period, unsigned int interval,
10064 unsigned int count, const u8 *device_types,
10065 size_t dev_types_len,
10066 const u8 *ies, size_t ies_len)
10067{
10068 struct i802_bss *bss = priv;
10069 struct wpa_driver_nl80211_data *drv = bss->drv;
10070 struct nl_msg *msg;
10071 struct nlattr *container;
10072 int ret;
10073
10074 wpa_printf(MSG_DEBUG,
10075 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
10076 freq, period, interval, count);
10077
10078 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10079 return -1;
10080
10081 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10082 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10083 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10084 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START))
10085 goto fail;
10086
10087 container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10088 if (!container)
10089 goto fail;
10090
10091 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL,
10092 freq) ||
10093 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD,
10094 period) ||
10095 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL,
10096 interval) ||
10097 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT,
10098 count) ||
10099 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES,
10100 dev_types_len, device_types) ||
10101 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE,
10102 ies_len, ies))
10103 goto fail;
10104
10105 nla_nest_end(msg, container);
10106 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10107 msg = NULL;
10108 if (ret) {
10109 wpa_printf(MSG_DEBUG,
10110 "nl80211: Failed to send P2P Listen offload vendor command");
10111 goto fail;
10112 }
10113
10114 return 0;
10115
10116fail:
10117 nlmsg_free(msg);
10118 return -1;
10119}
10120
10121
10122static int nl80211_p2p_lo_stop(void *priv)
10123{
10124 struct i802_bss *bss = priv;
10125 struct wpa_driver_nl80211_data *drv = bss->drv;
10126 struct nl_msg *msg;
10127
10128 wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload");
10129
10130 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10131 return -1;
10132
10133 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10134 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10135 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10136 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) {
10137 nlmsg_free(msg);
10138 return -1;
10139 }
10140
10141 return send_and_recv_msgs(drv, msg, NULL, NULL);
10142}
10143
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080010144
10145static int nl80211_set_tdls_mode(void *priv, int tdls_external_control)
10146{
10147 struct i802_bss *bss = priv;
10148 struct wpa_driver_nl80211_data *drv = bss->drv;
10149 struct nl_msg *msg;
10150 struct nlattr *params;
10151 int ret;
10152 u32 tdls_mode;
10153
10154 wpa_printf(MSG_DEBUG,
10155 "nl80211: Set TDKS mode: tdls_external_control=%d",
10156 tdls_external_control);
10157
10158 if (tdls_external_control == 1)
10159 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT |
10160 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL;
10161 else
10162 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT;
10163
10164 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10165 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10166 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10167 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS))
10168 goto fail;
10169
10170 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10171 if (!params)
10172 goto fail;
10173
10174 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE,
10175 tdls_mode))
10176 goto fail;
10177
10178 nla_nest_end(msg, params);
10179
10180 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10181 msg = NULL;
10182 if (ret) {
10183 wpa_printf(MSG_ERROR,
10184 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10185 ret, strerror(-ret));
10186 goto fail;
10187 }
10188 return 0;
10189fail:
10190 nlmsg_free(msg);
10191 return -1;
10192}
10193
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010194
10195#ifdef CONFIG_MBO
10196
10197static enum mbo_transition_reject_reason
10198nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status)
10199{
10200 switch (status) {
10201 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED:
10202 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS;
10203 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED:
10204 return MBO_TRANSITION_REJECT_REASON_DELAY;
10205 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY:
10206 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY;
10207 case QCA_STATUS_REJECT_LOW_RSSI:
10208 return MBO_TRANSITION_REJECT_REASON_RSSI;
10209 case QCA_STATUS_REJECT_HIGH_INTERFERENCE:
10210 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE;
10211 case QCA_STATUS_REJECT_UNKNOWN:
10212 default:
10213 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
10214 }
10215}
10216
10217
10218static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate,
10219 struct nlattr *tb[], int num)
10220{
10221 enum qca_wlan_btm_candidate_status status;
10222 char buf[50];
10223
10224 os_memcpy(candidate->bssid,
10225 nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]),
10226 ETH_ALEN);
10227
10228 status = nla_get_u32(
10229 tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]);
10230 candidate->is_accept = status == QCA_STATUS_ACCEPT;
10231 candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status);
10232
10233 if (candidate->is_accept)
10234 os_snprintf(buf, sizeof(buf), "Accepted");
10235 else
10236 os_snprintf(buf, sizeof(buf),
10237 "Rejected, Reject_reason: %d",
10238 candidate->reject_reason);
10239 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s",
10240 num, MAC2STR(candidate->bssid), buf);
10241}
10242
10243
10244static int
10245nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg)
10246{
10247 struct wpa_bss_candidate_info *info = arg;
10248 struct candidate_list *candidate = info->candidates;
10249 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
10250 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10251 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1];
10252 static struct nla_policy policy[
10253 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = {
10254 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = {
10255 .minlen = ETH_ALEN
10256 },
10257 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = {
10258 .type = NLA_U32,
10259 },
10260 };
10261 struct nlattr *attr;
10262 int rem;
10263 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10264 u8 num;
10265
10266 num = info->num; /* number of candidates sent to driver */
10267 info->num = 0;
10268 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10269 genlmsg_attrlen(gnlh, 0), NULL);
10270
10271 if (!tb_msg[NL80211_ATTR_VENDOR_DATA] ||
10272 nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10273 tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) ||
10274 !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO])
10275 return NL_SKIP;
10276
10277 wpa_printf(MSG_DEBUG,
10278 "nl80211: WNM Candidate list received from driver");
10279 nla_for_each_nested(attr,
10280 tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO],
10281 rem) {
10282 if (info->num >= num ||
10283 nla_parse_nested(
10284 tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX,
10285 attr, policy) ||
10286 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] ||
10287 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS])
10288 break;
10289
10290 nl80211_parse_btm_candidate_info(candidate, tb, info->num);
10291
10292 candidate++;
10293 info->num++;
10294 }
10295
10296 return NL_SKIP;
10297}
10298
10299
10300static struct wpa_bss_candidate_info *
10301nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params)
10302{
10303 struct i802_bss *bss = priv;
10304 struct wpa_driver_nl80211_data *drv = bss->drv;
10305 struct nl_msg *msg;
10306 struct nlattr *attr, *attr1, *attr2;
10307 struct wpa_bss_candidate_info *info;
10308 u8 i;
10309 int ret;
10310 u8 *pos;
10311
10312 if (!drv->fetch_bss_trans_status)
10313 return NULL;
10314
10315 info = os_zalloc(sizeof(*info));
10316 if (!info)
10317 return NULL;
10318 /* Allocate memory for number of candidates sent to driver */
10319 info->candidates = os_calloc(params->n_candidates,
10320 sizeof(*info->candidates));
10321 if (!info->candidates) {
10322 os_free(info);
10323 return NULL;
10324 }
10325
10326 /* Copy the number of candidates being sent to driver. This is used in
10327 * nl80211_get_bss_transition_status_handler() to limit the number of
10328 * candidates that can be populated in info->candidates and will be
10329 * later overwritten with the actual number of candidates received from
10330 * the driver.
10331 */
10332 info->num = params->n_candidates;
10333
10334 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10335 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10336 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10337 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS))
10338 goto fail;
10339
10340 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10341 if (!attr)
10342 goto fail;
10343
10344 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON,
10345 params->mbo_transition_reason))
10346 goto fail;
10347
10348 attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO);
10349 if (!attr1)
10350 goto fail;
10351
10352 wpa_printf(MSG_DEBUG,
10353 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
10354 params->mbo_transition_reason, params->n_candidates);
10355 pos = params->bssid;
10356 for (i = 0; i < params->n_candidates; i++) {
10357 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i,
10358 MAC2STR(pos));
10359 attr2 = nla_nest_start(msg, i);
10360 if (!attr2 ||
10361 nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID,
10362 ETH_ALEN, pos))
10363 goto fail;
10364 pos += ETH_ALEN;
10365 nla_nest_end(msg, attr2);
10366 }
10367
10368 nla_nest_end(msg, attr1);
10369 nla_nest_end(msg, attr);
10370
10371 ret = send_and_recv_msgs(drv, msg,
10372 nl80211_get_bss_transition_status_handler,
10373 info);
10374 msg = NULL;
10375 if (ret) {
10376 wpa_printf(MSG_ERROR,
10377 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
10378 ret, strerror(-ret));
10379 goto fail;
10380 }
10381 return info;
10382
10383fail:
10384 nlmsg_free(msg);
10385 os_free(info->candidates);
10386 os_free(info);
10387 return NULL;
10388}
10389
10390
10391/**
10392 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
10393 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
10394 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
10395 * Returns: 0 on success, -1 on failure
10396 */
10397static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow)
10398{
10399 struct i802_bss *bss = priv;
10400 struct wpa_driver_nl80211_data *drv = bss->drv;
10401 struct nl_msg *msg;
10402 struct nlattr *attr;
10403 int ret = -1;
10404
10405 if (!drv->set_wifi_conf_vendor_cmd_avail)
10406 return -1;
10407
10408 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10409 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10410 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10411 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION))
10412 goto fail;
10413
10414 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10415 if (!attr)
10416 goto fail;
10417
10418 wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d",
10419 ignore_disallow);
10420 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED,
10421 ignore_disallow))
10422 goto fail;
10423
10424 nla_nest_end(msg, attr);
10425
10426 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10427 msg = NULL;
10428 if (ret) {
10429 wpa_printf(MSG_ERROR,
10430 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
10431 ret, strerror(-ret));
10432 goto fail;
10433 }
10434
10435fail:
10436 nlmsg_free(msg);
10437 return ret;
10438}
10439
10440#endif /* CONFIG_MBO */
10441
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010442#endif /* CONFIG_DRIVER_NL80211_QCA */
10443
10444
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010445static int nl80211_write_to_file(const char *name, unsigned int val)
10446{
10447 int fd, len;
10448 char tmp[128];
10449
10450 fd = open(name, O_RDWR);
10451 if (fd < 0) {
10452 wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s",
10453 name, strerror(errno));
10454 return fd;
10455 }
10456
10457 len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
10458 len = write(fd, tmp, len);
10459 if (len < 0)
10460 wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
10461 name, strerror(errno));
10462 close(fd);
10463
10464 return 0;
10465}
10466
10467
10468static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags)
10469{
10470 struct i802_bss *bss = priv;
10471 char path[128];
10472 int ret;
10473
10474 wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x",
10475 filter_flags);
10476
10477 /* Configure filtering of unicast frame encrypted using GTK */
10478 ret = os_snprintf(path, sizeof(path),
10479 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
10480 bss->ifname);
10481 if (os_snprintf_error(sizeof(path), ret))
10482 return -1;
10483
10484 ret = nl80211_write_to_file(path,
10485 !!(filter_flags &
10486 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10487 if (ret) {
10488 wpa_printf(MSG_ERROR,
10489 "nl80211: Failed to set IPv4 unicast in multicast filter");
10490 return ret;
10491 }
10492
10493 os_snprintf(path, sizeof(path),
10494 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
10495 bss->ifname);
10496 ret = nl80211_write_to_file(path,
10497 !!(filter_flags &
10498 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10499
10500 if (ret) {
10501 wpa_printf(MSG_ERROR,
10502 "nl80211: Failed to set IPv6 unicast in multicast filter");
10503 return ret;
10504 }
10505
10506 /* Configure filtering of unicast frame encrypted using GTK */
10507 os_snprintf(path, sizeof(path),
10508 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
10509 bss->ifname);
10510 ret = nl80211_write_to_file(path,
10511 !!(filter_flags &
10512 WPA_DATA_FRAME_FILTER_FLAG_ARP));
10513 if (ret) {
10514 wpa_printf(MSG_ERROR,
10515 "nl80211: Failed set gratuitous ARP filter");
10516 return ret;
10517 }
10518
10519 /* Configure filtering of IPv6 NA frames */
10520 os_snprintf(path, sizeof(path),
10521 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
10522 bss->ifname);
10523 ret = nl80211_write_to_file(path,
10524 !!(filter_flags &
10525 WPA_DATA_FRAME_FILTER_FLAG_NA));
10526 if (ret) {
10527 wpa_printf(MSG_ERROR,
10528 "nl80211: Failed to set unsolicited NA filter");
10529 return ret;
10530 }
10531
10532 return 0;
10533}
10534
10535
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070010536static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type,
10537 const u8 **ext_capa, const u8 **ext_capa_mask,
10538 unsigned int *ext_capa_len)
10539{
10540 struct i802_bss *bss = priv;
10541 struct wpa_driver_nl80211_data *drv = bss->drv;
10542 enum nl80211_iftype nlmode;
10543 unsigned int i;
10544
10545 if (!ext_capa || !ext_capa_mask || !ext_capa_len)
10546 return -1;
10547
10548 nlmode = wpa_driver_nl80211_if_type(type);
10549
10550 /* By default, use the per-radio values */
10551 *ext_capa = drv->extended_capa;
10552 *ext_capa_mask = drv->extended_capa_mask;
10553 *ext_capa_len = drv->extended_capa_len;
10554
10555 /* Replace the default value if a per-interface type value exists */
10556 for (i = 0; i < drv->num_iface_ext_capa; i++) {
10557 if (nlmode == drv->iface_ext_capa[i].iftype) {
10558 *ext_capa = drv->iface_ext_capa[i].ext_capa;
10559 *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask;
10560 *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len;
10561 break;
10562 }
10563 }
10564
10565 return 0;
10566}
10567
10568
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010569static int nl80211_update_connection_params(
10570 void *priv, struct wpa_driver_associate_params *params,
10571 enum wpa_drv_update_connect_params_mask mask)
10572{
10573 struct i802_bss *bss = priv;
10574 struct wpa_driver_nl80211_data *drv = bss->drv;
10575 struct nl_msg *msg;
10576 int ret = -1;
10577 enum nl80211_auth_type type;
10578
10579 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS);
10580 if (!msg)
10581 goto fail;
10582
10583 wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)",
10584 drv->ifindex);
10585
10586 if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) {
10587 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
10588 params->wpa_ie))
10589 goto fail;
10590 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie,
10591 params->wpa_ie_len);
10592 }
10593
10594 if (mask & WPA_DRV_UPDATE_AUTH_TYPE) {
10595 type = get_nl_auth_type(params->auth_alg);
10596 if (type == NL80211_AUTHTYPE_MAX ||
10597 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
10598 goto fail;
10599 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
10600 }
10601
10602 if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) &&
10603 nl80211_put_fils_connect_params(drv, params, msg))
10604 goto fail;
10605
10606 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10607 msg = NULL;
10608 if (ret)
10609 wpa_dbg(drv->ctx, MSG_DEBUG,
10610 "nl80211: Update connect params command failed: ret=%d (%s)",
10611 ret, strerror(-ret));
10612
10613fail:
10614 nlmsg_free(msg);
10615 return ret;
10616}
10617
10618
Roshan Pius3a1667e2018-07-03 15:17:14 -070010619static int nl80211_send_external_auth_status(void *priv,
10620 struct external_auth *params)
10621{
10622 struct i802_bss *bss = priv;
10623 struct wpa_driver_nl80211_data *drv = bss->drv;
10624 struct nl_msg *msg = NULL;
10625 int ret = -1;
10626
10627 wpa_dbg(drv->ctx, MSG_DEBUG,
10628 "nl80211: External auth status: %u", params->status);
10629
10630 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH);
10631 if (!msg ||
10632 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) ||
10633 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
10634 params->ssid) ||
10635 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))
10636 goto fail;
10637 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10638 msg = NULL;
10639 if (ret) {
10640 wpa_printf(MSG_DEBUG,
10641 "nl80211: External Auth status update failed: ret=%d (%s)",
10642 ret, strerror(-ret));
10643 goto fail;
10644 }
10645fail:
10646 nlmsg_free(msg);
10647 return ret;
10648}
10649
10650
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010651const struct wpa_driver_ops wpa_driver_nl80211_ops = {
10652 .name = "nl80211",
10653 .desc = "Linux nl80211/cfg80211",
10654 .get_bssid = wpa_driver_nl80211_get_bssid,
10655 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010656 .set_key = driver_nl80211_set_key,
10657 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010658 .sched_scan = wpa_driver_nl80211_sched_scan,
10659 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010660 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010661 .abort_scan = wpa_driver_nl80211_abort_scan,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010662 .deauthenticate = driver_nl80211_deauthenticate,
10663 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010664 .associate = wpa_driver_nl80211_associate,
10665 .global_init = nl80211_global_init,
10666 .global_deinit = nl80211_global_deinit,
10667 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010668 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010669 .get_capa = wpa_driver_nl80211_get_capa,
10670 .set_operstate = wpa_driver_nl80211_set_operstate,
10671 .set_supp_port = wpa_driver_nl80211_set_supp_port,
10672 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -080010673 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010674 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -070010675 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010676 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010677 .if_remove = driver_nl80211_if_remove,
10678 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010679 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010680 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010681 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010682 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
10683 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010684 .hapd_init = i802_init,
10685 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -070010686 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010687 .get_seqnum = i802_get_seqnum,
10688 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010689 .get_inact_sec = i802_get_inact_sec,
10690 .sta_clear_stats = i802_sta_clear_stats,
10691 .set_rts = i802_set_rts,
10692 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010693 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010694 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010695 .sta_deauth = i802_sta_deauth,
10696 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010697 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010698 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010699 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010700 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
10701 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
10702 .cancel_remain_on_channel =
10703 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010704 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010705 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -070010706 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010707 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010708 .signal_monitor = nl80211_signal_monitor,
10709 .signal_poll = nl80211_signal_poll,
10710 .send_frame = nl80211_send_frame,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010711 .set_param = nl80211_set_param,
10712 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -070010713 .add_pmkid = nl80211_add_pmkid,
10714 .remove_pmkid = nl80211_remove_pmkid,
10715 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010716 .set_rekey_info = nl80211_set_rekey_info,
10717 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010718 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010719 .start_dfs_cac = nl80211_start_radar_detection,
10720 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010721#ifdef CONFIG_TDLS
10722 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
10723 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010724 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
10725 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010726#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010727 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -070010728 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010729 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -070010730 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010731 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010732#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070010733 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010734 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070010735 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010736#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070010737#ifdef ANDROID
Dmitry Shmidt41712582015-06-29 11:02:15 -070010738#ifndef ANDROID_LIB_STUB
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070010739 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt41712582015-06-29 11:02:15 -070010740#endif /* !ANDROID_LIB_STUB */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010741#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080010742 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010743 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070010744 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070010745 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010746#ifdef CONFIG_MESH
10747 .init_mesh = wpa_driver_nl80211_init_mesh,
10748 .join_mesh = wpa_driver_nl80211_join_mesh,
10749 .leave_mesh = wpa_driver_nl80211_leave_mesh,
10750#endif /* CONFIG_MESH */
10751 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
10752 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
10753 .br_port_set_attr = wpa_driver_br_port_set_attr,
10754 .br_set_net_param = wpa_driver_br_set_net_param,
10755 .add_tx_ts = nl80211_add_ts,
10756 .del_tx_ts = nl80211_del_ts,
Dmitry Shmidte4663042016-04-04 10:07:49 -070010757 .get_ifindex = nl80211_get_ifindex,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010758#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010759 .roaming = nl80211_roaming,
Roshan Pius3a1667e2018-07-03 15:17:14 -070010760 .disable_fils = nl80211_disable_fils,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010761 .do_acs = wpa_driver_do_acs,
Ravi Joshie6ccb162015-07-16 17:45:41 -070010762 .set_band = nl80211_set_band,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010763 .get_pref_freq_list = nl80211_get_pref_freq_list,
10764 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010765 .p2p_lo_start = nl80211_p2p_lo_start,
10766 .p2p_lo_stop = nl80211_p2p_lo_stop,
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010767 .set_default_scan_ies = nl80211_set_default_scan_ies,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080010768 .set_tdls_mode = nl80211_set_tdls_mode,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010769#ifdef CONFIG_MBO
10770 .get_bss_transition_status = nl80211_get_bss_transition_status,
10771 .ignore_assoc_disallow = nl80211_ignore_assoc_disallow,
10772#endif /* CONFIG_MBO */
10773 .set_bssid_blacklist = nl80211_set_bssid_blacklist,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010774#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010775 .configure_data_frame_filters = nl80211_configure_data_frame_filters,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070010776 .get_ext_capab = nl80211_get_ext_capab,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010777 .update_connect_params = nl80211_update_connection_params,
Roshan Pius3a1667e2018-07-03 15:17:14 -070010778 .send_external_auth_status = nl80211_send_external_auth_status,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010779};