blob: b7efb6a3b864d51a3cb2ba8c9e8e8cb952bcec1d [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 Shalom74f70d42019-02-11 14:42:39 -080043#ifndef NETLINK_CAP_ACK
44#define NETLINK_CAP_ACK 10
45#endif /* NETLINK_CAP_ACK */
Hai Shalom39ba6fc2019-01-22 12:40:38 -080046/* support for extack if compilation headers are too old */
47#ifndef NETLINK_EXT_ACK
48#define NETLINK_EXT_ACK 11
49enum nlmsgerr_attrs {
50 NLMSGERR_ATTR_UNUSED,
51 NLMSGERR_ATTR_MSG,
52 NLMSGERR_ATTR_OFFS,
53 NLMSGERR_ATTR_COOKIE,
54
55 __NLMSGERR_ATTR_MAX,
56 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
57};
58#endif
59#ifndef NLM_F_CAPPED
60#define NLM_F_CAPPED 0x100
61#endif
62#ifndef NLM_F_ACK_TLVS
63#define NLM_F_ACK_TLVS 0x200
64#endif
65#ifndef SOL_NETLINK
66#define SOL_NETLINK 270
67#endif
68
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080069#ifndef CONFIG_LIBNL20
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070070/*
71 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
72 * but when you free a socket again it will mess up its bitmap and
73 * and use the wrong number the next time it needs a socket ID.
74 * Therefore, we wrap the handle alloc/destroy and add our own pid
75 * accounting.
76 */
77static uint32_t port_bitmap[32] = { 0 };
78
79static struct nl_handle *nl80211_handle_alloc(void *cb)
80{
81 struct nl_handle *handle;
82 uint32_t pid = getpid() & 0x3FFFFF;
83 int i;
84
85 handle = nl_handle_alloc_cb(cb);
86
87 for (i = 0; i < 1024; i++) {
88 if (port_bitmap[i / 32] & (1 << (i % 32)))
89 continue;
90 port_bitmap[i / 32] |= 1 << (i % 32);
91 pid += i << 22;
92 break;
93 }
94
95 nl_socket_set_local_port(handle, pid);
96
97 return handle;
98}
99
100static void nl80211_handle_destroy(struct nl_handle *handle)
101{
102 uint32_t port = nl_socket_get_local_port(handle);
103
104 port >>= 22;
105 port_bitmap[port / 32] &= ~(1 << (port % 32));
106
107 nl_handle_destroy(handle);
108}
109#endif /* CONFIG_LIBNL20 */
110
111
Dmitry Shmidt54605472013-11-08 11:10:19 -0800112#ifdef ANDROID
113/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -0800114#undef nl_socket_set_nonblocking
115#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800116
Dmitry Shmidt54605472013-11-08 11:10:19 -0800117#endif /* ANDROID */
118
119
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800120static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
121{
122 struct nl_handle *handle;
123
124 handle = nl80211_handle_alloc(cb);
125 if (handle == NULL) {
126 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
127 "callbacks (%s)", dbg);
128 return NULL;
129 }
130
131 if (genl_connect(handle)) {
132 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
133 "netlink (%s)", dbg);
134 nl80211_handle_destroy(handle);
135 return NULL;
136 }
137
138 return handle;
139}
140
141
142static void nl_destroy_handles(struct nl_handle **handle)
143{
144 if (*handle == NULL)
145 return;
146 nl80211_handle_destroy(*handle);
147 *handle = NULL;
148}
149
150
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151#if __WORDSIZE == 64
152#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
153#else
154#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
155#endif
156
157static void nl80211_register_eloop_read(struct nl_handle **handle,
158 eloop_sock_handler handler,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700159 void *eloop_data, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700160{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800161#ifdef CONFIG_LIBNL20
162 /*
163 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
164 * by default. It is possible to hit that limit in some cases where
165 * operations are blocked, e.g., with a burst of Deauthentication frames
166 * to hostapd and STA entry deletion. Try to increase the buffer to make
167 * this less likely to occur.
168 */
169 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
170 wpa_printf(MSG_DEBUG,
171 "nl80211: Could not set nl_socket RX buffer size: %s",
172 strerror(errno));
173 /* continue anyway with the default (smaller) buffer */
174 }
175#endif /* CONFIG_LIBNL20 */
176
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700177 nl_socket_set_nonblocking(*handle);
178 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
179 eloop_data, *handle);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700180 if (!persist)
181 *handle = (void *) (((intptr_t) *handle) ^
182 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700183}
184
185
Roshan Pius3a1667e2018-07-03 15:17:14 -0700186static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700187{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700188 if (!persist)
189 *handle = (void *) (((intptr_t) *handle) ^
190 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700191 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
192 nl_destroy_handles(handle);
193}
194
195
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800196static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800197static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800198
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800199static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700200static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
201 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800204wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800205 const u8 *set_addr, int first,
206 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800207static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800209 const u8 *buf, size_t buf_len, u64 *cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800210 int no_cck, int no_ack, int offchanok,
211 const u16 *csa_offs, size_t csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800212static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
213 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800215#define IFIDX_ANY -1
216
217static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
218 int ifidx_reason);
219static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
220 int ifidx_reason);
221static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
222 int ifidx_reason);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700223
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700224static int nl80211_set_channel(struct i802_bss *bss,
225 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
227 int ifindex, int disabled);
228
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800229static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
230 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800231
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700232static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800233static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700234#ifdef CONFIG_MESH
235static int nl80211_put_mesh_config(struct nl_msg *msg,
236 struct wpa_driver_mesh_bss_params *params);
237#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -0800238static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -0700239 u16 reason);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700240
241
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800242/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800243enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800244{
245 switch (width) {
246 case NL80211_CHAN_WIDTH_20_NOHT:
247 return CHAN_WIDTH_20_NOHT;
248 case NL80211_CHAN_WIDTH_20:
249 return CHAN_WIDTH_20;
250 case NL80211_CHAN_WIDTH_40:
251 return CHAN_WIDTH_40;
252 case NL80211_CHAN_WIDTH_80:
253 return CHAN_WIDTH_80;
254 case NL80211_CHAN_WIDTH_80P80:
255 return CHAN_WIDTH_80P80;
256 case NL80211_CHAN_WIDTH_160:
257 return CHAN_WIDTH_160;
258 }
259 return CHAN_WIDTH_UNKNOWN;
260}
261
262
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800263int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700265 return nlmode == NL80211_IFTYPE_AP ||
266 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800267}
268
269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800270int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800271{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700272 return nlmode == NL80211_IFTYPE_STATION ||
273 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800274}
275
276
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700277static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700279 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
280 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800281}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282
283
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800284struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
285 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700286{
287 struct i802_bss *bss;
288
289 for (bss = drv->first_bss; bss; bss = bss->next) {
290 if (bss->ifindex == ifindex)
291 return bss;
292 }
293
294 return NULL;
295}
296
297
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800298static int is_mesh_interface(enum nl80211_iftype nlmode)
299{
300 return nlmode == NL80211_IFTYPE_MESH_POINT;
301}
302
303
304void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700305{
306 if (drv->associated)
307 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
308 drv->associated = 0;
309 os_memset(drv->bssid, 0, ETH_ALEN);
Hai Shalom5f92bc92019-04-18 11:54:11 -0700310 drv->first_bss->freq = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700311}
312
313
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314/* nl80211 code */
315static int ack_handler(struct nl_msg *msg, void *arg)
316{
317 int *err = arg;
318 *err = 0;
319 return NL_STOP;
320}
321
322static int finish_handler(struct nl_msg *msg, void *arg)
323{
324 int *ret = arg;
325 *ret = 0;
326 return NL_SKIP;
327}
328
329static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
330 void *arg)
331{
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800332 struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1;
333 int len = nlh->nlmsg_len;
334 struct nlattr *attrs;
335 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 int *ret = arg;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800337 int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339 *ret = err->error;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800340
341 if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
342 return NL_SKIP;
343
344 if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
345 ack_len += err->msg.nlmsg_len - sizeof(*nlh);
346
347 if (len <= ack_len)
348 return NL_STOP;
349
350 attrs = (void *) ((unsigned char *) nlh + ack_len);
351 len -= ack_len;
352
353 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
354 if (tb[NLMSGERR_ATTR_MSG]) {
355 len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]),
356 nla_len(tb[NLMSGERR_ATTR_MSG]));
357 wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s",
358 len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG]));
359 }
360
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361 return NL_SKIP;
362}
363
364
365static int no_seq_check(struct nl_msg *msg, void *arg)
366{
367 return NL_OK;
368}
369
370
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800371static void nl80211_nlmsg_clear(struct nl_msg *msg)
372{
373 /*
374 * Clear nlmsg data, e.g., to make sure key material is not left in
375 * heap memory for unnecessarily long time.
376 */
377 if (msg) {
378 struct nlmsghdr *hdr = nlmsg_hdr(msg);
379 void *data = nlmsg_data(hdr);
380 /*
381 * This would use nlmsg_datalen() or the older nlmsg_len() if
382 * only libnl were to maintain a stable API.. Neither will work
383 * with all released versions, so just calculate the length
384 * here.
385 */
386 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
387
388 os_memset(data, 0, len);
389 }
390}
391
392
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800393static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394 struct nl_handle *nl_handle, struct nl_msg *msg,
395 int (*valid_handler)(struct nl_msg *, void *),
396 void *valid_data)
397{
398 struct nl_cb *cb;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800399 int err = -ENOMEM, opt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800401 if (!msg)
402 return -ENOMEM;
403
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800404 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 if (!cb)
406 goto out;
407
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800408 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
409 opt = 1;
410 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
411 NETLINK_EXT_ACK, &opt, sizeof(opt));
412
Hai Shalom74f70d42019-02-11 14:42:39 -0800413 /* try to set NETLINK_CAP_ACK to 1, ignoring errors */
414 opt = 1;
415 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
416 NETLINK_CAP_ACK, &opt, sizeof(opt));
417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 err = nl_send_auto_complete(nl_handle, msg);
419 if (err < 0)
420 goto out;
421
422 err = 1;
423
424 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
425 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
426 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
427
428 if (valid_handler)
429 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
430 valid_handler, valid_data);
431
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700432 while (err > 0) {
433 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700434 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700435 wpa_printf(MSG_INFO,
436 "nl80211: %s->nl_recvmsgs failed: %d",
437 __func__, res);
438 }
439 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 out:
441 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800442 if (!valid_handler && valid_data == (void *) -1)
443 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 nlmsg_free(msg);
445 return err;
446}
447
448
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800449int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
450 struct nl_msg *msg,
451 int (*valid_handler)(struct nl_msg *, void *),
452 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454 return send_and_recv(drv->global, drv->global->nl, msg,
455 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456}
457
458
459struct family_data {
460 const char *group;
461 int id;
462};
463
464
465static int family_handler(struct nl_msg *msg, void *arg)
466{
467 struct family_data *res = arg;
468 struct nlattr *tb[CTRL_ATTR_MAX + 1];
469 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
470 struct nlattr *mcgrp;
471 int i;
472
473 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
474 genlmsg_attrlen(gnlh, 0), NULL);
475 if (!tb[CTRL_ATTR_MCAST_GROUPS])
476 return NL_SKIP;
477
478 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
479 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
480 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
481 nla_len(mcgrp), NULL);
482 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
483 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
484 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
485 res->group,
486 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
487 continue;
488 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
489 break;
490 };
491
492 return NL_SKIP;
493}
494
495
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800496static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497 const char *family, const char *group)
498{
499 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800500 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 struct family_data res = { group, -ENOENT };
502
503 msg = nlmsg_alloc();
504 if (!msg)
505 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800506 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
507 0, 0, CTRL_CMD_GETFAMILY, 0) ||
508 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
509 nlmsg_free(msg);
510 return -1;
511 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800513 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 if (ret == 0)
515 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 return ret;
517}
518
519
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800520void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
521 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522{
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700523 if (TEST_FAIL())
524 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800525 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
526 0, flags, cmd, 0);
527}
528
529
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800530static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
531{
532 if (bss->wdev_id_set)
533 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
534 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
535}
536
537
538struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
539{
540 struct nl_msg *msg;
541
542 msg = nlmsg_alloc();
543 if (!msg)
544 return NULL;
545
546 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
547 nl80211_set_iface_id(msg, bss) < 0) {
548 nlmsg_free(msg);
549 return NULL;
550 }
551
552 return msg;
553}
554
555
556static struct nl_msg *
557nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
558 int flags, uint8_t cmd)
559{
560 struct nl_msg *msg;
561
562 msg = nlmsg_alloc();
563 if (!msg)
564 return NULL;
565
566 if (!nl80211_cmd(drv, msg, flags, cmd) ||
567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
568 nlmsg_free(msg);
569 return NULL;
570 }
571
572 return msg;
573}
574
575
576struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
577 uint8_t cmd)
578{
579 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
580}
581
582
583struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
584{
585 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
586}
587
588
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800589struct wiphy_idx_data {
590 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700591 enum nl80211_iftype nlmode;
592 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800593};
594
595
596static int netdev_info_handler(struct nl_msg *msg, void *arg)
597{
598 struct nlattr *tb[NL80211_ATTR_MAX + 1];
599 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
600 struct wiphy_idx_data *info = arg;
601
602 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
603 genlmsg_attrlen(gnlh, 0), NULL);
604
605 if (tb[NL80211_ATTR_WIPHY])
606 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
607
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700608 if (tb[NL80211_ATTR_IFTYPE])
609 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
610
611 if (tb[NL80211_ATTR_MAC] && info->macaddr)
612 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
613 ETH_ALEN);
614
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 return NL_SKIP;
616}
617
618
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800619int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620{
621 struct nl_msg *msg;
622 struct wiphy_idx_data data = {
623 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700624 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800625 };
626
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800627 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
628 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800629
630 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
631 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800632 return -1;
633}
634
635
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700636static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
637{
638 struct nl_msg *msg;
639 struct wiphy_idx_data data = {
640 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
641 .macaddr = NULL,
642 };
643
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800644 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
645 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700646
647 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
648 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700649 return NL80211_IFTYPE_UNSPECIFIED;
650}
651
652
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700653static int nl80211_get_macaddr(struct i802_bss *bss)
654{
655 struct nl_msg *msg;
656 struct wiphy_idx_data data = {
657 .macaddr = bss->addr,
658 };
659
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800660 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
661 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700662
663 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700664}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700665
666
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800667static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
668 struct nl80211_wiphy_data *w)
669{
670 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800671 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800672
673 msg = nlmsg_alloc();
674 if (!msg)
675 return -1;
676
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800677 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
678 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
679 nlmsg_free(msg);
680 return -1;
681 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800682
683 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800684 if (ret) {
685 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
686 "failed: ret=%d (%s)",
687 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800688 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800689 return ret;
690}
691
692
693static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
694{
695 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700696 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800697
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800698 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800699
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700700 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700701 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700702 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
703 __func__, res);
704 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800705}
706
707
708static int process_beacon_event(struct nl_msg *msg, void *arg)
709{
710 struct nl80211_wiphy_data *w = arg;
711 struct wpa_driver_nl80211_data *drv;
712 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
713 struct nlattr *tb[NL80211_ATTR_MAX + 1];
714 union wpa_event_data event;
715
716 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
717 genlmsg_attrlen(gnlh, 0), NULL);
718
719 if (gnlh->cmd != NL80211_CMD_FRAME) {
720 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
721 gnlh->cmd);
722 return NL_SKIP;
723 }
724
725 if (!tb[NL80211_ATTR_FRAME])
726 return NL_SKIP;
727
728 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
729 wiphy_list) {
730 os_memset(&event, 0, sizeof(event));
731 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
732 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
733 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
734 }
735
736 return NL_SKIP;
737}
738
739
740static struct nl80211_wiphy_data *
741nl80211_get_wiphy_data_ap(struct i802_bss *bss)
742{
743 static DEFINE_DL_LIST(nl80211_wiphys);
744 struct nl80211_wiphy_data *w;
745 int wiphy_idx, found = 0;
746 struct i802_bss *tmp_bss;
Paul Stewart092955c2017-02-06 09:13:09 -0800747 u8 channel;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800748
749 if (bss->wiphy_data != NULL)
750 return bss->wiphy_data;
751
752 wiphy_idx = nl80211_get_wiphy_index(bss);
753
754 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
755 if (w->wiphy_idx == wiphy_idx)
756 goto add;
757 }
758
759 /* alloc new one */
760 w = os_zalloc(sizeof(*w));
761 if (w == NULL)
762 return NULL;
763 w->wiphy_idx = wiphy_idx;
764 dl_list_init(&w->bsss);
765 dl_list_init(&w->drvs);
766
Paul Stewart092955c2017-02-06 09:13:09 -0800767 /* Beacon frames not supported in IEEE 802.11ad */
768 if (ieee80211_freq_to_chan(bss->freq, &channel) !=
769 HOSTAPD_MODE_IEEE80211AD) {
770 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
771 if (!w->nl_cb) {
772 os_free(w);
773 return NULL;
774 }
775 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
776 no_seq_check, NULL);
777 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
778 process_beacon_event, w);
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000779
Paul Stewart092955c2017-02-06 09:13:09 -0800780 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
781 "wiphy beacons");
782 if (w->nl_beacons == NULL) {
783 os_free(w);
784 return NULL;
785 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000786
Paul Stewart092955c2017-02-06 09:13:09 -0800787 if (nl80211_register_beacons(bss->drv, w)) {
788 nl_destroy_handles(&w->nl_beacons);
789 os_free(w);
790 return NULL;
791 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000792
Paul Stewart092955c2017-02-06 09:13:09 -0800793 nl80211_register_eloop_read(&w->nl_beacons,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700794 nl80211_recv_beacons, w, 0);
Paul Stewart092955c2017-02-06 09:13:09 -0800795 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800796
797 dl_list_add(&nl80211_wiphys, &w->list);
798
799add:
800 /* drv entry for this bss already there? */
801 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
802 if (tmp_bss->drv == bss->drv) {
803 found = 1;
804 break;
805 }
806 }
807 /* if not add it */
808 if (!found)
809 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
810
811 dl_list_add(&w->bsss, &bss->wiphy_list);
812 bss->wiphy_data = w;
813 return w;
814}
815
816
817static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
818{
819 struct nl80211_wiphy_data *w = bss->wiphy_data;
820 struct i802_bss *tmp_bss;
821 int found = 0;
822
823 if (w == NULL)
824 return;
825 bss->wiphy_data = NULL;
826 dl_list_del(&bss->wiphy_list);
827
828 /* still any for this drv present? */
829 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
830 if (tmp_bss->drv == bss->drv) {
831 found = 1;
832 break;
833 }
834 }
835 /* if not remove it */
836 if (!found)
837 dl_list_del(&bss->drv->wiphy_list);
838
839 if (!dl_list_empty(&w->bsss))
840 return;
841
Paul Stewart092955c2017-02-06 09:13:09 -0800842 if (w->nl_beacons)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700843 nl80211_destroy_eloop_handle(&w->nl_beacons, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844
845 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800846 dl_list_del(&w->list);
847 os_free(w);
848}
849
850
Dmitry Shmidte4663042016-04-04 10:07:49 -0700851static unsigned int nl80211_get_ifindex(void *priv)
852{
853 struct i802_bss *bss = priv;
854 struct wpa_driver_nl80211_data *drv = bss->drv;
855
856 return drv->ifindex;
857}
858
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
861{
862 struct i802_bss *bss = priv;
863 struct wpa_driver_nl80211_data *drv = bss->drv;
864 if (!drv->associated)
865 return -1;
866 os_memcpy(bssid, drv->bssid, ETH_ALEN);
867 return 0;
868}
869
870
871static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
872{
873 struct i802_bss *bss = priv;
874 struct wpa_driver_nl80211_data *drv = bss->drv;
875 if (!drv->associated)
876 return -1;
877 os_memcpy(ssid, drv->ssid, drv->ssid_len);
878 return drv->ssid_len;
879}
880
881
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800882static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700883 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
884 int ifindex, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885{
886 union wpa_event_data event;
887
Dmitry Shmidte4663042016-04-04 10:07:49 -0700888 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800889 if (if_nametoindex(drv->first_bss->ifname) == 0) {
890 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
891 drv->first_bss->ifname);
892 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700893 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800894 if (!drv->if_removed)
895 return;
896 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
897 drv->first_bss->ifname);
898 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 }
900
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800901 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700902 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 os_strlcpy(event.interface_status.ifname, ifname,
904 sizeof(event.interface_status.ifname));
905 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700906 if (drv)
907 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
908 else
909 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
910 &event);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800911}
912
913
914static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700915 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
916 int ifindex, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800917{
918 union wpa_event_data event;
919
Dmitry Shmidte4663042016-04-04 10:07:49 -0700920 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800921 if (drv->if_removed) {
922 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
923 ifname);
924 return;
925 }
926 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
927 ifname);
928 drv->if_removed = 1;
929 } else {
930 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
931 ifname);
932 }
933
934 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700935 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800936 os_strlcpy(event.interface_status.ifname, ifname,
937 sizeof(event.interface_status.ifname));
938 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700939 if (drv)
940 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
941 else
942 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
943 &event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944}
945
946
947static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
948 u8 *buf, size_t len)
949{
950 int attrlen, rta_len;
951 struct rtattr *attr;
952
953 attrlen = len;
954 attr = (struct rtattr *) buf;
955
956 rta_len = RTA_ALIGN(sizeof(struct rtattr));
957 while (RTA_OK(attr, attrlen)) {
958 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800959 if (os_strcmp(((char *) attr) + rta_len,
960 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 return 1;
962 else
963 break;
964 }
965 attr = RTA_NEXT(attr, attrlen);
966 }
967
968 return 0;
969}
970
971
972static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
973 int ifindex, u8 *buf, size_t len)
974{
975 if (drv->ifindex == ifindex)
976 return 1;
977
978 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800979 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
981 "interface");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700982 if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0)
983 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 return 1;
985 }
986
987 return 0;
988}
989
990
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991static struct wpa_driver_nl80211_data *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700992nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len,
993 int *init_failed)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800994{
995 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700996 int res;
997
998 if (init_failed)
999 *init_failed = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 dl_list_for_each(drv, &global->interfaces,
1001 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001002 res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len);
1003 if (res < 0) {
1004 wpa_printf(MSG_DEBUG,
1005 "nl80211: Found matching own interface, but failed to complete reinitialization");
1006 if (init_failed)
1007 *init_failed = 1;
1008 return drv;
1009 }
1010 if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001011 return drv;
1012 }
1013 return NULL;
1014}
1015
1016
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001017static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001018 int ifindex, int notify)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001019{
1020 struct i802_bss *bss;
1021 u8 addr[ETH_ALEN];
1022
1023 bss = get_bss_ifindex(drv, ifindex);
1024 if (bss &&
1025 linux_get_ifhwaddr(drv->global->ioctl_sock,
1026 bss->ifname, addr) < 0) {
1027 wpa_printf(MSG_DEBUG,
1028 "nl80211: %s: failed to re-read MAC address",
1029 bss->ifname);
1030 } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1031 wpa_printf(MSG_DEBUG,
1032 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1033 MACSTR " to " MACSTR,
1034 ifindex, bss->ifname,
1035 MAC2STR(bss->addr), MAC2STR(addr));
1036 os_memcpy(bss->addr, addr, ETH_ALEN);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001037 if (notify)
1038 wpa_supplicant_event(drv->ctx,
1039 EVENT_INTERFACE_MAC_CHANGED, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001040 }
1041}
1042
1043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
1045 struct ifinfomsg *ifi,
1046 u8 *buf, size_t len)
1047{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001048 struct nl80211_global *global = ctx;
1049 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001050 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051 struct rtattr *attr;
1052 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001053 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001054 char ifname[IFNAMSIZ + 1];
1055 char extra[100], *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001056 int init_failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001058 extra[0] = '\0';
1059 pos = extra;
1060 end = pos + sizeof(extra);
1061 ifname[0] = '\0';
1062
1063 attrlen = len;
1064 attr = (struct rtattr *) buf;
1065 while (RTA_OK(attr, attrlen)) {
1066 switch (attr->rta_type) {
1067 case IFLA_IFNAME:
1068 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1069 break;
1070 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1071 ifname[RTA_PAYLOAD(attr)] = '\0';
1072 break;
1073 case IFLA_MASTER:
1074 brid = nla_get_u32((struct nlattr *) attr);
1075 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1076 break;
1077 case IFLA_WIRELESS:
1078 pos += os_snprintf(pos, end - pos, " wext");
1079 break;
1080 case IFLA_OPERSTATE:
1081 pos += os_snprintf(pos, end - pos, " operstate=%u",
1082 nla_get_u32((struct nlattr *) attr));
1083 break;
1084 case IFLA_LINKMODE:
1085 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1086 nla_get_u32((struct nlattr *) attr));
1087 break;
1088 }
1089 attr = RTA_NEXT(attr, attrlen);
1090 }
1091 extra[sizeof(extra) - 1] = '\0';
1092
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001093 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1094 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1095 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1097 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1098 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1099 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1100
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001101 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001102 if (!drv)
1103 goto event_newlink;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001104 if (init_failed)
1105 return; /* do not update interface state */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001108 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001109 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001110 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001111 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1112 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001113 drv->ignore_if_down_event = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001114 /* Re-read MAC address as it may have changed */
1115 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 return;
1117 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001118 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
1119 namebuf, ifname);
1120 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1121 wpa_printf(MSG_DEBUG,
1122 "nl80211: Not the main interface (%s) - do not indicate interface down",
1123 drv->first_bss->ifname);
1124 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001125 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1126 "event generated by mode change");
1127 drv->ignore_if_down_event = 0;
1128 } else {
1129 drv->if_disabled = 1;
1130 wpa_supplicant_event(drv->ctx,
1131 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001132
1133 /*
1134 * Try to get drv again, since it may be removed as
1135 * part of the EVENT_INTERFACE_DISABLED handling for
1136 * dynamic interfaces
1137 */
1138 drv = nl80211_find_drv(global, ifi->ifi_index,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001139 buf, len, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001140 if (!drv)
1141 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001142 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001143 }
1144
1145 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07001146 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001147 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001148 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001149 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1150 "event since interface %s is down",
1151 namebuf);
Hai Shalomc9e41a12018-07-31 14:41:42 -07001152 return;
1153 }
1154 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
1155 namebuf, ifname);
1156 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1157 wpa_printf(MSG_DEBUG,
1158 "nl80211: Not the main interface (%s) - do not indicate interface up",
1159 drv->first_bss->ifname);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001160 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001161 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1162 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001163 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001164 } else if (drv->if_removed) {
1165 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1166 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001167 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001168 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001169 /* Re-read MAC address as it may have changed */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001170 nl80211_refresh_mac(drv, ifi->ifi_index, 0);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001171
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001172 drv->if_disabled = 0;
1173 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1174 NULL);
1175 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 }
1177
1178 /*
1179 * Some drivers send the association event before the operup event--in
1180 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1181 * fails. This will hit us when wpa_supplicant does not need to do
1182 * IEEE 802.1X authentication
1183 */
1184 if (drv->operstate == 1 &&
1185 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001186 !(ifi->ifi_flags & IFF_RUNNING)) {
1187 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001188 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 }
1191
Dmitry Shmidte4663042016-04-04 10:07:49 -07001192event_newlink:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001193 if (ifname[0])
Dmitry Shmidte4663042016-04-04 10:07:49 -07001194 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1195 ifname);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001196
Dmitry Shmidte4663042016-04-04 10:07:49 -07001197 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001198 struct i802_bss *bss;
1199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001201 if (!if_indextoname(brid, namebuf)) {
1202 wpa_printf(MSG_DEBUG,
1203 "nl80211: Could not find bridge ifname for ifindex %u",
1204 brid);
1205 return;
1206 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1208 brid, namebuf);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001209 add_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001210
1211 for (bss = drv->first_bss; bss; bss = bss->next) {
1212 if (os_strcmp(ifname, bss->ifname) == 0) {
1213 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1214 break;
1215 }
1216 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218}
1219
1220
1221static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1222 struct ifinfomsg *ifi,
1223 u8 *buf, size_t len)
1224{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001225 struct nl80211_global *global = ctx;
1226 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001227 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228 struct rtattr *attr;
1229 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001230 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001231 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001232
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001233 extra[0] = '\0';
1234 pos = extra;
1235 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001236 ifname[0] = '\0';
1237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 attrlen = len;
1239 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001241 switch (attr->rta_type) {
1242 case IFLA_IFNAME:
1243 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1244 break;
1245 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1246 ifname[RTA_PAYLOAD(attr)] = '\0';
1247 break;
1248 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001250 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1251 break;
1252 case IFLA_OPERSTATE:
1253 pos += os_snprintf(pos, end - pos, " operstate=%u",
1254 nla_get_u32((struct nlattr *) attr));
1255 break;
1256 case IFLA_LINKMODE:
1257 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1258 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001259 break;
1260 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261 attr = RTA_NEXT(attr, attrlen);
1262 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001263 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001264
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001265 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1266 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1267 ifi->ifi_flags,
1268 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1269 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1270 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1271 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1272
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001273 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001274
Dmitry Shmidte4663042016-04-04 10:07:49 -07001275 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276 /* device has been removed from bridge */
1277 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001278
1279 if (!if_indextoname(brid, namebuf)) {
1280 wpa_printf(MSG_DEBUG,
1281 "nl80211: Could not find bridge ifname for ifindex %u",
1282 brid);
1283 } else {
1284 wpa_printf(MSG_DEBUG,
1285 "nl80211: Remove ifindex %u for bridge %s",
1286 brid, namebuf);
1287 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001288 del_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001290
1291 if (ifi->ifi_family != AF_BRIDGE || !brid)
1292 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1293 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294}
1295
1296
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001297struct nl80211_get_assoc_freq_arg {
1298 struct wpa_driver_nl80211_data *drv;
1299 unsigned int assoc_freq;
1300 unsigned int ibss_freq;
1301 u8 assoc_bssid[ETH_ALEN];
1302 u8 assoc_ssid[SSID_MAX_LEN];
1303 u8 assoc_ssid_len;
1304};
1305
1306static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg)
1307{
1308 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1309 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1310 struct nlattr *bss[NL80211_BSS_MAX + 1];
1311 static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
1312 [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC },
1313 [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
1314 [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC },
1315 [NL80211_BSS_STATUS] = { .type = NLA_U32 },
1316 };
1317 struct nl80211_get_assoc_freq_arg *ctx = arg;
1318 enum nl80211_bss_status status;
1319
1320 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1321 genlmsg_attrlen(gnlh, 0), NULL);
1322 if (!tb[NL80211_ATTR_BSS] ||
1323 nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS],
1324 bss_policy) ||
1325 !bss[NL80211_BSS_STATUS])
1326 return NL_SKIP;
1327
1328 status = nla_get_u32(bss[NL80211_BSS_STATUS]);
1329 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1330 bss[NL80211_BSS_FREQUENCY]) {
1331 ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1332 wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz",
1333 ctx->assoc_freq);
1334 }
1335 if (status == NL80211_BSS_STATUS_IBSS_JOINED &&
1336 bss[NL80211_BSS_FREQUENCY]) {
1337 ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1338 wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz",
1339 ctx->ibss_freq);
1340 }
1341 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1342 bss[NL80211_BSS_BSSID]) {
1343 os_memcpy(ctx->assoc_bssid,
1344 nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN);
1345 wpa_printf(MSG_DEBUG, "nl80211: Associated with "
1346 MACSTR, MAC2STR(ctx->assoc_bssid));
1347 }
1348
1349 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1350 bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
1351 const u8 *ie, *ssid;
1352 size_t ie_len;
1353
1354 ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1355 ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1356 ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
1357 if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) {
1358 ctx->assoc_ssid_len = ssid[1];
1359 os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]);
1360 }
1361 }
1362
1363 return NL_SKIP;
1364}
1365
1366
1367int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001368{
1369 struct nl_msg *msg;
1370 int ret;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001371 struct nl80211_get_assoc_freq_arg arg;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001372
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001373 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001374 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001375 arg.drv = drv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001376 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1377 &arg);
1378 if (ret == 0) {
1379 os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len);
1380 return arg.assoc_ssid_len;
1381 }
1382 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)",
1383 ret, strerror(-ret));
1384 return ret;
1385}
1386
1387
1388unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
1389{
1390 struct nl_msg *msg;
1391 int ret;
1392 struct nl80211_get_assoc_freq_arg arg;
1393
1394 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1395 os_memset(&arg, 0, sizeof(arg));
1396 arg.drv = drv;
1397 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1398 &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001399 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001400 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1401 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001402 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001403 "associated BSS from scan results: %u MHz", freq);
1404 if (freq)
1405 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001406 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001407 }
1408 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1409 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001410 return drv->assoc_freq;
1411}
1412
1413
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414static int get_link_signal(struct nl_msg *msg, void *arg)
1415{
1416 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1417 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1418 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1419 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1420 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001421 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001422 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001423 };
1424 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1425 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1426 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1427 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1428 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1429 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1430 };
1431 struct wpa_signal_info *sig_change = arg;
1432
1433 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1434 genlmsg_attrlen(gnlh, 0), NULL);
1435 if (!tb[NL80211_ATTR_STA_INFO] ||
1436 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1437 tb[NL80211_ATTR_STA_INFO], policy))
1438 return NL_SKIP;
1439 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1440 return NL_SKIP;
1441
1442 sig_change->current_signal =
1443 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1444
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001445 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1446 sig_change->avg_signal =
1447 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1448 else
1449 sig_change->avg_signal = 0;
1450
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001451 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1452 sig_change->avg_beacon_signal =
1453 (s8)
1454 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1455 else
1456 sig_change->avg_beacon_signal = 0;
1457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001458 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1459 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1460 sinfo[NL80211_STA_INFO_TX_BITRATE],
1461 rate_policy)) {
1462 sig_change->current_txrate = 0;
1463 } else {
1464 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1465 sig_change->current_txrate =
1466 nla_get_u16(rinfo[
1467 NL80211_RATE_INFO_BITRATE]) * 100;
1468 }
1469 }
1470 }
1471
1472 return NL_SKIP;
1473}
1474
1475
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001476int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1477 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001478{
1479 struct nl_msg *msg;
1480
Hai Shalom74f70d42019-02-11 14:42:39 -08001481 sig->current_signal = -WPA_INVALID_NOISE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 sig->current_txrate = 0;
1483
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001484 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1485 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1486 nlmsg_free(msg);
1487 return -ENOBUFS;
1488 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001489
1490 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491}
1492
1493
1494static int get_link_noise(struct nl_msg *msg, void *arg)
1495{
1496 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1497 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1498 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1499 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1500 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1501 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1502 };
1503 struct wpa_signal_info *sig_change = arg;
1504
1505 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1506 genlmsg_attrlen(gnlh, 0), NULL);
1507
1508 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1509 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1510 return NL_SKIP;
1511 }
1512
1513 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1514 tb[NL80211_ATTR_SURVEY_INFO],
1515 survey_policy)) {
1516 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1517 "attributes!");
1518 return NL_SKIP;
1519 }
1520
1521 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1522 return NL_SKIP;
1523
1524 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1525 sig_change->frequency)
1526 return NL_SKIP;
1527
1528 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1529 return NL_SKIP;
1530
1531 sig_change->current_noise =
1532 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1533
1534 return NL_SKIP;
1535}
1536
1537
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001538int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1539 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540{
1541 struct nl_msg *msg;
1542
Hai Shalom74f70d42019-02-11 14:42:39 -08001543 sig_change->current_noise = WPA_INVALID_NOISE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544 sig_change->frequency = drv->assoc_freq;
1545
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001546 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548}
1549
1550
Hai Shalom74f70d42019-02-11 14:42:39 -08001551static int get_channel_info(struct nl_msg *msg, void *arg)
1552{
1553 struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 };
1554 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1555 struct wpa_channel_info *chan_info = arg;
1556
1557 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1558 genlmsg_attrlen(gnlh, 0), NULL);
1559
1560 os_memset(chan_info, 0, sizeof(struct wpa_channel_info));
1561 chan_info->chanwidth = CHAN_WIDTH_UNKNOWN;
1562
1563 if (tb[NL80211_ATTR_WIPHY_FREQ])
1564 chan_info->frequency =
1565 nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
1566 if (tb[NL80211_ATTR_CHANNEL_WIDTH])
1567 chan_info->chanwidth = convert2width(
1568 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
1569 if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1570 enum nl80211_channel_type ct =
1571 nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1572
1573 switch (ct) {
1574 case NL80211_CHAN_HT40MINUS:
1575 chan_info->sec_channel = -1;
1576 break;
1577 case NL80211_CHAN_HT40PLUS:
1578 chan_info->sec_channel = 1;
1579 break;
1580 default:
1581 chan_info->sec_channel = 0;
1582 break;
1583 }
1584 }
1585 if (tb[NL80211_ATTR_CENTER_FREQ1])
1586 chan_info->center_frq1 =
1587 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
1588 if (tb[NL80211_ATTR_CENTER_FREQ2])
1589 chan_info->center_frq2 =
1590 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
1591
1592 if (chan_info->center_frq2) {
1593 u8 seg1_idx = 0;
1594
1595 if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) !=
1596 NUM_HOSTAPD_MODES)
1597 chan_info->seg1_idx = seg1_idx;
1598 }
1599
1600 return NL_SKIP;
1601}
1602
1603
1604static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci)
1605{
1606 struct i802_bss *bss = priv;
1607 struct wpa_driver_nl80211_data *drv = bss->drv;
1608 struct nl_msg *msg;
1609
1610 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
1611 return send_and_recv_msgs(drv, msg, get_channel_info, ci);
1612}
1613
1614
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1616 void *handle)
1617{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001618 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001619 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001621 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001622
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001623 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001624 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001625 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1626 __func__, res);
1627 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628}
1629
1630
1631/**
1632 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1633 * @priv: driver_nl80211 private data
1634 * @alpha2_arg: country to which to switch to
1635 * Returns: 0 on success, -1 on failure
1636 *
1637 * This asks nl80211 to set the regulatory domain for given
1638 * country ISO / IEC alpha2.
1639 */
1640static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1641{
1642 struct i802_bss *bss = priv;
1643 struct wpa_driver_nl80211_data *drv = bss->drv;
1644 char alpha2[3];
1645 struct nl_msg *msg;
1646
1647 msg = nlmsg_alloc();
1648 if (!msg)
1649 return -ENOMEM;
1650
1651 alpha2[0] = alpha2_arg[0];
1652 alpha2[1] = alpha2_arg[1];
1653 alpha2[2] = '\0';
1654
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001655 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1656 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1657 nlmsg_free(msg);
1658 return -EINVAL;
1659 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1661 return -EINVAL;
1662 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663}
1664
1665
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001666static int nl80211_get_country(struct nl_msg *msg, void *arg)
1667{
1668 char *alpha2 = arg;
1669 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1670 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1671
1672 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1673 genlmsg_attrlen(gnlh, 0), NULL);
1674 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1675 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1676 return NL_SKIP;
1677 }
1678 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1679 return NL_SKIP;
1680}
1681
1682
1683static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1684{
1685 struct i802_bss *bss = priv;
1686 struct wpa_driver_nl80211_data *drv = bss->drv;
1687 struct nl_msg *msg;
1688 int ret;
1689
1690 msg = nlmsg_alloc();
1691 if (!msg)
1692 return -ENOMEM;
1693
1694 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1695 alpha2[0] = '\0';
1696 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1697 if (!alpha2[0])
1698 ret = -1;
1699
1700 return ret;
1701}
1702
1703
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001704static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705{
1706 int ret;
1707
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001708 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1709 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1711 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001712 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 }
1714
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001715 global->nl = nl_create_handle(global->nl_cb, "nl");
1716 if (global->nl == NULL)
1717 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001719 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1720 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1722 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001723 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724 }
1725
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001726 global->nl_event = nl_create_handle(global->nl_cb, "event");
1727 if (global->nl_event == NULL)
1728 goto err;
1729
1730 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001732 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733 if (ret < 0) {
1734 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1735 "membership for scan events: %d (%s)",
1736 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001737 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001738 }
1739
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001740 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001742 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 if (ret < 0) {
1744 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1745 "membership for mlme events: %d (%s)",
1746 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 }
1749
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001750 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001752 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 if (ret < 0) {
1754 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1755 "membership for regulatory events: %d (%s)",
1756 ret, strerror(-ret));
1757 /* Continue without regulatory events */
1758 }
1759
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001760 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1761 if (ret >= 0)
1762 ret = nl_socket_add_membership(global->nl_event, ret);
1763 if (ret < 0) {
1764 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1765 "membership for vendor events: %d (%s)",
1766 ret, strerror(-ret));
1767 /* Continue without vendor events */
1768 }
1769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1771 no_seq_check, NULL);
1772 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1773 process_global_event, global);
1774
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001775 nl80211_register_eloop_read(&global->nl_event,
1776 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001777 global->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778
1779 return 0;
1780
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001781err:
1782 nl_destroy_handles(&global->nl_event);
1783 nl_destroy_handles(&global->nl);
1784 nl_cb_put(global->nl_cb);
1785 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 return -1;
1787}
1788
1789
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001790static void nl80211_check_global(struct nl80211_global *global)
1791{
1792 struct nl_handle *handle;
1793 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1794 int ret;
1795 unsigned int i;
1796
1797 /*
1798 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1799 * and all registration having been cleared.
1800 */
1801 handle = (void *) (((intptr_t) global->nl_event) ^
1802 ELOOP_SOCKET_INVALID);
1803
1804 for (i = 0; groups[i]; i++) {
1805 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1806 if (ret >= 0)
1807 ret = nl_socket_add_membership(handle, ret);
1808 if (ret < 0) {
1809 wpa_printf(MSG_INFO,
1810 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1811 groups[i], ret, strerror(-ret));
1812 }
1813 }
1814}
1815
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1818{
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001819 struct wpa_driver_nl80211_data *drv = ctx;
1820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001821 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001822
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 /*
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001824 * rtnetlink ifdown handler will report interfaces other than the P2P
1825 * Device interface as disabled.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001827 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1828 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001829}
1830
1831
1832static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1833{
1834 struct wpa_driver_nl80211_data *drv = ctx;
1835 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001836 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1838 "after rfkill unblock");
1839 return;
1840 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001841
1842 if (is_p2p_net_interface(drv->nlmode))
1843 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
1844
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001845 /*
1846 * rtnetlink ifup handler will report interfaces other than the P2P
1847 * Device interface as enabled.
1848 */
1849 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1850 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851}
1852
1853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001854static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1855 void *eloop_ctx,
1856 void *handle)
1857{
1858 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1859 u8 data[2048];
1860 struct msghdr msg;
1861 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001862 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001863 struct cmsghdr *cmsg;
1864 int res, found_ee = 0, found_wifi = 0, acked = 0;
1865 union wpa_event_data event;
1866
1867 memset(&msg, 0, sizeof(msg));
1868 msg.msg_iov = &entry;
1869 msg.msg_iovlen = 1;
1870 entry.iov_base = data;
1871 entry.iov_len = sizeof(data);
1872 msg.msg_control = &control;
1873 msg.msg_controllen = sizeof(control);
1874
1875 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1876 /* if error or not fitting 802.3 header, return */
1877 if (res < 14)
1878 return;
1879
1880 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1881 {
1882 if (cmsg->cmsg_level == SOL_SOCKET &&
1883 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1884 int *ack;
1885
1886 found_wifi = 1;
1887 ack = (void *)CMSG_DATA(cmsg);
1888 acked = *ack;
1889 }
1890
1891 if (cmsg->cmsg_level == SOL_PACKET &&
1892 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1893 struct sock_extended_err *err =
1894 (struct sock_extended_err *)CMSG_DATA(cmsg);
1895
1896 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1897 found_ee = 1;
1898 }
1899 }
1900
1901 if (!found_ee || !found_wifi)
1902 return;
1903
1904 memset(&event, 0, sizeof(event));
1905 event.eapol_tx_status.dst = data;
1906 event.eapol_tx_status.data = data + 14;
1907 event.eapol_tx_status.data_len = res - 14;
1908 event.eapol_tx_status.ack = acked;
1909 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1910}
1911
1912
1913static int nl80211_init_bss(struct i802_bss *bss)
1914{
1915 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1916 if (!bss->nl_cb)
1917 return -1;
1918
1919 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1920 no_seq_check, NULL);
1921 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1922 process_bss_event, bss);
1923
1924 return 0;
1925}
1926
1927
1928static void nl80211_destroy_bss(struct i802_bss *bss)
1929{
1930 nl_cb_put(bss->nl_cb);
1931 bss->nl_cb = NULL;
1932}
1933
1934
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001935static void
1936wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
1937{
1938 struct rfkill_config *rcfg;
1939
1940 if (drv->rfkill)
1941 return;
1942
1943 rcfg = os_zalloc(sizeof(*rcfg));
1944 if (!rcfg)
1945 return;
1946
1947 rcfg->ctx = drv;
1948
1949 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1950 * not associated with a netdev, so use the name of some other interface
1951 * sharing the same wiphy as the P2P Device interface.
1952 *
1953 * Note: This is valid, as a P2P Device interface is always dynamically
1954 * created and is created only once another wpa_s interface was added.
1955 */
1956 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
1957 struct nl80211_global *global = drv->global;
1958 struct wpa_driver_nl80211_data *tmp1;
1959
1960 dl_list_for_each(tmp1, &global->interfaces,
1961 struct wpa_driver_nl80211_data, list) {
1962 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
1963 !tmp1->rfkill)
1964 continue;
1965
1966 wpa_printf(MSG_DEBUG,
1967 "nl80211: Use (%s) to initialize P2P Device rfkill",
1968 tmp1->first_bss->ifname);
1969 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
1970 sizeof(rcfg->ifname));
1971 break;
1972 }
1973 } else {
1974 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
1975 sizeof(rcfg->ifname));
1976 }
1977
1978 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1979 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1980 drv->rfkill = rfkill_init(rcfg);
1981 if (!drv->rfkill) {
1982 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1983 os_free(rcfg);
1984 }
1985}
1986
1987
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001988static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1989 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001990 const u8 *set_addr,
1991 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001992{
1993 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001994 struct i802_bss *bss;
1995
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001996 if (global_priv == NULL)
1997 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998 drv = os_zalloc(sizeof(*drv));
1999 if (drv == NULL)
2000 return NULL;
2001 drv->global = global_priv;
2002 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002003 drv->hostapd = !!hostapd;
2004 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002005
2006 /*
2007 * There is no driver capability flag for this, so assume it is
2008 * supported and disable this on first attempt to use if the driver
2009 * rejects the command due to missing support.
2010 */
2011 drv->set_rekey_offload = 1;
2012
Hai Shalom81f62d82019-07-22 12:10:00 -07002013 drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002014 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002015
2016 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
2017 if (!drv->first_bss) {
2018 os_free(drv);
2019 return NULL;
2020 }
2021 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002022 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002023 bss->ctx = ctx;
2024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
2026 drv->monitor_ifidx = -1;
2027 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002028 drv->eapol_tx_sock = -1;
2029 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002031 if (nl80211_init_bss(bss))
2032 goto failed;
2033
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002034 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 goto failed;
2036
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002037 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
2038 if (drv->eapol_tx_sock < 0)
2039 goto failed;
2040
2041 if (drv->data_tx_status) {
2042 int enabled = 1;
2043
2044 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
2045 &enabled, sizeof(enabled)) < 0) {
2046 wpa_printf(MSG_DEBUG,
2047 "nl80211: wifi status sockopt failed\n");
2048 drv->data_tx_status = 0;
2049 if (!drv->use_monitor)
2050 drv->capa.flags &=
2051 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
2052 } else {
2053 eloop_register_read_sock(drv->eapol_tx_sock,
2054 wpa_driver_nl80211_handle_eapol_tx_status,
2055 drv, NULL);
2056 }
2057 }
2058
2059 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002060 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002061 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002062 drv->in_interface_list = 1;
2063 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002064
2065 return bss;
2066
2067failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002068 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 return NULL;
2070}
2071
2072
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002073/**
2074 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2075 * @ctx: context to be used when calling wpa_supplicant functions,
2076 * e.g., wpa_supplicant_event()
2077 * @ifname: interface name, e.g., wlan0
2078 * @global_priv: private driver global data from global_init()
2079 * Returns: Pointer to private data, %NULL on failure
2080 */
2081static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
2082 void *global_priv)
2083{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002084 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
2085 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002086}
2087
2088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002089static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 struct nl_handle *nl_handle,
2091 u16 type, const u8 *match, size_t match_len)
2092{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002093 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002094 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002095 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002096 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002097
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002098 buf[0] = '\0';
2099 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07002100 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
2101 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002103 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
2104 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
2105 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
2106 nlmsg_free(msg);
2107 return -1;
2108 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002109
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002110 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 if (ret) {
2112 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
2113 "failed (type=%u): ret=%d (%s)",
2114 type, ret, strerror(-ret));
2115 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
2116 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002117 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 return ret;
2119}
2120
2121
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002122static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
2123{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002124 if (bss->nl_mgmt) {
2125 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
2126 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
2127 return -1;
2128 }
2129
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002130 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002131 if (bss->nl_mgmt == NULL)
2132 return -1;
2133
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002134 return 0;
2135}
2136
2137
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002138static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
2139{
2140 nl80211_register_eloop_read(&bss->nl_mgmt,
2141 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002142 bss->nl_cb, 0);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002143}
2144
2145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002146static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147 const u8 *match, size_t match_len)
2148{
2149 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002150 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002151 type, match, match_len);
2152}
2153
2154
Roshan Pius3a1667e2018-07-03 15:17:14 -07002155static int nl80211_init_connect_handle(struct i802_bss *bss)
2156{
2157 if (bss->nl_connect) {
2158 wpa_printf(MSG_DEBUG,
2159 "nl80211: Connect handle already created (nl_connect=%p)",
2160 bss->nl_connect);
2161 return -1;
2162 }
2163
2164 bss->nl_connect = nl_create_handle(bss->nl_cb, "connect");
2165 if (!bss->nl_connect)
2166 return -1;
2167 nl80211_register_eloop_read(&bss->nl_connect,
2168 wpa_driver_nl80211_event_receive,
2169 bss->nl_cb, 1);
2170 return 0;
2171}
2172
2173
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002174static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002175{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002176 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002177 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002178
2179 if (nl80211_alloc_mgmt_handle(bss))
2180 return -1;
2181 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
2182 "handle %p", bss->nl_mgmt);
2183
Roshan Pius3a1667e2018-07-03 15:17:14 -07002184 if (drv->nlmode == NL80211_IFTYPE_ADHOC ||
2185 ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
2186 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002187 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2188
2189 /* register for any AUTH message */
2190 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
2191 }
2192
Dmitry Shmidt051af732013-10-22 13:52:46 -07002193#ifdef CONFIG_INTERWORKING
2194 /* QoS Map Configure */
2195 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002196 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002197#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002198#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002199 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002200 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002201 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002203 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002204 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002206 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002207 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002208 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002209 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002210 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08002211 /* Protected GAS Initial Request */
2212 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
2213 ret = -1;
2214 /* Protected GAS Initial Response */
2215 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
2216 ret = -1;
2217 /* Protected GAS Comeback Request */
2218 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
2219 ret = -1;
2220 /* Protected GAS Comeback Response */
2221 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
2222 ret = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002223#endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002224#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002226 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
2228 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002229 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002230 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002231 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002232 (u8 *) "\x7f\x50\x6f\x9a\x09",
2233 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002234 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235#endif /* CONFIG_P2P */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002236#ifdef CONFIG_DPP
2237 /* DPP Public Action */
2238 if (nl80211_register_action_frame(bss,
2239 (u8 *) "\x04\x09\x50\x6f\x9a\x1a",
2240 6) < 0)
2241 ret = -1;
2242#endif /* CONFIG_DPP */
Hai Shalom74f70d42019-02-11 14:42:39 -08002243#ifdef CONFIG_OCV
2244 /* SA Query Request */
2245 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0)
2246 ret = -1;
2247#endif /* CONFIG_OCV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002248 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002249 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002250 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002251#ifdef CONFIG_TDLS
2252 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
2253 /* TDLS Discovery Response */
2254 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
2255 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002256 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002257 }
2258#endif /* CONFIG_TDLS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002259#ifdef CONFIG_FST
2260 /* FST Action frames */
2261 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2262 ret = -1;
2263#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264
2265 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002266 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002267 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268 else
2269 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
2270 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002272 /* WNM - BSS Transition Management Request */
2273 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002274 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002275 /* WNM-Sleep Mode Response */
2276 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002277 ret = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002278#ifdef CONFIG_WNM
2279 /* WNM - Collocated Interference Request */
2280 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0)
2281 ret = -1;
2282#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002284#ifdef CONFIG_HS20
2285 /* WNM-Notification */
2286 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002287 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002288#endif /* CONFIG_HS20 */
2289
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002290 /* WMM-AC ADDTS Response */
2291 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
2292 ret = -1;
2293
2294 /* WMM-AC DELTS */
2295 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
2296 ret = -1;
2297
2298 /* Radio Measurement - Neighbor Report Response */
2299 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
2300 ret = -1;
2301
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002302 /* Radio Measurement - Radio Measurement Request */
2303 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0)
2304 ret = -1;
2305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002306 /* Radio Measurement - Link Measurement Request */
2307 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
2308 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
2309 ret = -1;
2310
2311 nl80211_mgmt_handle_register_eloop(bss);
2312
2313 return ret;
2314}
2315
2316
2317static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2318{
2319 int ret = 0;
2320
2321 if (nl80211_alloc_mgmt_handle(bss))
2322 return -1;
2323
2324 wpa_printf(MSG_DEBUG,
2325 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2326 bss->nl_mgmt);
2327
2328 /* Auth frames for mesh SAE */
2329 if (nl80211_register_frame(bss, bss->nl_mgmt,
2330 (WLAN_FC_TYPE_MGMT << 2) |
2331 (WLAN_FC_STYPE_AUTH << 4),
2332 NULL, 0) < 0)
2333 ret = -1;
2334
2335 /* Mesh peering open */
2336 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2337 ret = -1;
2338 /* Mesh peering confirm */
2339 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2340 ret = -1;
2341 /* Mesh peering close */
2342 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2343 ret = -1;
2344
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002345 nl80211_mgmt_handle_register_eloop(bss);
2346
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002347 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002348}
2349
2350
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002351static int nl80211_register_spurious_class3(struct i802_bss *bss)
2352{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002353 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002354 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002355
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002356 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
2357 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002358 if (ret) {
2359 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2360 "failed: ret=%d (%s)",
2361 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002362 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002363 return ret;
2364}
2365
2366
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002367static int nl80211_action_subscribe_ap(struct i802_bss *bss)
2368{
2369 int ret = 0;
2370
2371 /* Public Action frames */
2372 if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0)
2373 ret = -1;
2374 /* RRM Measurement Report */
2375 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0)
2376 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08002377 /* RRM Link Measurement Report */
2378 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0)
2379 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002380 /* RRM Neighbor Report Request */
2381 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0)
2382 ret = -1;
2383 /* FT Action frames */
2384 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2385 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002386 /* SA Query */
2387 if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0)
2388 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002389 /* Protected Dual of Public Action */
2390 if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0)
2391 ret = -1;
2392 /* WNM */
2393 if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0)
2394 ret = -1;
2395 /* WMM */
2396 if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0)
2397 ret = -1;
2398#ifdef CONFIG_FST
2399 /* FST Action frames */
2400 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2401 ret = -1;
2402#endif /* CONFIG_FST */
2403 /* Vendor-specific */
2404 if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0)
2405 ret = -1;
2406
2407 return ret;
2408}
2409
2410
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002411static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2412{
2413 static const int stypes[] = {
2414 WLAN_FC_STYPE_AUTH,
2415 WLAN_FC_STYPE_ASSOC_REQ,
2416 WLAN_FC_STYPE_REASSOC_REQ,
2417 WLAN_FC_STYPE_DISASSOC,
2418 WLAN_FC_STYPE_DEAUTH,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002419 WLAN_FC_STYPE_PROBE_REQ,
2420/* Beacon doesn't work as mac80211 doesn't currently allow
2421 * it, but it wouldn't really be the right thing anyway as
2422 * it isn't per interface ... maybe just dump the scan
2423 * results periodically for OLBC?
2424 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002425 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002426 };
2427 unsigned int i;
2428
2429 if (nl80211_alloc_mgmt_handle(bss))
2430 return -1;
2431 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2432 "handle %p", bss->nl_mgmt);
2433
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002434 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002435 if (nl80211_register_frame(bss, bss->nl_mgmt,
2436 (WLAN_FC_TYPE_MGMT << 2) |
2437 (stypes[i] << 4),
2438 NULL, 0) < 0) {
2439 goto out_err;
2440 }
2441 }
2442
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002443 if (nl80211_action_subscribe_ap(bss))
2444 goto out_err;
2445
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002446 if (nl80211_register_spurious_class3(bss))
2447 goto out_err;
2448
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002449 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002450 return 0;
2451
2452out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002453 nl_destroy_handles(&bss->nl_mgmt);
2454 return -1;
2455}
2456
2457
2458static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2459{
2460 if (nl80211_alloc_mgmt_handle(bss))
2461 return -1;
2462 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2463 "handle %p (device SME)", bss->nl_mgmt);
2464
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002465 if (nl80211_action_subscribe_ap(bss))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002466 goto out_err;
2467
Hai Shalom5f92bc92019-04-18 11:54:11 -07002468 if (bss->drv->device_ap_sme) {
2469 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2470
2471 /* Register for all Authentication frames */
2472 if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0)
2473 < 0)
2474 wpa_printf(MSG_DEBUG,
2475 "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work");
2476 }
2477
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002478 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002479 return 0;
2480
2481out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002482 nl_destroy_handles(&bss->nl_mgmt);
2483 return -1;
2484}
2485
2486
2487static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2488{
2489 if (bss->nl_mgmt == NULL)
2490 return;
2491 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2492 "(%s)", bss->nl_mgmt, reason);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002493 nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002494
2495 nl80211_put_wiphy_data_ap(bss);
2496}
2497
2498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2500{
2501 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2502}
2503
2504
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002505static void nl80211_del_p2pdev(struct i802_bss *bss)
2506{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002507 struct nl_msg *msg;
2508 int ret;
2509
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002510 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2511 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002512
2513 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2514 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002515 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002516}
2517
2518
2519static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2520{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002521 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002522 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002523
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002524 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2525 NL80211_CMD_STOP_P2P_DEVICE);
2526 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002527
2528 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2529 start ? "Start" : "Stop",
2530 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002531 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002532 return ret;
2533}
2534
2535
2536static int i802_set_iface_flags(struct i802_bss *bss, int up)
2537{
2538 enum nl80211_iftype nlmode;
2539
2540 nlmode = nl80211_get_ifmode(bss);
2541 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2542 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2543 bss->ifname, up);
2544 }
2545
2546 /* P2P Device has start/stop which is equivalent */
2547 return nl80211_set_p2pdev(bss, up);
2548}
2549
2550
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002551#ifdef CONFIG_TESTING_OPTIONS
2552static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2553{
2554 /* struct wpa_driver_nl80211_data *drv = arg; */
2555 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2556 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2557
2558
2559 wpa_printf(MSG_DEBUG,
2560 "nl80211: QCA vendor test command response received");
2561
2562 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2563 genlmsg_attrlen(gnlh, 0), NULL);
2564 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2565 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2566 return NL_SKIP;
2567 }
2568
2569 wpa_hexdump(MSG_DEBUG,
2570 "nl80211: Received QCA vendor test command response",
2571 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2572 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2573
2574 return NL_SKIP;
2575}
2576#endif /* CONFIG_TESTING_OPTIONS */
2577
2578
2579static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2580{
2581#ifdef CONFIG_TESTING_OPTIONS
2582 struct nl_msg *msg;
2583 struct nlattr *params;
2584 int ret;
2585
2586 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2587 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2588 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2589 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2590 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2591 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2592 nlmsg_free(msg);
2593 return;
2594 }
2595 nla_nest_end(msg, params);
2596
2597 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2598 wpa_printf(MSG_DEBUG,
2599 "nl80211: QCA vendor test command returned %d (%s)",
2600 ret, strerror(-ret));
2601#endif /* CONFIG_TESTING_OPTIONS */
2602}
2603
2604
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002606wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002607 const u8 *set_addr, int first,
2608 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002609{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002610 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002611 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002612 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002613
2614 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002615 bss->ifindex = drv->ifindex;
2616 bss->wdev_id = drv->global->if_add_wdevid;
2617 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2618
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002619 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2620 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002621 drv->global->if_add_wdevid_set = 0;
2622
Dmitry Shmidt03658832014-08-13 11:03:49 -07002623 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2624 bss->static_ap = 1;
2625
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002626 if (first &&
2627 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2628 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2629 drv->start_iface_up = 1;
2630
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002631 if (wpa_driver_nl80211_capa(drv))
2632 return -1;
2633
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002634 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2635 return -1;
2636
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002637 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2638 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002640 if (set_addr &&
2641 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2642 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2643 set_addr)))
2644 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002645
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002646 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2647 drv->start_mode_ap = 1;
2648
Dmitry Shmidt03658832014-08-13 11:03:49 -07002649 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002650 nlmode = NL80211_IFTYPE_AP;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002651 else if (bss->if_dynamic ||
2652 nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002653 nlmode = nl80211_get_ifmode(bss);
2654 else
2655 nlmode = NL80211_IFTYPE_STATION;
2656
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002657 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002658 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002659 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002660 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002661
Dmitry Shmidt98660862014-03-11 17:26:21 -07002662 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002663 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002664
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002665 wpa_driver_nl80211_drv_init_rfkill(drv);
2666
Dmitry Shmidt98660862014-03-11 17:26:21 -07002667 if (!rfkill_is_blocked(drv->rfkill)) {
2668 int ret = i802_set_iface_flags(bss, 1);
2669 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2671 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002672 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002674
2675 if (is_p2p_net_interface(nlmode))
2676 nl80211_disable_11b_rates(bss->drv,
2677 bss->drv->ifindex, 1);
2678
Dmitry Shmidt98660862014-03-11 17:26:21 -07002679 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2680 return ret;
2681 } else {
2682 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2683 "interface '%s' due to rfkill", bss->ifname);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002684 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
2685 drv->if_disabled = 1;
2686
Dmitry Shmidt98660862014-03-11 17:26:21 -07002687 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688 }
2689
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002690 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002691 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2692 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002693
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002694 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2695 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2696 bss->addr))
2697 return -1;
2698 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
2699 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002701 if (send_rfkill_event) {
2702 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2703 drv, drv->ctx);
2704 }
2705
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002706 if (drv->vendor_cmd_test_avail)
2707 qca_vendor_test(drv);
2708
Roshan Pius3a1667e2018-07-03 15:17:14 -07002709 nl80211_init_connect_handle(bss);
2710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002711 return 0;
2712}
2713
2714
Paul Stewart092955c2017-02-06 09:13:09 -08002715static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716{
2717 struct nl_msg *msg;
Paul Stewart092955c2017-02-06 09:13:09 -08002718 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002720 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2721 drv->ifindex);
Paul Stewart092955c2017-02-06 09:13:09 -08002722 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002723 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725}
2726
2727
2728/**
2729 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002730 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002731 *
2732 * Shut down driver interface and processing of driver events. Free
2733 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2734 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002735static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002736{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002737 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002738 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002739
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002740 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2741 bss->ifname, drv->disabled_11b_rates);
2742
Dmitry Shmidt04949592012-07-19 12:16:46 -07002743 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002744 if (drv->data_tx_status)
2745 eloop_unregister_read_sock(drv->eapol_tx_sock);
2746 if (drv->eapol_tx_sock >= 0)
2747 close(drv->eapol_tx_sock);
2748
2749 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002750 wpa_driver_nl80211_probe_req_report(bss, 0);
2751 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002752 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2753 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002754 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2755 "interface %s from bridge %s: %s",
2756 bss->ifname, bss->brname, strerror(errno));
2757 }
Hai Shalomc9e41a12018-07-31 14:41:42 -07002758
2759 if (drv->rtnl_sk)
2760 nl80211_handle_destroy(drv->rtnl_sk);
2761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002763 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2764 0) < 0)
2765 wpa_printf(MSG_INFO,
2766 "nl80211: Could not set bridge %s down",
2767 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002768 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2770 "bridge %s: %s",
2771 bss->brname, strerror(errno));
2772 }
2773
2774 nl80211_remove_monitor_interface(drv);
2775
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002776 if (is_ap_interface(drv->nlmode))
Paul Stewart092955c2017-02-06 09:13:09 -08002777 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 if (drv->eapol_sock >= 0) {
2780 eloop_unregister_read_sock(drv->eapol_sock);
2781 close(drv->eapol_sock);
2782 }
2783
2784 if (drv->if_indices != drv->default_if_indices)
2785 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002787 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002788 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2789
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002790 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2791 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002792 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 rfkill_deinit(drv->rfkill);
2794
2795 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2796
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002797 if (!drv->start_iface_up)
2798 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002799
2800 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002801 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2802 0) < 0) {
2803 wpa_printf(MSG_DEBUG,
2804 "nl80211: Could not set interface down to restore permanent MAC address");
2805 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002806 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2807 drv->perm_addr) < 0) {
2808 wpa_printf(MSG_DEBUG,
2809 "nl80211: Could not restore permanent MAC address");
2810 }
2811 }
2812
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002813 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002814 if (!drv->hostapd || !drv->start_mode_ap)
2815 wpa_driver_nl80211_set_mode(bss,
2816 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002817 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002818 } else {
2819 nl80211_mgmt_unsubscribe(bss, "deinit");
2820 nl80211_del_p2pdev(bss);
2821 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002822
Roshan Pius3a1667e2018-07-03 15:17:14 -07002823 if (bss->nl_connect)
2824 nl80211_destroy_eloop_handle(&bss->nl_connect, 1);
2825
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002826 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002827
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828 os_free(drv->filter_ssids);
2829
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002830 os_free(drv->auth_ie);
2831
2832 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 dl_list_del(&drv->list);
2834
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002835 os_free(drv->extended_capa);
2836 os_free(drv->extended_capa_mask);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002837 for (i = 0; i < drv->num_iface_ext_capa; i++) {
2838 os_free(drv->iface_ext_capa[i].ext_capa);
2839 os_free(drv->iface_ext_capa[i].ext_capa_mask);
2840 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002841 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002842 os_free(drv);
2843}
2844
2845
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002846static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2847{
2848 switch (alg) {
2849 case WPA_ALG_WEP:
2850 if (key_len == 5)
Paul Stewart092955c2017-02-06 09:13:09 -08002851 return RSN_CIPHER_SUITE_WEP40;
2852 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002853 case WPA_ALG_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002854 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002855 case WPA_ALG_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002856 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002857 case WPA_ALG_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002858 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002859 case WPA_ALG_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002860 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002861 case WPA_ALG_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002862 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002863 case WPA_ALG_IGTK:
Paul Stewart092955c2017-02-06 09:13:09 -08002864 return RSN_CIPHER_SUITE_AES_128_CMAC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002865 case WPA_ALG_BIP_GMAC_128:
Paul Stewart092955c2017-02-06 09:13:09 -08002866 return RSN_CIPHER_SUITE_BIP_GMAC_128;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002867 case WPA_ALG_BIP_GMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002868 return RSN_CIPHER_SUITE_BIP_GMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002869 case WPA_ALG_BIP_CMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002870 return RSN_CIPHER_SUITE_BIP_CMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002871 case WPA_ALG_SMS4:
Paul Stewart092955c2017-02-06 09:13:09 -08002872 return RSN_CIPHER_SUITE_SMS4;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002873 case WPA_ALG_KRK:
Paul Stewart092955c2017-02-06 09:13:09 -08002874 return RSN_CIPHER_SUITE_KRK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002875 case WPA_ALG_NONE:
2876 case WPA_ALG_PMK:
2877 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2878 alg);
2879 return 0;
2880 }
2881
2882 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2883 alg);
2884 return 0;
2885}
2886
2887
2888static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2889{
2890 switch (cipher) {
2891 case WPA_CIPHER_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002892 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002893 case WPA_CIPHER_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002894 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002895 case WPA_CIPHER_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002896 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002897 case WPA_CIPHER_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002898 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002899 case WPA_CIPHER_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002900 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002901 case WPA_CIPHER_WEP104:
Paul Stewart092955c2017-02-06 09:13:09 -08002902 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002903 case WPA_CIPHER_WEP40:
Paul Stewart092955c2017-02-06 09:13:09 -08002904 return RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002905 case WPA_CIPHER_GTK_NOT_USED:
Paul Stewart092955c2017-02-06 09:13:09 -08002906 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002907 }
2908
2909 return 0;
2910}
2911
2912
2913static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2914 int max_suites)
2915{
2916 int num_suites = 0;
2917
2918 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002919 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002920 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002921 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002922 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002923 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002924 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002925 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002926 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
Paul Stewart092955c2017-02-06 09:13:09 -08002927 suites[num_suites++] = RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002928 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
Paul Stewart092955c2017-02-06 09:13:09 -08002929 suites[num_suites++] = RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002930 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
Paul Stewart092955c2017-02-06 09:13:09 -08002931 suites[num_suites++] = RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002932
2933 return num_suites;
2934}
2935
2936
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002937#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002938static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2939 const u8 *key, size_t key_len)
2940{
2941 struct nl_msg *msg;
2942 int ret;
2943
2944 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2945 return 0;
2946
2947 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2948 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2949 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2950 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2951 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2952 nl80211_nlmsg_clear(msg);
2953 nlmsg_free(msg);
2954 return -1;
2955 }
2956 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2957 if (ret) {
2958 wpa_printf(MSG_DEBUG,
2959 "nl80211: Key management set key failed: ret=%d (%s)",
2960 ret, strerror(-ret));
2961 }
2962
2963 return ret;
2964}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002965#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002966
2967
Roshan Pius3a1667e2018-07-03 15:17:14 -07002968static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv,
2969 const u8 *key, size_t key_len,
2970 const u8 *addr)
2971{
2972 struct nl_msg *msg = NULL;
2973 int ret;
2974
2975 /*
2976 * If the authenticator address is not set, assume it is
2977 * the current BSSID.
2978 */
2979 if (!addr && drv->associated)
2980 addr = drv->bssid;
2981 else if (!addr)
2982 return -1;
2983
2984 wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR,
2985 MAC2STR(addr));
2986 wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len);
2987 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK);
2988 if (!msg ||
2989 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
2990 nla_put(msg, NL80211_ATTR_PMK, key_len, key)) {
2991 nl80211_nlmsg_clear(msg);
2992 nlmsg_free(msg);
2993 return -ENOBUFS;
2994 }
2995
2996 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2997 if (ret) {
2998 wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)",
2999 ret, strerror(-ret));
3000 }
3001
3002 return ret;
3003}
3004
3005
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003006static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007 enum wpa_alg alg, const u8 *addr,
3008 int key_idx, int set_tx,
3009 const u8 *seq, size_t seq_len,
3010 const u8 *key, size_t key_len)
3011{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003012 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003013 int ifindex;
Hai Shalomc3565922019-10-28 11:58:20 -07003014 struct nl_msg *msg;
3015 struct nl_msg *key_msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003017 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003018
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003019 /* Ignore for P2P Device */
3020 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
3021 return 0;
3022
3023 ifindex = if_nametoindex(ifname);
3024 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003026 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003027 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003028#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003029 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003030 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003031 tdls = 1;
3032 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003033#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003034
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003035#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003036 if (alg == WPA_ALG_PMK &&
3037 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
3038 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
3039 __func__);
3040 ret = issue_key_mgmt_set_key(drv, key, key_len);
3041 return ret;
3042 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003043#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044
Roshan Pius3a1667e2018-07-03 15:17:14 -07003045 if (alg == WPA_ALG_PMK &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003046 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X))
Roshan Pius3a1667e2018-07-03 15:17:14 -07003047 return nl80211_set_pmk(drv, key, key_len, addr);
3048
Hai Shalomc3565922019-10-28 11:58:20 -07003049 key_msg = nlmsg_alloc();
3050 if (!key_msg)
3051 return -ENOBUFS;
3052
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003054 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
3055 if (!msg)
Hai Shalomc3565922019-10-28 11:58:20 -07003056 goto fail2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003057 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003058 u32 suite;
3059
3060 suite = wpa_alg_to_cipher_suite(alg, key_len);
3061 if (!suite)
Hai Shalomc3565922019-10-28 11:58:20 -07003062 goto fail2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003063 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003064 if (!msg)
3065 goto fail2;
3066 if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) ||
3067 nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003068 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003069 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 }
3071
Dmitry Shmidt98660862014-03-11 17:26:21 -07003072 if (seq && seq_len) {
Hai Shalomc3565922019-10-28 11:58:20 -07003073 if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003074 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003075 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
3076 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077
3078 if (addr && !is_broadcast_ether_addr(addr)) {
3079 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003080 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
3081 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082
3083 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
3084 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Hai Shalomc3565922019-10-28 11:58:20 -07003085 if (nla_put_u32(key_msg, NL80211_KEY_TYPE,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003086 NL80211_KEYTYPE_GROUP))
3087 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088 }
3089 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003090 struct nlattr *types;
3091
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003092 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003093
Hai Shalomc3565922019-10-28 11:58:20 -07003094 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003095 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003096 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003097 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003098 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099 }
Hai Shalomc3565922019-10-28 11:58:20 -07003100 if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
3101 nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003102 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003103 nl80211_nlmsg_clear(key_msg);
3104 nlmsg_free(key_msg);
3105 key_msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003106
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003107 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003108 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
3109 ret = 0;
3110 if (ret)
3111 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
3112 ret, strerror(-ret));
3113
3114 /*
3115 * If we failed or don't need to set the default TX key (below),
3116 * we're done here.
3117 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003118 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003119 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003120 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003121 !is_broadcast_ether_addr(addr))
3122 return ret;
3123
Hai Shalomc3565922019-10-28 11:58:20 -07003124 key_msg = nlmsg_alloc();
3125 if (!key_msg)
3126 return -ENOBUFS;
3127
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003128 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003129 if (!msg)
3130 goto fail2;
3131 if (!key_msg ||
3132 nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
3133 nla_put_flag(key_msg, (alg == WPA_ALG_IGTK ||
3134 alg == WPA_ALG_BIP_GMAC_128 ||
3135 alg == WPA_ALG_BIP_GMAC_256 ||
3136 alg == WPA_ALG_BIP_CMAC_256) ?
3137 NL80211_KEY_DEFAULT_MGMT :
3138 NL80211_KEY_DEFAULT))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003139 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003140 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003141 struct nlattr *types;
3142
Hai Shalomc3565922019-10-28 11:58:20 -07003143 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003144 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003145 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003146 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003147 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003148 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003149 struct nlattr *types;
3150
Hai Shalomc3565922019-10-28 11:58:20 -07003151 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003152 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003153 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003154 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003155 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156 }
3157
Hai Shalomc3565922019-10-28 11:58:20 -07003158 if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
3159 goto fail;
3160 nl80211_nlmsg_clear(key_msg);
3161 nlmsg_free(key_msg);
3162 key_msg = NULL;
3163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003164 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3165 if (ret == -ENOENT)
3166 ret = 0;
3167 if (ret)
3168 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
3169 "err=%d %s)", ret, strerror(-ret));
3170 return ret;
3171
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003172fail:
3173 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003174 nlmsg_free(msg);
Hai Shalomc3565922019-10-28 11:58:20 -07003175fail2:
3176 nl80211_nlmsg_clear(key_msg);
3177 nlmsg_free(key_msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 return -ENOBUFS;
3179}
3180
3181
3182static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
3183 int key_idx, int defkey,
3184 const u8 *seq, size_t seq_len,
3185 const u8 *key, size_t key_len)
3186{
3187 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003188 u32 suite;
3189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003190 if (!key_attr)
3191 return -1;
3192
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003193 suite = wpa_alg_to_cipher_suite(alg, key_len);
3194 if (!suite)
3195 return -1;
3196
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003197 if (defkey && alg == WPA_ALG_IGTK) {
3198 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
3199 return -1;
3200 } else if (defkey) {
3201 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
3202 return -1;
3203 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003204
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003205 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003206 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003207 (seq && seq_len &&
3208 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
3209 nla_put(msg, NL80211_KEY_DATA, key_len, key))
3210 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003211
3212 nla_nest_end(msg, key_attr);
3213
3214 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003215}
3216
3217
3218static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
3219 struct nl_msg *msg)
3220{
3221 int i, privacy = 0;
3222 struct nlattr *nl_keys, *nl_key;
3223
3224 for (i = 0; i < 4; i++) {
3225 if (!params->wep_key[i])
3226 continue;
3227 privacy = 1;
3228 break;
3229 }
3230 if (params->wps == WPS_MODE_PRIVACY)
3231 privacy = 1;
3232 if (params->pairwise_suite &&
3233 params->pairwise_suite != WPA_CIPHER_NONE)
3234 privacy = 1;
3235
3236 if (!privacy)
3237 return 0;
3238
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003239 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3240 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003241
3242 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
3243 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003244 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003245
3246 for (i = 0; i < 4; i++) {
3247 if (!params->wep_key[i])
3248 continue;
3249
3250 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003251 if (!nl_key ||
3252 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
3253 params->wep_key[i]) ||
3254 nla_put_u32(msg, NL80211_KEY_CIPHER,
3255 params->wep_key_len[i] == 5 ?
Paul Stewart092955c2017-02-06 09:13:09 -08003256 RSN_CIPHER_SUITE_WEP40 :
3257 RSN_CIPHER_SUITE_WEP104) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003258 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
3259 (i == params->wep_tx_keyidx &&
3260 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
3261 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003262
3263 nla_nest_end(msg, nl_key);
3264 }
3265 nla_nest_end(msg, nl_keys);
3266
3267 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003268}
3269
3270
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003271int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
3272 const u8 *addr, int cmd, u16 reason_code,
Hai Shalom74f70d42019-02-11 14:42:39 -08003273 int local_state_change,
3274 struct nl_handle *nl_connect)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003275{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003276 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003277 struct nl_msg *msg;
3278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003279 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
3280 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
3281 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
3282 (local_state_change &&
3283 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
3284 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003285 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003286 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003287
Hai Shalom74f70d42019-02-11 14:42:39 -08003288 if (nl_connect)
3289 ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL);
3290 else
3291 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003292 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003293 wpa_dbg(drv->ctx, MSG_DEBUG,
3294 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3295 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003296 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003297 return ret;
3298}
3299
3300
3301static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Hai Shalom81f62d82019-07-22 12:10:00 -07003302 u16 reason_code,
Hai Shalom74f70d42019-02-11 14:42:39 -08003303 struct nl_handle *nl_connect)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003304{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003305 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003306 int drv_associated = drv->associated;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003307
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003308 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003309 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003310 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003311 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
Hai Shalom74f70d42019-02-11 14:42:39 -08003312 reason_code, 0, nl_connect);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003313 /*
3314 * For locally generated disconnect, supplicant already generates a
3315 * DEAUTH event, so ignore the event from NL80211.
3316 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003317 drv->ignore_next_local_disconnect = drv_associated && (ret == 0);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003318
3319 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003320}
3321
3322
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003323static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
Hai Shalom81f62d82019-07-22 12:10:00 -07003324 const u8 *addr, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003326 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003327 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003328 int drv_associated = drv->associated;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003329
3330 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
3331 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003332 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003333 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003334 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
3335 struct nl_handle *nl_connect = NULL;
3336
3337 if (bss->use_nl_connect)
3338 nl_connect = bss->nl_connect;
3339 return wpa_driver_nl80211_disconnect(drv, reason_code,
3340 nl_connect);
3341 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
3343 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003344 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003345 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
Hai Shalom74f70d42019-02-11 14:42:39 -08003346 reason_code, 0, NULL);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003347 /*
3348 * For locally generated deauthenticate, supplicant already generates a
3349 * DEAUTH event, so ignore the event from NL80211.
3350 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003351 drv->ignore_next_local_deauth = drv_associated && (ret == 0);
3352
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003353 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354}
3355
3356
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003357static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
3358 struct wpa_driver_auth_params *params)
3359{
3360 int i;
3361
3362 drv->auth_freq = params->freq;
3363 drv->auth_alg = params->auth_alg;
3364 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
3365 drv->auth_local_state_change = params->local_state_change;
3366 drv->auth_p2p = params->p2p;
3367
3368 if (params->bssid)
3369 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
3370 else
3371 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
3372
3373 if (params->ssid) {
3374 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
3375 drv->auth_ssid_len = params->ssid_len;
3376 } else
3377 drv->auth_ssid_len = 0;
3378
3379
3380 os_free(drv->auth_ie);
3381 drv->auth_ie = NULL;
3382 drv->auth_ie_len = 0;
3383 if (params->ie) {
3384 drv->auth_ie = os_malloc(params->ie_len);
3385 if (drv->auth_ie) {
3386 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
3387 drv->auth_ie_len = params->ie_len;
3388 }
3389 }
3390
3391 for (i = 0; i < 4; i++) {
3392 if (params->wep_key[i] && params->wep_key_len[i] &&
3393 params->wep_key_len[i] <= 16) {
3394 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
3395 params->wep_key_len[i]);
3396 drv->auth_wep_key_len[i] = params->wep_key_len[i];
3397 } else
3398 drv->auth_wep_key_len[i] = 0;
3399 }
3400}
3401
3402
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003403static void nl80211_unmask_11b_rates(struct i802_bss *bss)
3404{
3405 struct wpa_driver_nl80211_data *drv = bss->drv;
3406
3407 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
3408 return;
3409
3410 /*
3411 * Looks like we failed to unmask 11b rates previously. This could
3412 * happen, e.g., if the interface was down at the point in time when a
3413 * P2P group was terminated.
3414 */
3415 wpa_printf(MSG_DEBUG,
3416 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3417 bss->ifname);
3418 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
3419}
3420
3421
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003422static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg)
3423{
3424 if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
3425 return NL80211_AUTHTYPE_OPEN_SYSTEM;
3426 if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
3427 return NL80211_AUTHTYPE_SHARED_KEY;
3428 if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
3429 return NL80211_AUTHTYPE_NETWORK_EAP;
3430 if (wpa_auth_alg & WPA_AUTH_ALG_FT)
3431 return NL80211_AUTHTYPE_FT;
3432 if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
3433 return NL80211_AUTHTYPE_SAE;
3434 if (wpa_auth_alg & WPA_AUTH_ALG_FILS)
3435 return NL80211_AUTHTYPE_FILS_SK;
3436 if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS)
3437 return NL80211_AUTHTYPE_FILS_SK_PFS;
3438
3439 return NL80211_AUTHTYPE_MAX;
3440}
3441
3442
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003444 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003445{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003446 struct wpa_driver_nl80211_data *drv = bss->drv;
3447 int ret = -1, i;
3448 struct nl_msg *msg;
3449 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003450 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003451 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003452 int is_retry;
3453
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003454 nl80211_unmask_11b_rates(bss);
3455
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003456 is_retry = drv->retry_auth;
3457 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003458 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003460 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003461 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003462 if (params->bssid)
3463 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
3464 else
3465 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003466 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003467 nlmode = params->p2p ?
3468 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
3469 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003470 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003471 return -1;
3472
3473retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003474 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
3475 drv->ifindex);
3476
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003477 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
3478 if (!msg)
3479 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003480
3481 for (i = 0; i < 4; i++) {
3482 if (!params->wep_key[i])
3483 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003484 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003485 NULL, i,
3486 i == params->wep_tx_keyidx, NULL, 0,
3487 params->wep_key[i],
3488 params->wep_key_len[i]);
3489 if (params->wep_tx_keyidx != i)
3490 continue;
3491 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003492 params->wep_key[i], params->wep_key_len[i]))
3493 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003494 }
3495
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003496 if (params->bssid) {
3497 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
3498 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003499 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
3500 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 }
3502 if (params->freq) {
3503 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003504 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
3505 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 }
3507 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003508 wpa_printf(MSG_DEBUG, " * SSID=%s",
3509 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003510 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
3511 params->ssid))
3512 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003513 }
3514 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003515 if (params->ie &&
3516 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
3517 goto fail;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003518 if (params->auth_data) {
3519 wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data,
3520 params->auth_data_len);
3521 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len,
3522 params->auth_data))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003523 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003524 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003525 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003526 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003527 if (type == NL80211_AUTHTYPE_MAX ||
3528 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003529 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530 if (params->local_state_change) {
3531 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003532 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
3533 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003534 }
3535
3536 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3537 msg = NULL;
3538 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003539 wpa_dbg(drv->ctx, MSG_DEBUG,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003540 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
3541 count, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 count++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003543 if ((ret == -EALREADY || ret == -EEXIST) && count == 1 &&
3544 params->bssid && !params->local_state_change) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003545 /*
3546 * mac80211 does not currently accept new
3547 * authentication if we are already authenticated. As a
3548 * workaround, force deauthentication and try again.
3549 */
3550 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
3551 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07003552 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003553 wpa_driver_nl80211_deauthenticate(
3554 bss, params->bssid,
3555 WLAN_REASON_PREV_AUTH_NOT_VALID);
3556 nlmsg_free(msg);
3557 goto retry;
3558 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003559
3560 if (ret == -ENOENT && params->freq && !is_retry) {
3561 /*
3562 * cfg80211 has likely expired the BSS entry even
3563 * though it was previously available in our internal
3564 * BSS table. To recover quickly, start a single
3565 * channel scan on the specified channel.
3566 */
3567 struct wpa_driver_scan_params scan;
3568 int freqs[2];
3569
3570 os_memset(&scan, 0, sizeof(scan));
3571 scan.num_ssids = 1;
3572 if (params->ssid) {
3573 scan.ssids[0].ssid = params->ssid;
3574 scan.ssids[0].ssid_len = params->ssid_len;
3575 }
3576 freqs[0] = params->freq;
3577 freqs[1] = 0;
3578 scan.freqs = freqs;
3579 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3580 "channel scan to refresh cfg80211 BSS "
3581 "entry");
3582 ret = wpa_driver_nl80211_scan(bss, &scan);
3583 if (ret == 0) {
3584 nl80211_copy_auth_params(drv, params);
3585 drv->scan_for_auth = 1;
3586 }
3587 } else if (is_retry) {
3588 /*
3589 * Need to indicate this with an event since the return
3590 * value from the retry is not delivered to core code.
3591 */
3592 union wpa_event_data event;
3593 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3594 "failed");
3595 os_memset(&event, 0, sizeof(event));
3596 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3597 ETH_ALEN);
3598 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3599 &event);
3600 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003601 } else {
3602 wpa_printf(MSG_DEBUG,
3603 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003604 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003605
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003606fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003607 nlmsg_free(msg);
3608 return ret;
3609}
3610
3611
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003612int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003613{
3614 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003615 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003616 int i;
3617
3618 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3619
3620 os_memset(&params, 0, sizeof(params));
3621 params.freq = drv->auth_freq;
3622 params.auth_alg = drv->auth_alg;
3623 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3624 params.local_state_change = drv->auth_local_state_change;
3625 params.p2p = drv->auth_p2p;
3626
3627 if (!is_zero_ether_addr(drv->auth_bssid_))
3628 params.bssid = drv->auth_bssid_;
3629
3630 if (drv->auth_ssid_len) {
3631 params.ssid = drv->auth_ssid;
3632 params.ssid_len = drv->auth_ssid_len;
3633 }
3634
3635 params.ie = drv->auth_ie;
3636 params.ie_len = drv->auth_ie_len;
3637
3638 for (i = 0; i < 4; i++) {
3639 if (drv->auth_wep_key_len[i]) {
3640 params.wep_key[i] = drv->auth_wep_key[i];
3641 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3642 }
3643 }
3644
3645 drv->retry_auth = 1;
3646 return wpa_driver_nl80211_authenticate(bss, &params);
3647}
3648
3649
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003650static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3651 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003652 int encrypt, int noack,
3653 unsigned int freq, int no_cck,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003654 int offchanok, unsigned int wait_time,
3655 const u16 *csa_offs,
3656 size_t csa_offs_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003657{
3658 struct wpa_driver_nl80211_data *drv = bss->drv;
3659 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003660 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003661
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003662 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3663 freq = nl80211_get_assoc_freq(drv);
3664 wpa_printf(MSG_DEBUG,
3665 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3666 freq);
3667 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003668 if (freq == 0) {
3669 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3670 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003671 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003672 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003673
Dmitry Shmidt56052862013-10-04 10:23:25 -07003674 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003675 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003676 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003677 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003678 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003679
Dmitry Shmidt56052862013-10-04 10:23:25 -07003680 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003681 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003682 &cookie, no_cck, noack, offchanok,
3683 csa_offs, csa_offs_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003684 if (res == 0 && !noack) {
3685 const struct ieee80211_mgmt *mgmt;
3686 u16 fc;
3687
3688 mgmt = (const struct ieee80211_mgmt *) data;
3689 fc = le_to_host16(mgmt->frame_control);
3690 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3691 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3692 wpa_printf(MSG_MSGDUMP,
3693 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3694 (long long unsigned int)
3695 drv->send_action_cookie,
3696 (long long unsigned int) cookie);
3697 drv->send_action_cookie = cookie;
3698 }
3699 }
3700
3701 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003702}
3703
3704
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003705static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3706 size_t data_len, int noack,
3707 unsigned int freq, int no_cck,
3708 int offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003709 unsigned int wait_time,
3710 const u16 *csa_offs,
3711 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003712{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003713 struct wpa_driver_nl80211_data *drv = bss->drv;
3714 struct ieee80211_mgmt *mgmt;
3715 int encrypt = 1;
3716 u16 fc;
3717
3718 mgmt = (struct ieee80211_mgmt *) data;
3719 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003720 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3721 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3722 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3723 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003724
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003725 if ((is_sta_interface(drv->nlmode) ||
3726 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003727 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3728 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3729 /*
3730 * The use of last_mgmt_freq is a bit of a hack,
3731 * but it works due to the single-threaded nature
3732 * of wpa_supplicant.
3733 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003734 if (freq == 0) {
3735 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3736 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003737 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003738 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003739 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003740 data, data_len, NULL, 1, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003741 1, csa_offs, csa_offs_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003742 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003743
3744 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003745 if (freq == 0) {
3746 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3747 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003748 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003749 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003750 return nl80211_send_frame_cmd(bss, freq,
3751 (int) freq == bss->freq ? 0 :
3752 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003753 data, data_len,
3754 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003755 no_cck, noack, offchanok,
3756 csa_offs, csa_offs_len);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003757 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003759 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3760 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3761 /*
3762 * Only one of the authentication frame types is encrypted.
3763 * In order for static WEP encryption to work properly (i.e.,
3764 * to not encrypt the frame), we need to tell mac80211 about
3765 * the frames that must not be encrypted.
3766 */
3767 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3768 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3769 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3770 encrypt = 0;
3771 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003772
Dmitry Shmidt56052862013-10-04 10:23:25 -07003773 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003774 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003775 noack, freq, no_cck, offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003776 wait_time, csa_offs,
3777 csa_offs_len);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003778}
3779
3780
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003781static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3782{
3783 u8 rates[NL80211_MAX_SUPP_RATES];
3784 u8 rates_len = 0;
3785 int i;
3786
3787 if (!basic_rates)
3788 return 0;
3789
3790 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3791 rates[rates_len++] = basic_rates[i] / 5;
3792
3793 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3794}
3795
3796
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003797static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3798 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003799 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003800{
3801 struct wpa_driver_nl80211_data *drv = bss->drv;
3802 struct nl_msg *msg;
3803
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003804 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3805 (cts >= 0 &&
3806 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3807 (preamble >= 0 &&
3808 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3809 (slot >= 0 &&
3810 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3811 (ht_opmode >= 0 &&
3812 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3813 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003814 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3815 nl80211_put_basic_rates(msg, basic_rates)) {
3816 nlmsg_free(msg);
3817 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003818 }
3819
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003820 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003821}
3822
3823
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003824static int wpa_driver_nl80211_set_acl(void *priv,
3825 struct hostapd_acl_params *params)
3826{
3827 struct i802_bss *bss = priv;
3828 struct wpa_driver_nl80211_data *drv = bss->drv;
3829 struct nl_msg *msg;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003830 struct nl_msg *acl;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003831 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003832 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003833
3834 if (!(drv->capa.max_acl_mac_addrs))
3835 return -ENOTSUP;
3836
3837 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3838 return -ENOTSUP;
3839
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003840 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3841 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3842
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003843 acl = nlmsg_alloc();
3844 if (!acl)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003845 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003846 for (i = 0; i < params->num_mac_acl; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003847 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3848 nlmsg_free(acl);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003849 return -ENOMEM;
3850 }
3851 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003852
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003853 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3854 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3855 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3856 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3857 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
3858 nlmsg_free(msg);
3859 nlmsg_free(acl);
3860 return -ENOMEM;
3861 }
3862 nlmsg_free(acl);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003863
3864 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003865 if (ret) {
3866 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3867 ret, strerror(-ret));
3868 }
3869
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003870 return ret;
3871}
3872
3873
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003874static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3875{
3876 if (beacon_int > 0) {
3877 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3878 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3879 beacon_int);
3880 }
3881
3882 return 0;
3883}
3884
3885
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003886static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period)
3887{
3888 if (dtim_period > 0) {
3889 wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period);
3890 return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
3891 }
3892
3893 return 0;
3894}
3895
3896
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003897#ifdef CONFIG_MESH
3898static int nl80211_set_mesh_config(void *priv,
3899 struct wpa_driver_mesh_bss_params *params)
3900{
3901 struct i802_bss *bss = priv;
3902 struct wpa_driver_nl80211_data *drv = bss->drv;
3903 struct nl_msg *msg;
3904 int ret;
3905
3906 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG);
3907 if (!msg)
3908 return -1;
3909
3910 ret = nl80211_put_mesh_config(msg, params);
3911 if (ret < 0) {
3912 nlmsg_free(msg);
3913 return ret;
3914 }
3915
3916 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3917 if (ret) {
3918 wpa_printf(MSG_ERROR,
3919 "nl80211: Mesh config set failed: %d (%s)",
3920 ret, strerror(-ret));
3921 return ret;
3922 }
3923 return 0;
3924}
3925#endif /* CONFIG_MESH */
3926
3927
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003928static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags,
3929 struct wpa_driver_ap_params *params)
3930{
3931 struct nlattr *bands, *band;
3932 struct nl80211_txrate_vht vht_rate;
3933
3934 if (!params->freq ||
3935 (params->beacon_rate == 0 &&
3936 params->rate_type == BEACON_RATE_LEGACY))
3937 return 0;
3938
3939 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
3940 if (!bands)
3941 return -1;
3942
3943 switch (params->freq->mode) {
3944 case HOSTAPD_MODE_IEEE80211B:
3945 case HOSTAPD_MODE_IEEE80211G:
3946 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
3947 break;
3948 case HOSTAPD_MODE_IEEE80211A:
3949 band = nla_nest_start(msg, NL80211_BAND_5GHZ);
3950 break;
3951 case HOSTAPD_MODE_IEEE80211AD:
3952 band = nla_nest_start(msg, NL80211_BAND_60GHZ);
3953 break;
3954 default:
3955 return 0;
3956 }
3957
3958 if (!band)
3959 return -1;
3960
3961 os_memset(&vht_rate, 0, sizeof(vht_rate));
3962
3963 switch (params->rate_type) {
3964 case BEACON_RATE_LEGACY:
3965 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) {
3966 wpa_printf(MSG_INFO,
3967 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
3968 return -1;
3969 }
3970
3971 if (nla_put_u8(msg, NL80211_TXRATE_LEGACY,
3972 (u8) params->beacon_rate / 5) ||
3973 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
3974 (params->freq->vht_enabled &&
3975 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3976 &vht_rate)))
3977 return -1;
3978
3979 wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)",
3980 params->beacon_rate);
3981 break;
3982 case BEACON_RATE_HT:
3983 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) {
3984 wpa_printf(MSG_INFO,
3985 "nl80211: Driver does not support setting Beacon frame rate (HT)");
3986 return -1;
3987 }
3988 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
3989 nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) ||
3990 (params->freq->vht_enabled &&
3991 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3992 &vht_rate)))
3993 return -1;
3994 wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u",
3995 params->beacon_rate);
3996 break;
3997 case BEACON_RATE_VHT:
3998 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) {
3999 wpa_printf(MSG_INFO,
4000 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
4001 return -1;
4002 }
4003 vht_rate.mcs[0] = BIT(params->beacon_rate);
4004 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL))
4005 return -1;
4006 if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL))
4007 return -1;
4008 if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4009 &vht_rate))
4010 return -1;
4011 wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u",
4012 params->beacon_rate);
4013 break;
4014 }
4015
4016 nla_nest_end(msg, band);
4017 nla_nest_end(msg, bands);
4018
4019 return 0;
4020}
4021
4022
4023static int nl80211_set_multicast_to_unicast(struct i802_bss *bss,
4024 int multicast_to_unicast)
4025{
4026 struct wpa_driver_nl80211_data *drv = bss->drv;
4027 struct nl_msg *msg;
4028 int ret;
4029
4030 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST);
4031 if (!msg ||
4032 (multicast_to_unicast &&
4033 nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) {
4034 wpa_printf(MSG_ERROR,
4035 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
4036 bss->ifname);
4037 nlmsg_free(msg);
4038 return -ENOBUFS;
4039 }
4040
4041 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4042
4043 switch (ret) {
4044 case 0:
4045 wpa_printf(MSG_DEBUG,
4046 "nl80211: multicast to unicast %s on interface %s",
4047 multicast_to_unicast ? "enabled" : "disabled",
4048 bss->ifname);
4049 break;
4050 case -EOPNOTSUPP:
4051 if (!multicast_to_unicast)
4052 break;
4053 wpa_printf(MSG_INFO,
4054 "nl80211: multicast to unicast not supported on interface %s",
4055 bss->ifname);
4056 break;
4057 default:
4058 wpa_printf(MSG_ERROR,
4059 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
4060 multicast_to_unicast ? "enabling" : "disabling",
4061 ret, strerror(-ret), bss->ifname);
4062 break;
4063 }
4064
4065 return ret;
4066}
4067
4068
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004069static int wpa_driver_nl80211_set_ap(void *priv,
4070 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004071{
4072 struct i802_bss *bss = priv;
4073 struct wpa_driver_nl80211_data *drv = bss->drv;
4074 struct nl_msg *msg;
4075 u8 cmd = NL80211_CMD_NEW_BEACON;
Hai Shalom74f70d42019-02-11 14:42:39 -08004076 int ret = -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004077 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004078 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004079 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004080 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004081 u32 ver;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004082#ifdef CONFIG_MESH
4083 struct wpa_driver_mesh_bss_params mesh_params;
4084#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004085
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004086 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004088 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
4089 beacon_set);
4090 if (beacon_set)
4091 cmd = NL80211_CMD_SET_BEACON;
Paul Stewart092955c2017-02-06 09:13:09 -08004092 else if (!drv->device_ap_sme && !drv->use_monitor &&
4093 !nl80211_get_wiphy_data_ap(bss))
4094 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004096 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
4097 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004098 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
4099 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004100 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004101 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004102 wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate);
4103 wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004104 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Hai Shalom74f70d42019-02-11 14:42:39 -08004105 wpa_printf(MSG_DEBUG, "nl80211: ssid=%s",
4106 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004107 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
4108 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
4109 params->head) ||
4110 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
4111 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004112 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004113 nl80211_put_beacon_rate(msg, drv->capa.flags, params) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004114 nl80211_put_dtim_period(msg, params->dtim_period) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004115 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4116 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004117 if (params->proberesp && params->proberesp_len) {
4118 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
4119 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004120 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
4121 params->proberesp))
4122 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004123 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004124 switch (params->hide_ssid) {
4125 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004126 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004127 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4128 NL80211_HIDDEN_SSID_NOT_IN_USE))
4129 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004130 break;
4131 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004132 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004133 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4134 NL80211_HIDDEN_SSID_ZERO_LEN))
4135 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004136 break;
4137 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004138 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004139 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4140 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
4141 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004142 break;
4143 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004144 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004145 if (params->privacy &&
4146 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
4147 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004148 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004149 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
4150 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
4151 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004152 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
4153 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4154 NL80211_AUTHTYPE_SHARED_KEY))
4155 goto fail;
4156 } else {
4157 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4158 NL80211_AUTHTYPE_OPEN_SYSTEM))
4159 goto fail;
4160 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004161
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004162 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004163 ver = 0;
4164 if (params->wpa_version & WPA_PROTO_WPA)
4165 ver |= NL80211_WPA_VERSION_1;
4166 if (params->wpa_version & WPA_PROTO_RSN)
4167 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004168 if (ver &&
4169 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4170 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004171
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004172 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
4173 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004174 num_suites = 0;
4175 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
Paul Stewart092955c2017-02-06 09:13:09 -08004176 suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004177 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
Paul Stewart092955c2017-02-06 09:13:09 -08004178 suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004179 if (num_suites &&
4180 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
4181 suites))
4182 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004183
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004184 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004185 (!params->pairwise_ciphers ||
4186 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
4187 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
4188 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004189 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004190
Hai Shalom81f62d82019-07-22 12:10:00 -07004191 if (drv->device_ap_sme &&
4192 (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) &&
4193 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
4194 goto fail;
Hai Shalom5f92bc92019-04-18 11:54:11 -07004195
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004196 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
4197 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004198 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
4199 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004200 if (num_suites &&
4201 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4202 num_suites * sizeof(u32), suites))
4203 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004204
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004205 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
4206 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004207 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004208 if (suite &&
4209 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
4210 goto fail;
4211
Dmitry Shmidte4663042016-04-04 10:07:49 -07004212 if (params->ht_opmode != -1) {
4213 switch (params->smps_mode) {
4214 case HT_CAP_INFO_SMPS_DYNAMIC:
4215 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
4216 smps_mode = NL80211_SMPS_DYNAMIC;
4217 break;
4218 case HT_CAP_INFO_SMPS_STATIC:
4219 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
4220 smps_mode = NL80211_SMPS_STATIC;
4221 break;
4222 default:
4223 /* invalid - fallback to smps off */
4224 case HT_CAP_INFO_SMPS_DISABLED:
4225 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
4226 smps_mode = NL80211_SMPS_OFF;
4227 break;
4228 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004229 if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
Dmitry Shmidte4663042016-04-04 10:07:49 -07004230 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004231 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004232
4233 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004234 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
4235 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004236 if (nla_put(msg, NL80211_ATTR_IE,
4237 wpabuf_len(params->beacon_ies),
4238 wpabuf_head(params->beacon_ies)))
4239 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004240 }
4241 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004242 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
4243 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004244 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
4245 wpabuf_len(params->proberesp_ies),
4246 wpabuf_head(params->proberesp_ies)))
4247 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004248 }
4249 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004250 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
4251 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004252 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
4253 wpabuf_len(params->assocresp_ies),
4254 wpabuf_head(params->assocresp_ies)))
4255 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004257
Dmitry Shmidt04949592012-07-19 12:16:46 -07004258 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004259 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
4260 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004261 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
4262 params->ap_max_inactivity))
4263 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004264 }
4265
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004266#ifdef CONFIG_P2P
4267 if (params->p2p_go_ctwindow > 0) {
4268 if (drv->p2p_go_ctwindow_supported) {
4269 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
4270 params->p2p_go_ctwindow);
4271 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
4272 params->p2p_go_ctwindow))
4273 goto fail;
4274 } else {
4275 wpa_printf(MSG_INFO,
4276 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4277 }
4278 }
4279#endif /* CONFIG_P2P */
4280
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004281 if (params->pbss) {
4282 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
4283 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
4284 goto fail;
4285 }
4286
Hai Shalom74f70d42019-02-11 14:42:39 -08004287 if (params->ftm_responder) {
4288 struct nlattr *ftm;
4289
4290 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) {
4291 ret = -ENOTSUP;
4292 goto fail;
4293 }
4294
4295 ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER);
4296 if (!ftm ||
4297 nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) ||
4298 (params->lci &&
4299 nla_put(msg, NL80211_FTM_RESP_ATTR_LCI,
4300 wpabuf_len(params->lci),
4301 wpabuf_head(params->lci))) ||
4302 (params->civic &&
4303 nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC,
4304 wpabuf_len(params->civic),
4305 wpabuf_head(params->civic))))
4306 goto fail;
4307 nla_nest_end(msg, ftm);
4308 }
4309
Hai Shalomc3565922019-10-28 11:58:20 -07004310#ifdef CONFIG_IEEE80211AX
4311 if (params->he_spr) {
4312 struct nlattr *spr;
4313
4314 spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD);
4315 wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr);
4316
4317 if (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET,
4318 params->he_spr_srg_obss_pd_min_offset) ||
4319 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET,
4320 params->he_spr_srg_obss_pd_max_offset))
4321 goto fail;
4322
4323 nla_nest_end(msg, spr);
4324 }
4325#endif /* CONFIG_IEEE80211AX */
4326
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004327 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4328 if (ret) {
4329 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
4330 ret, strerror(-ret));
4331 } else {
4332 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004333 nl80211_set_bss(bss, params->cts_protect, params->preamble,
4334 params->short_slot_time, params->ht_opmode,
4335 params->isolate, params->basic_rates);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004336 nl80211_set_multicast_to_unicast(bss,
4337 params->multicast_to_unicast);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004338 if (beacon_set && params->freq &&
4339 params->freq->bandwidth != bss->bandwidth) {
4340 wpa_printf(MSG_DEBUG,
4341 "nl80211: Update BSS %s bandwidth: %d -> %d",
4342 bss->ifname, bss->bandwidth,
4343 params->freq->bandwidth);
4344 ret = nl80211_set_channel(bss, params->freq, 1);
4345 if (ret) {
4346 wpa_printf(MSG_DEBUG,
4347 "nl80211: Frequency set failed: %d (%s)",
4348 ret, strerror(-ret));
4349 } else {
4350 wpa_printf(MSG_DEBUG,
4351 "nl80211: Frequency set succeeded for ht2040 coex");
4352 bss->bandwidth = params->freq->bandwidth;
4353 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004354 } else if (!beacon_set && params->freq) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004355 /*
4356 * cfg80211 updates the driver on frequence change in AP
4357 * mode only at the point when beaconing is started, so
4358 * set the initial value here.
4359 */
4360 bss->bandwidth = params->freq->bandwidth;
4361 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004362 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004363
4364#ifdef CONFIG_MESH
4365 if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) {
4366 os_memset(&mesh_params, 0, sizeof(mesh_params));
4367 mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
4368 mesh_params.ht_opmode = params->ht_opmode;
4369 ret = nl80211_set_mesh_config(priv, &mesh_params);
4370 if (ret < 0)
4371 return ret;
4372 }
4373#endif /* CONFIG_MESH */
4374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004375 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004376fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004377 nlmsg_free(msg);
Hai Shalom74f70d42019-02-11 14:42:39 -08004378 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004379}
4380
4381
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004382static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004383 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004384{
Hai Shalomc3565922019-10-28 11:58:20 -07004385 enum hostapd_hw_mode hw_mode;
4386 int is_24ghz;
4387 u8 channel;
4388
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004389 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004390 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
4391 return -ENOBUFS;
4392
Hai Shalom81f62d82019-07-22 12:10:00 -07004393 wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004394 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
4395 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
4396
Hai Shalomc3565922019-10-28 11:58:20 -07004397 hw_mode = ieee80211_freq_to_chan(freq->freq, &channel);
4398 is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G ||
4399 hw_mode == HOSTAPD_MODE_IEEE80211B;
4400
4401 if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004402 enum nl80211_chan_width cw;
4403
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004404 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004405 switch (freq->bandwidth) {
4406 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004407 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004408 break;
4409 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004410 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004411 break;
4412 case 80:
4413 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004414 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004415 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004416 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004417 break;
4418 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004419 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004420 break;
4421 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004422 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004423 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004424
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004425 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
4426 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
4427 freq->center_freq1);
4428 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
4429 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004430 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
4431 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
4432 freq->center_freq1) ||
4433 (freq->center_freq2 &&
4434 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
4435 freq->center_freq2)))
4436 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004437 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004438 enum nl80211_channel_type ct;
4439
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004440 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
4441 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004442 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004443 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004444 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004445 break;
4446 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004447 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448 break;
4449 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004450 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004451 break;
4452 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004453
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004454 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004455 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
4456 return -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07004457 } else if (freq->edmg.channels && freq->edmg.bw_config) {
4458 wpa_printf(MSG_DEBUG,
4459 " * EDMG configuration: channels=0x%x bw_config=%d",
4460 freq->edmg.channels, freq->edmg.bw_config);
4461 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
4462 freq->edmg.channels) ||
4463 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
4464 freq->edmg.bw_config))
4465 return -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004466 } else {
4467 wpa_printf(MSG_DEBUG, " * channel_type=%d",
4468 NL80211_CHAN_NO_HT);
4469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
4470 NL80211_CHAN_NO_HT))
4471 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004473 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004474}
4475
4476
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004477static int nl80211_set_channel(struct i802_bss *bss,
4478 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004479{
4480 struct wpa_driver_nl80211_data *drv = bss->drv;
4481 struct nl_msg *msg;
4482 int ret;
4483
4484 wpa_printf(MSG_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07004485 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4486 freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004487 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004488
4489 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
4490 NL80211_CMD_SET_WIPHY);
4491 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
4492 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004493 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004494 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495
4496 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004497 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004498 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004499 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004500 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004501 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004502 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004503 return -1;
4504}
4505
4506
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004507static u32 sta_flags_nl80211(int flags)
4508{
4509 u32 f = 0;
4510
4511 if (flags & WPA_STA_AUTHORIZED)
4512 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
4513 if (flags & WPA_STA_WMM)
4514 f |= BIT(NL80211_STA_FLAG_WME);
4515 if (flags & WPA_STA_SHORT_PREAMBLE)
4516 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
4517 if (flags & WPA_STA_MFP)
4518 f |= BIT(NL80211_STA_FLAG_MFP);
4519 if (flags & WPA_STA_TDLS_PEER)
4520 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004521 if (flags & WPA_STA_AUTHENTICATED)
4522 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004523 if (flags & WPA_STA_ASSOCIATED)
4524 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004525
4526 return f;
4527}
4528
4529
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004530#ifdef CONFIG_MESH
4531static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
4532{
4533 switch (state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004534 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004535 return NL80211_PLINK_LISTEN;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004536 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004537 return NL80211_PLINK_OPN_SNT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004538 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004539 return NL80211_PLINK_OPN_RCVD;
4540 case PLINK_CNF_RCVD:
4541 return NL80211_PLINK_CNF_RCVD;
4542 case PLINK_ESTAB:
4543 return NL80211_PLINK_ESTAB;
4544 case PLINK_HOLDING:
4545 return NL80211_PLINK_HOLDING;
4546 case PLINK_BLOCKED:
4547 return NL80211_PLINK_BLOCKED;
4548 default:
4549 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
4550 state);
4551 }
4552 return -1;
4553}
4554#endif /* CONFIG_MESH */
4555
4556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004557static int wpa_driver_nl80211_sta_add(void *priv,
4558 struct hostapd_sta_add_params *params)
4559{
4560 struct i802_bss *bss = priv;
4561 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004562 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004563 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004564 int ret = -ENOBUFS;
4565
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004566 if ((params->flags & WPA_STA_TDLS_PEER) &&
4567 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
4568 return -EOPNOTSUPP;
4569
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004570 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
4571 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004572 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
4573 NL80211_CMD_NEW_STATION);
4574 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
4575 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004576
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004577 /*
4578 * Set the below properties only in one of the following cases:
4579 * 1. New station is added, already associated.
4580 * 2. Set WPA_STA_TDLS_PEER station.
4581 * 3. Set an already added unassociated station, if driver supports
4582 * full AP client state. (Set these properties after station became
4583 * associated will be rejected by the driver).
4584 */
4585 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4586 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4587 (params->flags & WPA_STA_ASSOCIATED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004588 wpa_hexdump(MSG_DEBUG, " * supported rates",
4589 params->supp_rates, params->supp_rates_len);
4590 wpa_printf(MSG_DEBUG, " * capability=0x%x",
4591 params->capability);
4592 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
4593 params->supp_rates_len, params->supp_rates) ||
4594 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
4595 params->capability))
4596 goto fail;
4597
4598 if (params->ht_capabilities) {
4599 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
4600 (u8 *) params->ht_capabilities,
4601 sizeof(*params->ht_capabilities));
4602 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
4603 sizeof(*params->ht_capabilities),
4604 params->ht_capabilities))
4605 goto fail;
4606 }
4607
4608 if (params->vht_capabilities) {
4609 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
4610 (u8 *) params->vht_capabilities,
4611 sizeof(*params->vht_capabilities));
4612 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
4613 sizeof(*params->vht_capabilities),
4614 params->vht_capabilities))
4615 goto fail;
4616 }
4617
Hai Shalom81f62d82019-07-22 12:10:00 -07004618 if (params->he_capab) {
4619 wpa_hexdump(MSG_DEBUG, " * he_capab",
4620 params->he_capab, params->he_capab_len);
4621 if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY,
4622 params->he_capab_len, params->he_capab))
4623 goto fail;
4624 }
4625
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004626 if (params->ext_capab) {
4627 wpa_hexdump(MSG_DEBUG, " * ext_capab",
4628 params->ext_capab, params->ext_capab_len);
4629 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
4630 params->ext_capab_len, params->ext_capab))
4631 goto fail;
4632 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004633
4634 if (is_ap_interface(drv->nlmode) &&
4635 nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS,
4636 params->support_p2p_ps ?
4637 NL80211_P2P_PS_SUPPORTED :
4638 NL80211_P2P_PS_UNSUPPORTED))
4639 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004640 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004641 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004642 if (params->aid) {
4643 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
4645 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004646 } else {
4647 /*
4648 * cfg80211 validates that AID is non-zero, so we have
4649 * to make this a non-zero value for the TDLS case where
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004650 * a dummy STA entry is used for now and for a station
4651 * that is still not associated.
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004652 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004653 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
4654 (params->flags & WPA_STA_TDLS_PEER) ?
4655 "TDLS" : "UNASSOC_STA");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004656 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
4657 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004658 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004659 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4660 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004661 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4662 params->listen_interval))
4663 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004664 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
4665 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004666 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
4667 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004668 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4669 (params->flags & WPA_STA_ASSOCIATED)) {
4670 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
4671 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4672 params->listen_interval);
4673 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
4674 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4675 params->listen_interval))
4676 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004677 }
4678
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004679 if (params->vht_opmode_enabled) {
4680 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004681 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
4682 params->vht_opmode))
4683 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004684 }
4685
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004686 if (params->supp_channels) {
4687 wpa_hexdump(MSG_DEBUG, " * supported channels",
4688 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004689 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
4690 params->supp_channels_len, params->supp_channels))
4691 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004692 }
4693
4694 if (params->supp_oper_classes) {
4695 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
4696 params->supp_oper_classes,
4697 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004698 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
4699 params->supp_oper_classes_len,
4700 params->supp_oper_classes))
4701 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004702 }
4703
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004704 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004705 upd.set = sta_flags_nl80211(params->flags);
4706 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004707
4708 /*
4709 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4710 * flags, as nl80211 driver moves a new station, by default, into
4711 * associated state.
4712 *
4713 * On the other hand, if the driver supports that feature and the
4714 * station is added in unauthenticated state, set the
4715 * authenticated/associated bits in the mask to prevent moving this
4716 * station to associated state before it is actually associated.
4717 *
4718 * This is irrelevant for mesh mode where the station is added to the
4719 * driver as authenticated already, and ASSOCIATED isn't part of the
4720 * nl80211 API.
4721 */
4722 if (!is_mesh_interface(drv->nlmode)) {
4723 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
4724 wpa_printf(MSG_DEBUG,
4725 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4726 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
4727 BIT(NL80211_STA_FLAG_AUTHENTICATED));
4728 } else if (!params->set &&
4729 !(params->flags & WPA_STA_TDLS_PEER)) {
4730 if (!(params->flags & WPA_STA_AUTHENTICATED))
4731 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
4732 if (!(params->flags & WPA_STA_ASSOCIATED))
4733 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
4734 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004735#ifdef CONFIG_MESH
4736 } else {
4737 if (params->plink_state == PLINK_ESTAB && params->peer_aid) {
4738 ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID,
4739 params->peer_aid);
4740 if (ret)
4741 goto fail;
4742 }
4743#endif /* CONFIG_MESH */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004744 }
4745
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004746 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
4747 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004748 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4749 goto fail;
4750
4751#ifdef CONFIG_MESH
4752 if (params->plink_state &&
4753 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
4754 sta_plink_state_nl80211(params->plink_state)))
4755 goto fail;
4756#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004757
Hai Shalomc3565922019-10-28 11:58:20 -07004758 if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4759 FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) &&
4760 (params->flags & WPA_STA_WMM)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004761 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
4762
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004763 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004764 if (!wme ||
4765 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
4766 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
4767 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
4768 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
4769 WMM_QOSINFO_STA_SP_MASK))
4770 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004771 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004772 }
4773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004774 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004775 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004777 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
4778 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
4779 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004780 if (ret == -EEXIST)
4781 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004782fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004783 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004784 return ret;
4785}
4786
4787
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004788static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
4789{
4790#ifdef CONFIG_LIBNL3_ROUTE
4791 struct wpa_driver_nl80211_data *drv = bss->drv;
4792 struct rtnl_neigh *rn;
4793 struct nl_addr *nl_addr;
4794 int err;
4795
4796 rn = rtnl_neigh_alloc();
4797 if (!rn)
4798 return;
4799
4800 rtnl_neigh_set_family(rn, AF_BRIDGE);
4801 rtnl_neigh_set_ifindex(rn, bss->ifindex);
4802 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
4803 if (!nl_addr) {
4804 rtnl_neigh_put(rn);
4805 return;
4806 }
4807 rtnl_neigh_set_lladdr(rn, nl_addr);
4808
4809 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
4810 if (err < 0) {
4811 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
4812 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
4813 bss->ifindex, nl_geterror(err));
4814 } else {
4815 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
4816 MACSTR, MAC2STR(addr));
4817 }
4818
4819 nl_addr_put(nl_addr);
4820 rtnl_neigh_put(rn);
4821#endif /* CONFIG_LIBNL3_ROUTE */
4822}
4823
4824
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004825static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
4826 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004827{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004828 struct wpa_driver_nl80211_data *drv = bss->drv;
4829 struct nl_msg *msg;
4830 int ret;
4831
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004832 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
4833 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
4834 (deauth == 0 &&
4835 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4836 WLAN_FC_STYPE_DISASSOC)) ||
4837 (deauth == 1 &&
4838 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4839 WLAN_FC_STYPE_DEAUTH)) ||
4840 (reason_code &&
4841 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
4842 nlmsg_free(msg);
4843 return -ENOBUFS;
4844 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004845
4846 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004847 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4848 " --> %d (%s)",
4849 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004850
4851 if (drv->rtnl_sk)
4852 rtnl_neigh_delete_fdb_entry(bss, addr);
4853
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004854 if (ret == -ENOENT)
4855 return 0;
4856 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004857}
4858
4859
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004860void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004861{
4862 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004863 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004864
4865 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
4866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004868 dl_list_for_each(drv2, &drv->global->interfaces,
4869 struct wpa_driver_nl80211_data, list)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004870 {
4871 del_ifidx(drv2, ifidx, IFIDX_ANY);
4872 /* Remove all bridges learned for this iface */
4873 del_ifidx(drv2, IFIDX_ANY, ifidx);
4874 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004875
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004876 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004877 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
4878 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
4880}
4881
4882
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004883const char * nl80211_iftype_str(enum nl80211_iftype mode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004884{
4885 switch (mode) {
4886 case NL80211_IFTYPE_ADHOC:
4887 return "ADHOC";
4888 case NL80211_IFTYPE_STATION:
4889 return "STATION";
4890 case NL80211_IFTYPE_AP:
4891 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004892 case NL80211_IFTYPE_AP_VLAN:
4893 return "AP_VLAN";
4894 case NL80211_IFTYPE_WDS:
4895 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004896 case NL80211_IFTYPE_MONITOR:
4897 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004898 case NL80211_IFTYPE_MESH_POINT:
4899 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004900 case NL80211_IFTYPE_P2P_CLIENT:
4901 return "P2P_CLIENT";
4902 case NL80211_IFTYPE_P2P_GO:
4903 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004904 case NL80211_IFTYPE_P2P_DEVICE:
4905 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004906 default:
4907 return "unknown";
4908 }
4909}
4910
4911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004912static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
4913 const char *ifname,
4914 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004915 const u8 *addr, int wds,
4916 int (*handler)(struct nl_msg *, void *),
4917 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004918{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004919 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004920 int ifidx;
4921 int ret = -ENOBUFS;
4922
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004923 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
4924 iftype, nl80211_iftype_str(iftype));
4925
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004926 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
4927 if (!msg ||
4928 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
4929 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
4930 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004931
4932 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004933 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004934
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004935 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004936 if (!flags ||
4937 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
4938 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004939
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004940 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004941 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004942 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
4943 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004944 }
4945
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004946 /*
4947 * Tell cfg80211 that the interface belongs to the socket that created
4948 * it, and the interface should be deleted when the socket is closed.
4949 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004950 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
4951 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004952
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004953 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004954 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004955 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004956 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004957 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004958 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4959 ifname, ret, strerror(-ret));
4960 return ret;
4961 }
4962
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004963 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4964 return 0;
4965
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004966 ifidx = if_nametoindex(ifname);
4967 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4968 ifname, ifidx);
4969
4970 if (ifidx <= 0)
4971 return -1;
4972
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004973 /*
4974 * Some virtual interfaces need to process EAPOL packets and events on
4975 * the parent interface. This is used mainly with hostapd.
4976 */
4977 if (drv->hostapd ||
4978 iftype == NL80211_IFTYPE_AP_VLAN ||
4979 iftype == NL80211_IFTYPE_WDS ||
4980 iftype == NL80211_IFTYPE_MONITOR) {
4981 /* start listening for EAPOL on this interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004982 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004983 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004984
4985 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004986 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987 nl80211_remove_iface(drv, ifidx);
4988 return -1;
4989 }
4990
4991 return ifidx;
4992}
4993
4994
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004995int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4996 const char *ifname, enum nl80211_iftype iftype,
4997 const u8 *addr, int wds,
4998 int (*handler)(struct nl_msg *, void *),
4999 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005000{
5001 int ret;
5002
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005003 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
5004 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005005
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005006 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005007 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005008 if (use_existing) {
5009 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
5010 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005011 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
5012 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
5013 addr) < 0 &&
5014 (linux_set_iface_flags(drv->global->ioctl_sock,
5015 ifname, 0) < 0 ||
5016 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
5017 addr) < 0 ||
5018 linux_set_iface_flags(drv->global->ioctl_sock,
5019 ifname, 1) < 0))
5020 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005021 return -ENFILE;
5022 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005023 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
5024
5025 /* Try to remove the interface that was already there. */
5026 nl80211_remove_iface(drv, if_nametoindex(ifname));
5027
5028 /* Try to create the interface again */
5029 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005030 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005031 }
5032
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005033 if (ret >= 0 && is_p2p_net_interface(iftype)) {
5034 wpa_printf(MSG_DEBUG,
5035 "nl80211: Interface %s created for P2P - disable 11b rates",
5036 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005037 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005039
5040 return ret;
5041}
5042
5043
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005044static int nl80211_setup_ap(struct i802_bss *bss)
5045{
5046 struct wpa_driver_nl80211_data *drv = bss->drv;
5047
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005048 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
5049 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005050
5051 /*
5052 * Disable Probe Request reporting unless we need it in this way for
5053 * devices that include the AP SME, in the other case (unless using
5054 * monitor iface) we'll get it through the nl_mgmt socket instead.
5055 */
5056 if (!drv->device_ap_sme)
5057 wpa_driver_nl80211_probe_req_report(bss, 0);
5058
5059 if (!drv->device_ap_sme && !drv->use_monitor)
5060 if (nl80211_mgmt_subscribe_ap(bss))
5061 return -1;
5062
5063 if (drv->device_ap_sme && !drv->use_monitor)
5064 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005065 wpa_printf(MSG_DEBUG,
5066 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005067
5068 if (!drv->device_ap_sme && drv->use_monitor &&
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005069 nl80211_create_monitor_interface(drv) &&
5070 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005071 return -1;
5072
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005073 if (drv->device_ap_sme &&
5074 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
5075 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
5076 "Probe Request frame reporting in AP mode");
5077 /* Try to survive without this */
5078 }
5079
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005080 return 0;
5081}
5082
5083
5084static void nl80211_teardown_ap(struct i802_bss *bss)
5085{
5086 struct wpa_driver_nl80211_data *drv = bss->drv;
5087
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005088 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
5089 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005090 if (drv->device_ap_sme) {
5091 wpa_driver_nl80211_probe_req_report(bss, 0);
5092 if (!drv->use_monitor)
5093 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
5094 } else if (drv->use_monitor)
5095 nl80211_remove_monitor_interface(drv);
5096 else
5097 nl80211_mgmt_unsubscribe(bss, "AP teardown");
5098
Paul Stewart092955c2017-02-06 09:13:09 -08005099 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005100 bss->beacon_set = 0;
5101}
5102
5103
5104static int nl80211_send_eapol_data(struct i802_bss *bss,
5105 const u8 *addr, const u8 *data,
5106 size_t data_len)
5107{
5108 struct sockaddr_ll ll;
5109 int ret;
5110
5111 if (bss->drv->eapol_tx_sock < 0) {
5112 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
5113 return -1;
5114 }
5115
5116 os_memset(&ll, 0, sizeof(ll));
5117 ll.sll_family = AF_PACKET;
5118 ll.sll_ifindex = bss->ifindex;
5119 ll.sll_protocol = htons(ETH_P_PAE);
5120 ll.sll_halen = ETH_ALEN;
5121 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
5122 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
5123 (struct sockaddr *) &ll, sizeof(ll));
5124 if (ret < 0)
5125 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
5126 strerror(errno));
5127
5128 return ret;
5129}
5130
5131
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005132static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5133
5134static int wpa_driver_nl80211_hapd_send_eapol(
5135 void *priv, const u8 *addr, const u8 *data,
5136 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
5137{
5138 struct i802_bss *bss = priv;
5139 struct wpa_driver_nl80211_data *drv = bss->drv;
5140 struct ieee80211_hdr *hdr;
5141 size_t len;
5142 u8 *pos;
5143 int res;
5144 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08005145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005146 if (drv->device_ap_sme || !drv->use_monitor)
5147 return nl80211_send_eapol_data(bss, addr, data, data_len);
5148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005149 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
5150 data_len;
5151 hdr = os_zalloc(len);
5152 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005153 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
5154 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155 return -1;
5156 }
5157
5158 hdr->frame_control =
5159 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
5160 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
5161 if (encrypt)
5162 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
5163 if (qos) {
5164 hdr->frame_control |=
5165 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
5166 }
5167
5168 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
5169 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
5170 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
5171 pos = (u8 *) (hdr + 1);
5172
5173 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005174 /* Set highest priority in QoS header */
5175 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005176 pos[1] = 0;
5177 pos += 2;
5178 }
5179
5180 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
5181 pos += sizeof(rfc1042_header);
5182 WPA_PUT_BE16(pos, ETH_P_PAE);
5183 pos += 2;
5184 memcpy(pos, data, data_len);
5185
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005186 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005187 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005188 if (res < 0) {
5189 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
5190 "failed: %d (%s)",
5191 (unsigned long) len, errno, strerror(errno));
5192 }
5193 os_free(hdr);
5194
5195 return res;
5196}
5197
5198
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005200 unsigned int total_flags,
5201 unsigned int flags_or,
5202 unsigned int flags_and)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005203{
5204 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005205 struct nl_msg *msg;
5206 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005207 struct nl80211_sta_flag_update upd;
5208
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005209 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
5210 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
5211 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
5212 !!(total_flags & WPA_STA_AUTHORIZED));
5213
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005214 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5215 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
5216 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005217
5218 /*
5219 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5220 * can be removed eventually.
5221 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005222 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005223 if (!flags ||
5224 ((total_flags & WPA_STA_AUTHORIZED) &&
5225 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
5226 ((total_flags & WPA_STA_WMM) &&
5227 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
5228 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
5229 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
5230 ((total_flags & WPA_STA_MFP) &&
5231 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
5232 ((total_flags & WPA_STA_TDLS_PEER) &&
5233 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
5234 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005235
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005236 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005237
5238 os_memset(&upd, 0, sizeof(upd));
5239 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
5240 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005241 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
5242 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005244 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5245fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005246 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005247 return -ENOBUFS;
5248}
5249
5250
Hai Shalom81f62d82019-07-22 12:10:00 -07005251static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr,
5252 unsigned int weight)
5253{
5254 struct i802_bss *bss = priv;
5255 struct nl_msg *msg;
5256
5257 wpa_printf(MSG_DEBUG,
5258 "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR
5259 " weight=%u", bss->ifname, MAC2STR(addr), weight);
5260
5261 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5262 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5263 nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight))
5264 goto fail;
5265
5266 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5267fail:
5268 nlmsg_free(msg);
5269 return -ENOBUFS;
5270}
5271
5272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005273static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
5274 struct wpa_driver_associate_params *params)
5275{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005276 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005277
5278 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005279 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
5280 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005281 nlmode = NL80211_IFTYPE_P2P_GO;
5282 } else
5283 nlmode = NL80211_IFTYPE_AP;
5284
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005285 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005286 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005287 nl80211_remove_monitor_interface(drv);
5288 return -1;
5289 }
5290
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005291 if (params->freq.freq &&
5292 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005293 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005294 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005295 nl80211_remove_monitor_interface(drv);
5296 return -1;
5297 }
5298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005299 return 0;
5300}
5301
5302
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005303static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
5304 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005305{
5306 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005307 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005308
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005309 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005310 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311 if (ret) {
5312 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
5313 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005314 } else {
5315 wpa_printf(MSG_DEBUG,
5316 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005317 }
5318
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005319 if (reset_mode &&
5320 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07005321 NL80211_IFTYPE_STATION)) {
5322 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5323 "station mode");
5324 }
5325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005326 return ret;
5327}
5328
5329
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005330static int nl80211_ht_vht_overrides(struct nl_msg *msg,
5331 struct wpa_driver_associate_params *params)
5332{
5333 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
5334 return -1;
5335
5336 if (params->htcaps && params->htcaps_mask) {
5337 int sz = sizeof(struct ieee80211_ht_capabilities);
5338 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
5339 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
5340 params->htcaps_mask, sz);
5341 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
5342 params->htcaps) ||
5343 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
5344 params->htcaps_mask))
5345 return -1;
5346 }
5347
5348#ifdef CONFIG_VHT_OVERRIDES
5349 if (params->disable_vht) {
5350 wpa_printf(MSG_DEBUG, " * VHT disabled");
5351 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
5352 return -1;
5353 }
5354
5355 if (params->vhtcaps && params->vhtcaps_mask) {
5356 int sz = sizeof(struct ieee80211_vht_capabilities);
5357 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
5358 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
5359 params->vhtcaps_mask, sz);
5360 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
5361 params->vhtcaps) ||
5362 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
5363 params->vhtcaps_mask))
5364 return -1;
5365 }
5366#endif /* CONFIG_VHT_OVERRIDES */
5367
5368 return 0;
5369}
5370
5371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005372static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
5373 struct wpa_driver_associate_params *params)
5374{
5375 struct nl_msg *msg;
5376 int ret = -1;
5377 int count = 0;
5378
5379 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
5380
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005381 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005382 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5383 "IBSS mode");
5384 return -1;
5385 }
5386
5387retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005388 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
5389 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
5390 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005391
Hai Shalom74f70d42019-02-11 14:42:39 -08005392 wpa_printf(MSG_DEBUG, " * SSID=%s",
5393 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005394 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
5395 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005396 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5397 drv->ssid_len = params->ssid_len;
5398
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005399 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
5400 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005401 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005402
5403 ret = nl80211_set_conn_keys(params, msg);
5404 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005405 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005406
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005407 if (params->bssid && params->fixed_bssid) {
5408 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
5409 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005410 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5411 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005412 }
5413
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005414 if (params->fixed_freq) {
5415 wpa_printf(MSG_DEBUG, " * fixed_freq");
5416 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
5417 goto fail;
5418 }
5419
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005420 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5421 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5422 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
5423 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005424 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005425 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5426 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005427 }
5428
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005429 if (params->wpa_ie) {
5430 wpa_hexdump(MSG_DEBUG,
5431 " * Extra IEs for Beacon/Probe Response frames",
5432 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005433 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
5434 params->wpa_ie))
5435 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005436 }
5437
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08005438 ret = nl80211_ht_vht_overrides(msg, params);
5439 if (ret < 0)
5440 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005441
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005442 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5443 msg = NULL;
5444 if (ret) {
5445 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
5446 ret, strerror(-ret));
5447 count++;
5448 if (ret == -EALREADY && count == 1) {
5449 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
5450 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005451 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005452 nlmsg_free(msg);
5453 goto retry;
5454 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005455 } else {
5456 wpa_printf(MSG_DEBUG,
5457 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005458 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005459
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005460fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005461 nlmsg_free(msg);
5462 return ret;
5463}
5464
5465
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005466static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv,
5467 struct wpa_driver_associate_params *params,
5468 struct nl_msg *msg)
5469{
5470 if (params->fils_erp_username_len) {
5471 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username",
5472 params->fils_erp_username,
5473 params->fils_erp_username_len);
5474 if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME,
5475 params->fils_erp_username_len,
5476 params->fils_erp_username))
5477 return -1;
5478 }
5479
5480 if (params->fils_erp_realm_len) {
5481 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm",
5482 params->fils_erp_realm,
5483 params->fils_erp_realm_len);
5484 if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM,
5485 params->fils_erp_realm_len, params->fils_erp_realm))
5486 return -1;
5487 }
5488
5489 wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u",
5490 params->fils_erp_next_seq_num);
5491 if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
5492 params->fils_erp_next_seq_num))
5493 return -1;
5494
5495 if (params->fils_erp_rrk_len) {
5496 wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)",
5497 (unsigned long) params->fils_erp_rrk_len);
5498 if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK,
5499 params->fils_erp_rrk_len, params->fils_erp_rrk))
5500 return -1;
5501 }
5502
5503 return 0;
5504}
5505
5506
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005507static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
5508 struct wpa_driver_associate_params *params,
5509 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005510{
Paul Stewart092955c2017-02-06 09:13:09 -08005511 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
5512 return -1;
5513
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005514 if (params->bssid) {
5515 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
5516 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005517 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5518 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005519 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005520
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005521 if (params->bssid_hint) {
5522 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
5523 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005524 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
5525 params->bssid_hint))
5526 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005527 }
5528
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005529 if (params->freq.freq) {
5530 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
5532 params->freq.freq))
5533 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005534 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005535 } else
5536 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005537
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005538 if (params->freq_hint) {
5539 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
5541 params->freq_hint))
5542 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005543 }
5544
Hai Shalomc3565922019-10-28 11:58:20 -07005545 if (params->freq.edmg.channels && params->freq.edmg.bw_config) {
5546 wpa_printf(MSG_DEBUG,
5547 " * EDMG configuration: channels=0x%x bw_config=%d",
5548 params->freq.edmg.channels,
5549 params->freq.edmg.bw_config);
5550 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
5551 params->freq.edmg.channels) ||
5552 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
5553 params->freq.edmg.bw_config))
5554 return -1;
5555 }
5556
Dmitry Shmidt04949592012-07-19 12:16:46 -07005557 if (params->bg_scan_period >= 0) {
5558 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
5559 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005560 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
5561 params->bg_scan_period))
5562 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005563 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005564
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005565 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005566 wpa_printf(MSG_DEBUG, " * SSID=%s",
5567 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005568 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
5569 params->ssid))
5570 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005571 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005572 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005573 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5574 drv->ssid_len = params->ssid_len;
5575 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005577 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005578 if (params->wpa_ie &&
5579 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
5580 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005581
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005582 if (params->wpa_proto) {
5583 enum nl80211_wpa_versions ver = 0;
5584
5585 if (params->wpa_proto & WPA_PROTO_WPA)
5586 ver |= NL80211_WPA_VERSION_1;
5587 if (params->wpa_proto & WPA_PROTO_RSN)
5588 ver |= NL80211_WPA_VERSION_2;
5589
5590 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005591 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
5592 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005593 }
5594
5595 if (params->pairwise_suite != WPA_CIPHER_NONE) {
5596 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
5597 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005598 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
5599 cipher))
5600 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005601 }
5602
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005603 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
5604 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
5605 /*
5606 * This is likely to work even though many drivers do not
5607 * advertise support for operations without GTK.
5608 */
5609 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5610 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005611 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
5612 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005613 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
5614 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005615 }
5616
5617 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5618 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5619 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
5620 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07005621 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005622 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
5623 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005624 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07005625 params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5626 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005627 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005628 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07005629 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005630 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 ||
5631 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 ||
5632 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07005633 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 ||
5634 params->key_mgmt_suite == WPA_KEY_MGMT_OWE ||
5635 params->key_mgmt_suite == WPA_KEY_MGMT_DPP) {
Paul Stewart092955c2017-02-06 09:13:09 -08005636 int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005637
5638 switch (params->key_mgmt_suite) {
5639 case WPA_KEY_MGMT_CCKM:
Paul Stewart092955c2017-02-06 09:13:09 -08005640 mgmt = RSN_AUTH_KEY_MGMT_CCKM;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005641 break;
5642 case WPA_KEY_MGMT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005643 mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005644 break;
5645 case WPA_KEY_MGMT_FT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005646 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005647 break;
5648 case WPA_KEY_MGMT_FT_PSK:
Paul Stewart092955c2017-02-06 09:13:09 -08005649 mgmt = RSN_AUTH_KEY_MGMT_FT_PSK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005650 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005651 case WPA_KEY_MGMT_IEEE8021X_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005652 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005653 break;
5654 case WPA_KEY_MGMT_PSK_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005655 mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005656 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005657 case WPA_KEY_MGMT_OSEN:
Paul Stewart092955c2017-02-06 09:13:09 -08005658 mgmt = RSN_AUTH_KEY_MGMT_OSEN;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005659 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07005660 case WPA_KEY_MGMT_SAE:
5661 mgmt = RSN_AUTH_KEY_MGMT_SAE;
5662 break;
5663 case WPA_KEY_MGMT_FT_SAE:
5664 mgmt = RSN_AUTH_KEY_MGMT_FT_SAE;
5665 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005666 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
Paul Stewart092955c2017-02-06 09:13:09 -08005667 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005668 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005669 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
Paul Stewart092955c2017-02-06 09:13:09 -08005670 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005671 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07005672 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
5673 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384;
5674 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005675 case WPA_KEY_MGMT_FILS_SHA256:
5676 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256;
5677 break;
5678 case WPA_KEY_MGMT_FILS_SHA384:
5679 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384;
5680 break;
5681 case WPA_KEY_MGMT_FT_FILS_SHA256:
5682 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
5683 break;
5684 case WPA_KEY_MGMT_FT_FILS_SHA384:
5685 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
5686 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005687 case WPA_KEY_MGMT_OWE:
5688 mgmt = RSN_AUTH_KEY_MGMT_OWE;
5689 break;
5690 case WPA_KEY_MGMT_DPP:
5691 mgmt = RSN_AUTH_KEY_MGMT_DPP;
5692 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005693 case WPA_KEY_MGMT_PSK:
5694 default:
Paul Stewart092955c2017-02-06 09:13:09 -08005695 mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005696 break;
5697 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07005698 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005699 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
5700 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005701 }
5702
Hai Shalomc3565922019-10-28 11:58:20 -07005703 if (params->req_handshake_offload &&
Hai Shalom74f70d42019-02-11 14:42:39 -08005704 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) {
5705 wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS");
5706 if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS))
5707 return -1;
5708 }
5709
Roshan Pius3a1667e2018-07-03 15:17:14 -07005710 /* Add PSK in case of 4-way handshake offload */
5711 if (params->psk &&
Hai Shalom74f70d42019-02-11 14:42:39 -08005712 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005713 wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32);
5714 if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk))
5715 return -1;
5716 }
5717
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005718 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5719 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005720
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005721 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
5722 (params->pairwise_suite == WPA_CIPHER_NONE ||
5723 params->pairwise_suite == WPA_CIPHER_WEP104 ||
5724 params->pairwise_suite == WPA_CIPHER_WEP40) &&
5725 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
5726 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
5727 return -1;
5728
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005729 if (params->rrm_used) {
5730 u32 drv_rrm_flags = drv->capa.rrm_flags;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005731 if ((!((drv_rrm_flags &
5732 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) &&
5733 (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) &&
5734 !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005735 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
5736 return -1;
5737 }
5738
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005739 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005740 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005741
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005742 if (params->p2p)
5743 wpa_printf(MSG_DEBUG, " * P2P group");
5744
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005745 if (params->pbss) {
5746 wpa_printf(MSG_DEBUG, " * PBSS");
5747 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
5748 return -1;
5749 }
5750
Dmitry Shmidte4663042016-04-04 10:07:49 -07005751 drv->connect_reassoc = 0;
5752 if (params->prev_bssid) {
5753 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
5754 MAC2STR(params->prev_bssid));
5755 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
5756 params->prev_bssid))
5757 return -1;
5758 drv->connect_reassoc = 1;
5759 }
5760
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005761 if ((params->auth_alg & WPA_AUTH_ALG_FILS) &&
5762 nl80211_put_fils_connect_params(drv, params, msg) != 0)
5763 return -1;
5764
Hai Shalomc3565922019-10-28 11:58:20 -07005765 if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5766 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07005767 (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) &&
5768 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
5769 return -1;
5770
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005771 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005772}
5773
5774
5775static int wpa_driver_nl80211_try_connect(
5776 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005777 struct wpa_driver_associate_params *params,
5778 struct nl_handle *nl_connect)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005779{
5780 struct nl_msg *msg;
5781 enum nl80211_auth_type type;
5782 int ret;
5783 int algs;
5784
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005785#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005786 if (params->req_key_mgmt_offload && params->psk &&
5787 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5788 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
5789 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
5790 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
5791 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
5792 if (ret)
5793 return ret;
5794 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005795#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005796
5797 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
5798 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005799 if (!msg)
5800 return -1;
5801
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005802 ret = nl80211_connect_common(drv, params, msg);
5803 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005804 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005805
Roshan Pius3a1667e2018-07-03 15:17:14 -07005806 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5807 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5808 goto fail;
5809
5810 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL &&
5811 (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) &&
5812 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL))
5813 goto fail;
5814
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005815 algs = 0;
5816 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
5817 algs++;
5818 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
5819 algs++;
5820 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
5821 algs++;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005822 if (params->auth_alg & WPA_AUTH_ALG_FILS)
5823 algs++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005824 if (params->auth_alg & WPA_AUTH_ALG_FT)
5825 algs++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005826 if (algs > 1) {
5827 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
5828 "selection");
5829 goto skip_auth_type;
5830 }
5831
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005832 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005833 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005834 if (type == NL80211_AUTHTYPE_MAX ||
5835 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005836 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005837
5838skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005839 ret = nl80211_set_conn_keys(params, msg);
5840 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005841 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005842
Roshan Pius3a1667e2018-07-03 15:17:14 -07005843 if (nl_connect)
Hai Shalom74f70d42019-02-11 14:42:39 -08005844 ret = send_and_recv(drv->global, nl_connect, msg,
5845 NULL, (void *) -1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005846 else
Hai Shalom74f70d42019-02-11 14:42:39 -08005847 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005849 msg = NULL;
5850 if (ret) {
5851 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
5852 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005853 } else {
5854 wpa_printf(MSG_DEBUG,
5855 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005856 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005858fail:
Hai Shalom74f70d42019-02-11 14:42:39 -08005859 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005860 nlmsg_free(msg);
5861 return ret;
5862
5863}
5864
5865
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005866static int wpa_driver_nl80211_connect(
5867 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005868 struct wpa_driver_associate_params *params,
5869 struct nl_handle *nl_connect)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005870{
Jithu Jancea7c60b42014-12-03 18:54:40 +05305871 int ret;
5872
5873 /* Store the connection attempted bssid for future use */
5874 if (params->bssid)
5875 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
5876 else
5877 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
5878
Roshan Pius3a1667e2018-07-03 15:17:14 -07005879 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005880 if (ret == -EALREADY) {
5881 /*
5882 * cfg80211 does not currently accept new connections if
5883 * we are already connected. As a workaround, force
5884 * disconnection and try again.
5885 */
5886 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
5887 "disconnecting before reassociation "
5888 "attempt");
5889 if (wpa_driver_nl80211_disconnect(
Hai Shalom74f70d42019-02-11 14:42:39 -08005890 drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005891 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005892 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005893 }
5894 return ret;
5895}
5896
5897
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005898static int wpa_driver_nl80211_associate(
5899 void *priv, struct wpa_driver_associate_params *params)
5900{
5901 struct i802_bss *bss = priv;
5902 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005903 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005904 struct nl_msg *msg;
5905
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005906 nl80211_unmask_11b_rates(bss);
5907
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005908 if (params->mode == IEEE80211_MODE_AP)
5909 return wpa_driver_nl80211_ap(drv, params);
5910
5911 if (params->mode == IEEE80211_MODE_IBSS)
5912 return wpa_driver_nl80211_ibss(drv, params);
5913
5914 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005915 enum nl80211_iftype nlmode = params->p2p ?
5916 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005917 struct nl_handle *nl_connect = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005918
5919 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005920 return -1;
Hai Shalomc3565922019-10-28 11:58:20 -07005921 if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5922 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005923 nl_connect = bss->nl_connect;
Hai Shalom74f70d42019-02-11 14:42:39 -08005924 bss->use_nl_connect = 1;
5925 } else {
5926 bss->use_nl_connect = 0;
5927 }
5928
Roshan Pius3a1667e2018-07-03 15:17:14 -07005929 return wpa_driver_nl80211_connect(drv, params, nl_connect);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005930 }
5931
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005932 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005933
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005934 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
5935 drv->ifindex);
5936 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005937 if (!msg)
5938 return -1;
5939
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005940 ret = nl80211_connect_common(drv, params, msg);
5941 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005942 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005943
Roshan Pius3a1667e2018-07-03 15:17:14 -07005944 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5945 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5946 goto fail;
5947
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005948 if (params->fils_kek) {
5949 wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)",
5950 (unsigned int) params->fils_kek_len);
5951 if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len,
5952 params->fils_kek))
5953 goto fail;
5954 }
5955 if (params->fils_nonces) {
5956 wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)",
5957 params->fils_nonces,
5958 params->fils_nonces_len);
5959 if (nla_put(msg, NL80211_ATTR_FILS_NONCES,
5960 params->fils_nonces_len, params->fils_nonces))
5961 goto fail;
5962 }
5963
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005964 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5965 msg = NULL;
5966 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005967 wpa_dbg(drv->ctx, MSG_DEBUG,
5968 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5969 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005970 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005971 } else {
5972 wpa_printf(MSG_DEBUG,
5973 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005975
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005976fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005977 nlmsg_free(msg);
5978 return ret;
5979}
5980
5981
5982static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005983 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984{
5985 struct nl_msg *msg;
5986 int ret = -ENOBUFS;
5987
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005988 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
5989 ifindex, mode, nl80211_iftype_str(mode));
5990
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005991 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
5992 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
5993 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005994
5995 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005996 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005997 if (!ret)
5998 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005999fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006000 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006001 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
6002 " %d (%s)", ifindex, mode, ret, strerror(-ret));
6003 return ret;
6004}
6005
6006
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006007static int wpa_driver_nl80211_set_mode_impl(
6008 struct i802_bss *bss,
6009 enum nl80211_iftype nlmode,
6010 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006011{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006012 struct wpa_driver_nl80211_data *drv = bss->drv;
6013 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006014 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006015 int was_ap = is_ap_interface(drv->nlmode);
6016 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006017 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006018
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07006019 if (TEST_FAIL())
6020 return -1;
6021
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006022 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
6023 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
6024 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006025
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006026 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006027 drv->nlmode = nlmode;
6028 ret = 0;
6029 goto done;
6030 }
6031
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006032 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006033 return -1;
6034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035 if (nlmode == drv->nlmode) {
6036 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
6037 "requested mode - ignore error");
6038 ret = 0;
6039 goto done; /* Already in the requested mode */
6040 }
6041
6042 /* mac80211 doesn't allow mode changes while the device is up, so
6043 * take the device down, try to set the mode again, and bring the
6044 * device back up.
6045 */
6046 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
6047 "interface down");
6048 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006049 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006050 if (res == -EACCES || res == -ENODEV)
6051 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006052 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006053 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
6054 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006055 os_sleep(0, 100000);
6056 continue;
6057 }
6058
6059 /*
6060 * Setting the mode will fail for some drivers if the phy is
6061 * on a frequency that the mode is disallowed in.
6062 */
6063 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006064 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006065 if (res) {
6066 wpa_printf(MSG_DEBUG,
6067 "nl80211: Failed to set frequency on interface");
6068 }
6069 }
6070
6071 /* Try to set the mode again while the interface is down */
6072 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
6073 if (mode_switch_res == -EBUSY) {
6074 wpa_printf(MSG_DEBUG,
6075 "nl80211: Delaying mode set while interface going down");
6076 os_sleep(0, 100000);
6077 continue;
6078 }
6079 ret = mode_switch_res;
6080 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006081 }
6082
6083 if (!ret) {
6084 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
6085 "interface is down");
6086 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006087 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006088 }
6089
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006090 /* Bring the interface back up */
6091 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
6092 if (res != 0) {
6093 wpa_printf(MSG_DEBUG,
6094 "nl80211: Failed to set interface up after switching mode");
6095 ret = -1;
6096 }
6097
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006098done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006099 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006100 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
6101 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006102 return ret;
6103 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006104
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006105 if (is_p2p_net_interface(nlmode)) {
6106 wpa_printf(MSG_DEBUG,
6107 "nl80211: Interface %s mode change to P2P - disable 11b rates",
6108 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006109 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006110 } else if (drv->disabled_11b_rates) {
6111 wpa_printf(MSG_DEBUG,
6112 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
6113 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006114 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006115 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006116
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006117 if (is_ap_interface(nlmode)) {
6118 nl80211_mgmt_unsubscribe(bss, "start AP");
6119 /* Setup additional AP mode functionality if needed */
6120 if (nl80211_setup_ap(bss))
6121 return -1;
6122 } else if (was_ap) {
6123 /* Remove additional AP mode functionality */
6124 nl80211_teardown_ap(bss);
6125 } else {
6126 nl80211_mgmt_unsubscribe(bss, "mode change");
6127 }
6128
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006129 if (is_mesh_interface(nlmode) &&
6130 nl80211_mgmt_subscribe_mesh(bss))
6131 return -1;
6132
Dmitry Shmidt04949592012-07-19 12:16:46 -07006133 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006134 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006135 nl80211_mgmt_subscribe_non_ap(bss) < 0)
6136 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
6137 "frame processing - ignore for now");
6138
6139 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006140}
6141
6142
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006143int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
6144 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006145{
6146 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
6147}
6148
6149
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006150static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
6151 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006152{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006153 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006154 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006155}
6156
6157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006158static int wpa_driver_nl80211_get_capa(void *priv,
6159 struct wpa_driver_capa *capa)
6160{
6161 struct i802_bss *bss = priv;
6162 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07006163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006164 if (!drv->has_capability)
6165 return -1;
6166 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006167 if (drv->extended_capa && drv->extended_capa_mask) {
6168 capa->extended_capa = drv->extended_capa;
6169 capa->extended_capa_mask = drv->extended_capa_mask;
6170 capa->extended_capa_len = drv->extended_capa_len;
6171 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006172
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006173 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006174}
6175
6176
6177static int wpa_driver_nl80211_set_operstate(void *priv, int state)
6178{
6179 struct i802_bss *bss = priv;
6180 struct wpa_driver_nl80211_data *drv = bss->drv;
6181
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006182 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
6183 bss->ifname, drv->operstate, state,
6184 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006185 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006186 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006187 state ? IF_OPER_UP : IF_OPER_DORMANT);
6188}
6189
6190
6191static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
6192{
6193 struct i802_bss *bss = priv;
6194 struct wpa_driver_nl80211_data *drv = bss->drv;
6195 struct nl_msg *msg;
6196 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006197 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006198
6199 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
6200 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
6201 return 0;
6202 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006203
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07006204 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
6205 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
6206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006207 os_memset(&upd, 0, sizeof(upd));
6208 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
6209 if (authorized)
6210 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006211
6212 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
6214 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
6215 nlmsg_free(msg);
6216 return -ENOBUFS;
6217 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006218
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006219 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006220 if (!ret)
6221 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006222 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
6223 ret, strerror(-ret));
6224 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006225}
6226
6227
Jouni Malinen75ecf522011-06-27 15:19:46 -07006228/* Set kernel driver on given frequency (MHz) */
6229static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006230{
Jouni Malinen75ecf522011-06-27 15:19:46 -07006231 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006232 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006233}
6234
6235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006236static inline int min_int(int a, int b)
6237{
6238 if (a < b)
6239 return a;
6240 return b;
6241}
6242
6243
6244static int get_key_handler(struct nl_msg *msg, void *arg)
6245{
6246 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6247 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6248
6249 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6250 genlmsg_attrlen(gnlh, 0), NULL);
6251
6252 /*
6253 * TODO: validate the key index and mac address!
6254 * Otherwise, there's a race condition as soon as
6255 * the kernel starts sending key notifications.
6256 */
6257
6258 if (tb[NL80211_ATTR_KEY_SEQ])
6259 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
6260 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
Hai Shalom021b0b52019-04-10 11:17:58 -07006261 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006262 return NL_SKIP;
6263}
6264
6265
6266static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
6267 int idx, u8 *seq)
6268{
6269 struct i802_bss *bss = priv;
6270 struct wpa_driver_nl80211_data *drv = bss->drv;
6271 struct nl_msg *msg;
6272
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006273 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
6274 NL80211_CMD_GET_KEY);
6275 if (!msg ||
6276 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
6277 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
6278 nlmsg_free(msg);
6279 return -ENOBUFS;
6280 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006281
6282 memset(seq, 0, 6);
6283
6284 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006285}
6286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006287
6288static int i802_set_rts(void *priv, int rts)
6289{
6290 struct i802_bss *bss = priv;
6291 struct wpa_driver_nl80211_data *drv = bss->drv;
6292 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006293 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294 u32 val;
6295
Hai Shalom021b0b52019-04-10 11:17:58 -07006296 if (rts >= 2347 || rts == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006297 val = (u32) -1;
6298 else
6299 val = rts;
6300
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006301 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6302 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6303 nlmsg_free(msg);
6304 return -ENOBUFS;
6305 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006306
6307 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6308 if (!ret)
6309 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
6311 "%d (%s)", rts, ret, strerror(-ret));
6312 return ret;
6313}
6314
6315
6316static int i802_set_frag(void *priv, int frag)
6317{
6318 struct i802_bss *bss = priv;
6319 struct wpa_driver_nl80211_data *drv = bss->drv;
6320 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006321 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006322 u32 val;
6323
Hai Shalom021b0b52019-04-10 11:17:58 -07006324 if (frag >= 2346 || frag == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006325 val = (u32) -1;
6326 else
6327 val = frag;
6328
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006329 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6330 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
6331 nlmsg_free(msg);
6332 return -ENOBUFS;
6333 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006334
6335 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6336 if (!ret)
6337 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006338 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
6339 "%d: %d (%s)", frag, ret, strerror(-ret));
6340 return ret;
6341}
6342
6343
6344static int i802_flush(void *priv)
6345{
6346 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006347 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006348 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006349
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006350 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
6351 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006352
6353 /*
6354 * XXX: FIX! this needs to flush all VLANs too
6355 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006356 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
6357 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006358 if (res) {
6359 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
6360 "(%s)", res, strerror(-res));
6361 }
6362 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006363}
6364
6365
Hai Shalom81f62d82019-07-22 12:10:00 -07006366static void get_sta_tid_stats(struct hostap_sta_driver_data *data,
6367 struct nlattr *attr)
6368{
6369 struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr;
6370 struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1];
6371 static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = {
6372 [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 },
6373 [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 },
6374 };
6375 int rem;
6376
6377 nla_for_each_nested(tidattr, attr, rem) {
6378 if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX,
6379 tidattr, NULL) != 0 ||
6380 !tid_stats[NL80211_TID_STATS_TXQ_STATS] ||
6381 nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX,
6382 tid_stats[NL80211_TID_STATS_TXQ_STATS],
6383 txq_stats_policy) != 0)
6384 continue;
6385 /* sum the backlogs over all TIDs for station */
6386 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES])
6387 data->backlog_bytes += nla_get_u32(
6388 txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]);
6389 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS])
6390 data->backlog_bytes += nla_get_u32(
6391 txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]);
6392 }
6393}
6394
6395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006396static int get_sta_handler(struct nl_msg *msg, void *arg)
6397{
6398 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6399 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6400 struct hostap_sta_driver_data *data = arg;
6401 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
6402 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
6403 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
6404 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
6405 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
6406 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
6407 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006408 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006409 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
6410 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006411 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Roshan Pius3a1667e2018-07-03 15:17:14 -07006412 [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 },
Hai Shalom81f62d82019-07-22 12:10:00 -07006413 [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 },
6414 [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006415 };
6416 struct nlattr *rate[NL80211_RATE_INFO_MAX + 1];
6417 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
6418 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
6419 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
6420 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
6421 [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 },
6422 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
6423 [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006424 };
6425
6426 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6427 genlmsg_attrlen(gnlh, 0), NULL);
6428
6429 /*
6430 * TODO: validate the interface and mac address!
6431 * Otherwise, there's a race condition as soon as
6432 * the kernel starts sending station notifications.
6433 */
6434
6435 if (!tb[NL80211_ATTR_STA_INFO]) {
6436 wpa_printf(MSG_DEBUG, "sta stats missing!");
6437 return NL_SKIP;
6438 }
6439 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
6440 tb[NL80211_ATTR_STA_INFO],
6441 stats_policy)) {
6442 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
6443 return NL_SKIP;
6444 }
6445
6446 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
6447 data->inactive_msec =
6448 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006449 /* For backwards compatibility, fetch the 32-bit counters first. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006450 if (stats[NL80211_STA_INFO_RX_BYTES])
6451 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
6452 if (stats[NL80211_STA_INFO_TX_BYTES])
6453 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006454 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
6455 stats[NL80211_STA_INFO_TX_BYTES64]) {
6456 /*
6457 * The driver supports 64-bit counters, so use them to override
6458 * the 32-bit values.
6459 */
6460 data->rx_bytes =
6461 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
6462 data->tx_bytes =
6463 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
6464 data->bytes_64bit = 1;
6465 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006466 if (stats[NL80211_STA_INFO_RX_PACKETS])
6467 data->rx_packets =
6468 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
6469 if (stats[NL80211_STA_INFO_TX_PACKETS])
6470 data->tx_packets =
6471 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Hai Shalom81f62d82019-07-22 12:10:00 -07006472 if (stats[NL80211_STA_INFO_RX_DURATION])
6473 data->rx_airtime =
6474 nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]);
6475 if (stats[NL80211_STA_INFO_TX_DURATION])
6476 data->tx_airtime =
6477 nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006478 if (stats[NL80211_STA_INFO_TX_FAILED])
6479 data->tx_retry_failed =
6480 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006481 if (stats[NL80211_STA_INFO_SIGNAL])
6482 data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006483 if (stats[NL80211_STA_INFO_ACK_SIGNAL]) {
6484 data->last_ack_rssi =
6485 nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]);
6486 data->flags |= STA_DRV_DATA_LAST_ACK_RSSI;
6487 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006488
6489 if (stats[NL80211_STA_INFO_TX_BITRATE] &&
6490 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6491 stats[NL80211_STA_INFO_TX_BITRATE],
6492 rate_policy) == 0) {
6493 if (rate[NL80211_RATE_INFO_BITRATE32])
6494 data->current_tx_rate =
6495 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6496 else if (rate[NL80211_RATE_INFO_BITRATE])
6497 data->current_tx_rate =
6498 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6499
6500 if (rate[NL80211_RATE_INFO_MCS]) {
6501 data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6502 data->flags |= STA_DRV_DATA_TX_MCS;
6503 }
6504 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6505 data->tx_vhtmcs =
6506 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6507 data->flags |= STA_DRV_DATA_TX_VHT_MCS;
6508 }
6509 if (rate[NL80211_RATE_INFO_SHORT_GI])
6510 data->flags |= STA_DRV_DATA_TX_SHORT_GI;
6511 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6512 data->tx_vht_nss =
6513 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6514 data->flags |= STA_DRV_DATA_TX_VHT_NSS;
6515 }
6516 }
6517
6518 if (stats[NL80211_STA_INFO_RX_BITRATE] &&
6519 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6520 stats[NL80211_STA_INFO_RX_BITRATE],
6521 rate_policy) == 0) {
6522 if (rate[NL80211_RATE_INFO_BITRATE32])
6523 data->current_rx_rate =
6524 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6525 else if (rate[NL80211_RATE_INFO_BITRATE])
6526 data->current_rx_rate =
6527 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6528
6529 if (rate[NL80211_RATE_INFO_MCS]) {
6530 data->rx_mcs =
6531 nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6532 data->flags |= STA_DRV_DATA_RX_MCS;
6533 }
6534 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6535 data->rx_vhtmcs =
6536 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6537 data->flags |= STA_DRV_DATA_RX_VHT_MCS;
6538 }
6539 if (rate[NL80211_RATE_INFO_SHORT_GI])
6540 data->flags |= STA_DRV_DATA_RX_SHORT_GI;
6541 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6542 data->rx_vht_nss =
6543 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6544 data->flags |= STA_DRV_DATA_RX_VHT_NSS;
6545 }
6546 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006547
Hai Shalom81f62d82019-07-22 12:10:00 -07006548 if (stats[NL80211_STA_INFO_TID_STATS])
6549 get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]);
6550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006551 return NL_SKIP;
6552}
6553
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006554static int i802_read_sta_data(struct i802_bss *bss,
6555 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006556 const u8 *addr)
6557{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006558 struct nl_msg *msg;
6559
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006560 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
6561 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6562 nlmsg_free(msg);
6563 return -ENOBUFS;
6564 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006565
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006566 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006567}
6568
6569
6570static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
6571 int cw_min, int cw_max, int burst_time)
6572{
6573 struct i802_bss *bss = priv;
6574 struct wpa_driver_nl80211_data *drv = bss->drv;
6575 struct nl_msg *msg;
6576 struct nlattr *txq, *params;
Hai Shalom74f70d42019-02-11 14:42:39 -08006577 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006578
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006579 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006580 if (!msg)
6581 return -1;
6582
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006583 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
6584 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006585 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006586
6587 /* We are only sending parameters for a single TXQ at a time */
6588 params = nla_nest_start(msg, 1);
6589 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006590 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006591
6592 switch (queue) {
6593 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006594 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
6595 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006596 break;
6597 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006598 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
6599 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006600 break;
6601 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006602 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
6603 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006604 break;
6605 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006606 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
6607 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006608 break;
6609 }
6610 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6611 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006612 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
6613 (burst_time * 100 + 16) / 32) ||
6614 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
6615 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
6616 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
6617 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006618
6619 nla_nest_end(msg, params);
6620
6621 nla_nest_end(msg, txq);
6622
Hai Shalom74f70d42019-02-11 14:42:39 -08006623 res = send_and_recv_msgs(drv, msg, NULL, NULL);
6624 wpa_printf(MSG_DEBUG,
6625 "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d",
6626 queue, aifs, cw_min, cw_max, burst_time, res);
6627 if (res == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006628 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006629 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006630fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006631 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006632 return -1;
6633}
6634
6635
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006636static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006637 const char *ifname, int vlan_id)
6638{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006639 struct wpa_driver_nl80211_data *drv = bss->drv;
6640 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006641 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006642
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006643 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6644 ", ifname=%s[%d], vlan_id=%d)",
6645 bss->ifname, if_nametoindex(bss->ifname),
6646 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006647 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6648 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
6649 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
6650 nlmsg_free(msg);
6651 return -ENOBUFS;
6652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006653
6654 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6655 if (ret < 0) {
6656 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6657 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
6658 MAC2STR(addr), ifname, vlan_id, ret,
6659 strerror(-ret));
6660 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006661 return ret;
6662}
6663
6664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006665static int i802_get_inact_sec(void *priv, const u8 *addr)
6666{
6667 struct hostap_sta_driver_data data;
6668 int ret;
6669
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08006670 os_memset(&data, 0, sizeof(data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006671 data.inactive_msec = (unsigned long) -1;
6672 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006673 if (ret == -ENOENT)
6674 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006675 if (ret || data.inactive_msec == (unsigned long) -1)
6676 return -1;
6677 return data.inactive_msec / 1000;
6678}
6679
6680
6681static int i802_sta_clear_stats(void *priv, const u8 *addr)
6682{
6683#if 0
6684 /* TODO */
6685#endif
6686 return 0;
6687}
6688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006689
6690static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07006691 u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006692{
6693 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006694 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006695 struct ieee80211_mgmt mgmt;
Dmitry Shmidt29333592017-01-09 12:27:11 -08006696 u8 channel;
6697
6698 if (ieee80211_freq_to_chan(bss->freq, &channel) ==
6699 HOSTAPD_MODE_IEEE80211AD) {
6700 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6701 * disassociate the STA instead. */
6702 return i802_sta_disassoc(priv, own_addr, addr, reason);
6703 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006704
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006705 if (is_mesh_interface(drv->nlmode))
6706 return -1;
6707
Dmitry Shmidt04949592012-07-19 12:16:46 -07006708 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006709 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006711 memset(&mgmt, 0, sizeof(mgmt));
6712 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6713 WLAN_FC_STYPE_DEAUTH);
6714 memcpy(mgmt.da, addr, ETH_ALEN);
6715 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6716 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6717 mgmt.u.deauth.reason_code = host_to_le16(reason);
6718 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6719 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006720 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006721 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006722}
6723
6724
6725static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07006726 u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006727{
6728 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006729 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006730 struct ieee80211_mgmt mgmt;
6731
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006732 if (is_mesh_interface(drv->nlmode))
6733 return -1;
6734
Dmitry Shmidt04949592012-07-19 12:16:46 -07006735 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006736 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006737
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006738 memset(&mgmt, 0, sizeof(mgmt));
6739 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6740 WLAN_FC_STYPE_DISASSOC);
6741 memcpy(mgmt.da, addr, ETH_ALEN);
6742 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6743 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6744 mgmt.u.disassoc.reason_code = host_to_le16(reason);
6745 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6746 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006747 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006748 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006749}
6750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006751
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006752static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
6753{
6754 char buf[200], *pos, *end;
6755 int i, res;
6756
6757 pos = buf;
6758 end = pos + sizeof(buf);
6759
6760 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006761 if (!drv->if_indices[i].ifindex)
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006762 continue;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006763 res = os_snprintf(pos, end - pos, " %d(%d)",
Hai Shalom81f62d82019-07-22 12:10:00 -07006764 drv->if_indices[i].ifindex,
6765 drv->if_indices[i].reason);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006766 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006767 break;
6768 pos += res;
6769 }
6770 *pos = '\0';
6771
6772 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
6773 drv->num_if_indices, buf);
6774}
6775
6776
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006777static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6778 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006779{
6780 int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07006781 struct drv_nl80211_if_info *old;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006782
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006783 wpa_printf(MSG_DEBUG,
6784 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6785 ifidx, ifidx_reason);
6786 if (have_ifidx(drv, ifidx, ifidx_reason)) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006787 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
6788 ifidx);
6789 return;
6790 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006791 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006792 if (drv->if_indices[i].ifindex == 0) {
6793 drv->if_indices[i].ifindex = ifidx;
6794 drv->if_indices[i].reason = ifidx_reason;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006795 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006796 return;
6797 }
6798 }
6799
6800 if (drv->if_indices != drv->default_if_indices)
6801 old = drv->if_indices;
6802 else
6803 old = NULL;
6804
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006805 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006806 sizeof(*old));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006807 if (!drv->if_indices) {
6808 if (!old)
6809 drv->if_indices = drv->default_if_indices;
6810 else
6811 drv->if_indices = old;
6812 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
6813 "interfaces");
6814 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
6815 return;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006816 }
6817 if (!old)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006818 os_memcpy(drv->if_indices, drv->default_if_indices,
6819 sizeof(drv->default_if_indices));
Hai Shalom81f62d82019-07-22 12:10:00 -07006820 drv->if_indices[drv->num_if_indices].ifindex = ifidx;
6821 drv->if_indices[drv->num_if_indices].reason = ifidx_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006822 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006823 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006824}
6825
6826
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006827static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6828 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006829{
6830 int i;
6831
6832 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006833 if ((drv->if_indices[i].ifindex == ifidx ||
6834 ifidx == IFIDX_ANY) &&
6835 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006836 ifidx_reason == IFIDX_ANY)) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006837 drv->if_indices[i].ifindex = 0;
6838 drv->if_indices[i].reason = 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006839 break;
6840 }
6841 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006842 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006843}
6844
6845
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006846static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6847 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006848{
6849 int i;
6850
6851 for (i = 0; i < drv->num_if_indices; i++)
Hai Shalom81f62d82019-07-22 12:10:00 -07006852 if (drv->if_indices[i].ifindex == ifidx &&
6853 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006854 ifidx_reason == IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07006855 return 1;
6856
6857 return 0;
6858}
6859
6860
6861static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006862 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006863{
6864 struct i802_bss *bss = priv;
6865 struct wpa_driver_nl80211_data *drv = bss->drv;
6866 char name[IFNAMSIZ + 1];
Roshan Pius3a1667e2018-07-03 15:17:14 -07006867 union wpa_event_data event;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006868 int ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006869
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006870 ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
6871 if (ret >= (int) sizeof(name))
6872 wpa_printf(MSG_WARNING,
6873 "nl80211: WDS interface name was truncated");
6874 else if (ret < 0)
6875 return ret;
6876
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006877 if (ifname_wds)
6878 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
6879
Jouni Malinen75ecf522011-06-27 15:19:46 -07006880 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
6881 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
6882 if (val) {
6883 if (!if_nametoindex(name)) {
6884 if (nl80211_create_iface(drv, name,
6885 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006886 bss->addr, 1, NULL, NULL, 0) <
6887 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006888 return -1;
6889 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006890 linux_br_add_if(drv->global->ioctl_sock,
6891 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006892 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006893
6894 os_memset(&event, 0, sizeof(event));
6895 event.wds_sta_interface.sta_addr = addr;
6896 event.wds_sta_interface.ifname = name;
6897 event.wds_sta_interface.istatus = INTERFACE_ADDED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07006898 wpa_supplicant_event(bss->ctx,
Roshan Pius3a1667e2018-07-03 15:17:14 -07006899 EVENT_WDS_STA_INTERFACE_STATUS,
6900 &event);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006901 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006902 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
6903 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
6904 "interface %s up", name);
6905 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006906 return i802_set_sta_vlan(priv, addr, name, 0);
6907 } else {
Hai Shalom74f70d42019-02-11 14:42:39 -08006908 if (bridge_ifname &&
6909 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
6910 name) < 0)
6911 wpa_printf(MSG_INFO,
6912 "nl80211: Failed to remove interface %s from bridge %s: %s",
6913 name, bridge_ifname, strerror(errno));
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006914
Jouni Malinen75ecf522011-06-27 15:19:46 -07006915 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08006916 nl80211_remove_iface(drv, if_nametoindex(name));
Roshan Pius3a1667e2018-07-03 15:17:14 -07006917 os_memset(&event, 0, sizeof(event));
6918 event.wds_sta_interface.sta_addr = addr;
6919 event.wds_sta_interface.ifname = name;
6920 event.wds_sta_interface.istatus = INTERFACE_REMOVED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07006921 wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS,
Roshan Pius3a1667e2018-07-03 15:17:14 -07006922 &event);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08006923 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006924 }
6925}
6926
6927
6928static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
6929{
6930 struct wpa_driver_nl80211_data *drv = eloop_ctx;
6931 struct sockaddr_ll lladdr;
6932 unsigned char buf[3000];
6933 int len;
6934 socklen_t fromlen = sizeof(lladdr);
6935
6936 len = recvfrom(sock, buf, sizeof(buf), 0,
6937 (struct sockaddr *)&lladdr, &fromlen);
6938 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006939 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
6940 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006941 return;
6942 }
6943
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006944 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07006945 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
6946}
6947
6948
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006949static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
6950 struct i802_bss *bss,
6951 const char *brname, const char *ifname)
6952{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006953 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006954 char in_br[IFNAMSIZ];
6955
6956 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006957 br_ifindex = if_nametoindex(brname);
6958 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006959 /*
6960 * Bridge was configured, but the bridge device does
6961 * not exist. Try to add it now.
6962 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006963 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006964 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
6965 "bridge interface %s: %s",
6966 brname, strerror(errno));
6967 return -1;
6968 }
6969 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006970 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006971 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006972 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006973 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006974
6975 if (linux_br_get(in_br, ifname) == 0) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07006976 if (os_strcmp(in_br, brname) == 0) {
6977 bss->already_in_bridge = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006978 return 0; /* already in the bridge */
Hai Shalomc9e41a12018-07-31 14:41:42 -07006979 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006980
6981 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
6982 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006983 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
6984 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006985 wpa_printf(MSG_ERROR, "nl80211: Failed to "
6986 "remove interface %s from bridge "
6987 "%s: %s",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006988 ifname, in_br, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006989 return -1;
6990 }
6991 }
6992
6993 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
6994 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006995 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006996 wpa_printf(MSG_WARNING,
6997 "nl80211: Failed to add interface %s into bridge %s: %s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006998 ifname, brname, strerror(errno));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006999 /* Try to continue without the interface being in a bridge. This
7000 * may be needed for some cases, e.g., with Open vSwitch, where
7001 * an external component will need to handle bridge
7002 * configuration. */
7003 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007004 }
7005 bss->added_if_into_bridge = 1;
7006
7007 return 0;
7008}
7009
7010
7011static void *i802_init(struct hostapd_data *hapd,
7012 struct wpa_init_params *params)
7013{
7014 struct wpa_driver_nl80211_data *drv;
7015 struct i802_bss *bss;
7016 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007017 char master_ifname[IFNAMSIZ];
7018 int ifindex, br_ifindex = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007019 int br_added = 0;
7020
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007021 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
7022 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007023 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007024 if (bss == NULL)
7025 return NULL;
7026
7027 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007028
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007029 if (linux_br_get(master_ifname, params->ifname) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007030 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007031 params->ifname, master_ifname);
7032 br_ifindex = if_nametoindex(master_ifname);
7033 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
7034 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
7035 linux_master_get(master_ifname, params->ifname) == 0) {
7036 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
7037 params->ifname, master_ifname);
7038 /* start listening for EAPOL on the master interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007039 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007040
7041 /* check if master itself is under bridge */
7042 if (linux_br_get(master_ifname, master_ifname) == 0) {
7043 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
7044 master_ifname);
7045 br_ifindex = if_nametoindex(master_ifname);
7046 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
7047 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007048 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007049 master_ifname[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007050 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007051
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007052 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007053
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007054 for (i = 0; i < params->num_bridge; i++) {
7055 if (params->bridge[i]) {
7056 ifindex = if_nametoindex(params->bridge[i]);
7057 if (ifindex)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007058 add_ifidx(drv, ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007059 if (ifindex == br_ifindex)
7060 br_added = 1;
7061 }
7062 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007063
7064 /* start listening for EAPOL on the default AP interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007065 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007066
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007067 if (params->num_bridge && params->bridge[0]) {
7068 if (i802_check_bridge(drv, bss, params->bridge[0],
7069 params->ifname) < 0)
7070 goto failed;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007071 if (os_strcmp(params->bridge[0], master_ifname) != 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007072 br_added = 1;
7073 }
7074
7075 if (!br_added && br_ifindex &&
7076 (params->num_bridge == 0 || !params->bridge[0]))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007077 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007078
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007079#ifdef CONFIG_LIBNL3_ROUTE
Hai Shalomc9e41a12018-07-31 14:41:42 -07007080 if (bss->added_if_into_bridge || bss->already_in_bridge) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007081 drv->rtnl_sk = nl_socket_alloc();
7082 if (drv->rtnl_sk == NULL) {
7083 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
7084 goto failed;
7085 }
7086
7087 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
7088 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
7089 strerror(errno));
7090 goto failed;
7091 }
7092 }
7093#endif /* CONFIG_LIBNL3_ROUTE */
7094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007095 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
7096 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007097 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
7098 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007099 goto failed;
7100 }
7101
7102 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
7103 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007104 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007105 goto failed;
7106 }
7107
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007108 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
7109 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007110 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007111 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007112
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007113 memcpy(bss->addr, params->own_addr, ETH_ALEN);
7114
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007115 return bss;
7116
7117failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007118 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007119 return NULL;
7120}
7121
7122
7123static void i802_deinit(void *priv)
7124{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007125 struct i802_bss *bss = priv;
7126 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007127}
7128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007129
7130static enum nl80211_iftype wpa_driver_nl80211_if_type(
7131 enum wpa_driver_if_type type)
7132{
7133 switch (type) {
7134 case WPA_IF_STATION:
7135 return NL80211_IFTYPE_STATION;
7136 case WPA_IF_P2P_CLIENT:
7137 case WPA_IF_P2P_GROUP:
7138 return NL80211_IFTYPE_P2P_CLIENT;
7139 case WPA_IF_AP_VLAN:
7140 return NL80211_IFTYPE_AP_VLAN;
7141 case WPA_IF_AP_BSS:
7142 return NL80211_IFTYPE_AP;
7143 case WPA_IF_P2P_GO:
7144 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007145 case WPA_IF_P2P_DEVICE:
7146 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007147 case WPA_IF_MESH:
7148 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007149 default:
7150 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007152}
7153
7154
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007155static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
7156{
7157 struct wpa_driver_nl80211_data *drv;
7158 dl_list_for_each(drv, &global->interfaces,
7159 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007160 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007161 return 1;
7162 }
7163 return 0;
7164}
7165
7166
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007167static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007168{
7169 unsigned int idx;
7170
7171 if (!drv->global)
7172 return -1;
7173
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007174 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007175 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007176 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007177 new_addr[0] ^= idx << 2;
7178 if (!nl80211_addr_in_use(drv->global, new_addr))
7179 break;
7180 }
7181 if (idx == 64)
7182 return -1;
7183
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007184 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007185 MACSTR, MAC2STR(new_addr));
7186
7187 return 0;
7188}
7189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007190
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007191struct wdev_info {
7192 u64 wdev_id;
7193 int wdev_id_set;
7194 u8 macaddr[ETH_ALEN];
7195};
7196
7197static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
7198{
7199 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7200 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7201 struct wdev_info *wi = arg;
7202
7203 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7204 genlmsg_attrlen(gnlh, 0), NULL);
7205 if (tb[NL80211_ATTR_WDEV]) {
7206 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
7207 wi->wdev_id_set = 1;
7208 }
7209
7210 if (tb[NL80211_ATTR_MAC])
7211 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
7212 ETH_ALEN);
7213
7214 return NL_SKIP;
7215}
7216
7217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007218static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
7219 const char *ifname, const u8 *addr,
7220 void *bss_ctx, void **drv_priv,
7221 char *force_ifname, u8 *if_addr,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007222 const char *bridge, int use_existing,
7223 int setup_ap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007224{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007225 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007226 struct i802_bss *bss = priv;
7227 struct wpa_driver_nl80211_data *drv = bss->drv;
7228 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007229 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007230
7231 if (addr)
7232 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007233 nlmode = wpa_driver_nl80211_if_type(type);
7234 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
7235 struct wdev_info p2pdev_info;
7236
7237 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
7238 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
7239 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007240 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007241 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
7242 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
7243 ifname);
7244 return -1;
7245 }
7246
7247 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
7248 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
7249 if (!is_zero_ether_addr(p2pdev_info.macaddr))
7250 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
7251 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
7252 ifname,
7253 (long long unsigned int) p2pdev_info.wdev_id);
7254 } else {
7255 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007256 0, NULL, NULL, use_existing);
7257 if (use_existing && ifidx == -ENFILE) {
7258 added = 0;
7259 ifidx = if_nametoindex(ifname);
7260 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007261 return -1;
7262 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007263 }
7264
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007265 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007266 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007267 os_memcpy(if_addr, bss->addr, ETH_ALEN);
7268 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007269 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007270 if (added)
7271 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007272 return -1;
7273 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007274 }
7275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007276 if (!addr &&
7277 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007278 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
7279 type == WPA_IF_STATION)) {
7280 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007281 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007282
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007283 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007284 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007285 if (added)
7286 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007287 return -1;
7288 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007289 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007290 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007291 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007292 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007293 if (added)
7294 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007295 return -1;
7296 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007297 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007298 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007299 if (added)
7300 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007301 return -1;
7302 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007303 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007304 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007305 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007306
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007307 if (type == WPA_IF_AP_BSS && setup_ap) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007308 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
7309 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007310 if (added)
7311 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007312 return -1;
7313 }
7314
7315 if (bridge &&
7316 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
7317 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
7318 "interface %s to a bridge %s",
7319 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007320 if (added)
7321 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007322 os_free(new_bss);
7323 return -1;
7324 }
7325
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007326 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
7327 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007328 if (added)
7329 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007330 os_free(new_bss);
7331 return -1;
7332 }
7333 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007334 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007335 new_bss->ifindex = ifidx;
7336 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007337 new_bss->next = drv->first_bss->next;
7338 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007339 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007340 new_bss->added_if = added;
7341 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007342 if (drv_priv)
7343 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007344 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007345
7346 /* Subscribe management frames for this WPA_IF_AP_BSS */
7347 if (nl80211_setup_ap(new_bss))
7348 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007349 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007350
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007351 if (drv->global)
7352 drv->global->if_add_ifindex = ifidx;
7353
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007354 /*
7355 * Some virtual interfaces need to process EAPOL packets and events on
7356 * the parent interface. This is used mainly with hostapd.
7357 */
7358 if (ifidx > 0 &&
7359 (drv->hostapd ||
7360 nlmode == NL80211_IFTYPE_AP_VLAN ||
7361 nlmode == NL80211_IFTYPE_WDS ||
7362 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007363 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007364
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007365 return 0;
7366}
7367
7368
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007369static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007370 enum wpa_driver_if_type type,
7371 const char *ifname)
7372{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007373 struct wpa_driver_nl80211_data *drv = bss->drv;
7374 int ifindex = if_nametoindex(ifname);
7375
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007376 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
7377 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007378 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07007379 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007380 else if (ifindex > 0 && !bss->added_if) {
7381 struct wpa_driver_nl80211_data *drv2;
7382 dl_list_for_each(drv2, &drv->global->interfaces,
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007383 struct wpa_driver_nl80211_data, list) {
7384 del_ifidx(drv2, ifindex, IFIDX_ANY);
7385 del_ifidx(drv2, IFIDX_ANY, ifindex);
7386 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007387 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007388
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007389 if (type != WPA_IF_AP_BSS)
7390 return 0;
7391
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007392 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007393 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
7394 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007395 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7396 "interface %s from bridge %s: %s",
7397 bss->ifname, bss->brname, strerror(errno));
7398 }
7399 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007400 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007401 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7402 "bridge %s: %s",
7403 bss->brname, strerror(errno));
7404 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007405
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007406 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007407 struct i802_bss *tbss;
7408
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007409 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
7410 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007411 if (tbss->next == bss) {
7412 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007413 /* Unsubscribe management frames */
7414 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007415 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007416 if (!bss->added_if)
7417 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007418 os_free(bss);
7419 bss = NULL;
7420 break;
7421 }
7422 }
7423 if (bss)
7424 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
7425 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007426 } else {
7427 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
7428 nl80211_teardown_ap(bss);
7429 if (!bss->added_if && !drv->first_bss->next)
Paul Stewart092955c2017-02-06 09:13:09 -08007430 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007431 nl80211_destroy_bss(bss);
7432 if (!bss->added_if)
7433 i802_set_iface_flags(bss, 0);
7434 if (drv->first_bss->next) {
7435 drv->first_bss = drv->first_bss->next;
7436 drv->ctx = drv->first_bss->ctx;
7437 os_free(bss);
7438 } else {
7439 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
7440 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007441 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007442
7443 return 0;
7444}
7445
7446
7447static int cookie_handler(struct nl_msg *msg, void *arg)
7448{
7449 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7450 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7451 u64 *cookie = arg;
7452 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7453 genlmsg_attrlen(gnlh, 0), NULL);
7454 if (tb[NL80211_ATTR_COOKIE])
7455 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
7456 return NL_SKIP;
7457}
7458
7459
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007460static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007461 unsigned int freq, unsigned int wait,
7462 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007463 u64 *cookie_out, int no_cck, int no_ack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007464 int offchanok, const u16 *csa_offs,
7465 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007466{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007467 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007468 struct nl_msg *msg;
7469 u64 cookie;
7470 int ret = -1;
7471
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007472 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007473 "no_ack=%d offchanok=%d",
7474 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007475 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007476
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007477 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
7478 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
7479 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
7480 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7481 drv->test_use_roc_tx) &&
7482 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
7483 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
7484 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007485 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
7486 csa_offs_len * sizeof(u16), csa_offs)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007487 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
7488 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007489
7490 cookie = 0;
7491 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7492 msg = NULL;
7493 if (ret) {
7494 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007495 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
7496 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007497 } else {
7498 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
7499 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
7500 (long long unsigned int) cookie);
7501
7502 if (cookie_out)
7503 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007504
7505 if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) {
7506 wpa_printf(MSG_DEBUG,
7507 "nl80211: Drop oldest pending send action cookie 0x%llx",
7508 (long long unsigned int)
7509 drv->send_action_cookies[0]);
7510 os_memmove(&drv->send_action_cookies[0],
7511 &drv->send_action_cookies[1],
7512 (MAX_SEND_ACTION_COOKIES - 1) *
7513 sizeof(u64));
7514 drv->num_send_action_cookies--;
7515 }
7516 drv->send_action_cookies[drv->num_send_action_cookies] = cookie;
7517 drv->num_send_action_cookies++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007518 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007519
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007520fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007521 nlmsg_free(msg);
7522 return ret;
7523}
7524
7525
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007526static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
7527 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007528 unsigned int wait_time,
7529 const u8 *dst, const u8 *src,
7530 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007531 const u8 *data, size_t data_len,
7532 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007533{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007534 struct wpa_driver_nl80211_data *drv = bss->drv;
7535 int ret = -1;
7536 u8 *buf;
7537 struct ieee80211_hdr *hdr;
7538
7539 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007540 "freq=%u MHz wait=%d ms no_cck=%d)",
7541 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007542
7543 buf = os_zalloc(24 + data_len);
7544 if (buf == NULL)
7545 return ret;
7546 os_memcpy(buf + 24, data, data_len);
7547 hdr = (struct ieee80211_hdr *) buf;
7548 hdr->frame_control =
7549 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
7550 os_memcpy(hdr->addr1, dst, ETH_ALEN);
7551 os_memcpy(hdr->addr2, src, ETH_ALEN);
7552 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
7553
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007554 if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) {
7555 wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR,
7556 MAC2STR(src));
7557 os_memcpy(bss->rand_addr, src, ETH_ALEN);
7558 } else {
7559 os_memset(bss->rand_addr, 0, ETH_ALEN);
7560 }
7561
Dmitry Shmidt56052862013-10-04 10:23:25 -07007562 if (is_ap_interface(drv->nlmode) &&
7563 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7564 (int) freq == bss->freq || drv->device_ap_sme ||
7565 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007566 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
7567 0, freq, no_cck, 1,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007568 wait_time, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007569 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007570 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007571 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007572 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007573 no_cck, 0, 1, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007574
7575 os_free(buf);
7576 return ret;
7577}
7578
7579
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007580static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007581{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007582 struct wpa_driver_nl80211_data *drv = bss->drv;
7583 struct nl_msg *msg;
7584 int ret;
7585
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08007586 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007587 (long long unsigned int) cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007588 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007589 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007590 nlmsg_free(msg);
7591 return;
7592 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007593
7594 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007595 if (ret)
7596 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
7597 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007598}
7599
7600
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007601static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
7602{
7603 struct i802_bss *bss = priv;
7604 struct wpa_driver_nl80211_data *drv = bss->drv;
7605 unsigned int i;
7606 u64 cookie;
7607
7608 /* Cancel the last pending TX cookie */
7609 nl80211_frame_wait_cancel(bss, drv->send_action_cookie);
7610
7611 /*
7612 * Cancel the other pending TX cookies, if any. This is needed since
7613 * the driver may keep a list of all pending offchannel TX operations
7614 * and free up the radio only once they have expired or cancelled.
7615 */
7616 for (i = drv->num_send_action_cookies; i > 0; i--) {
7617 cookie = drv->send_action_cookies[i - 1];
7618 if (cookie != drv->send_action_cookie)
7619 nl80211_frame_wait_cancel(bss, cookie);
7620 }
7621 drv->num_send_action_cookies = 0;
7622}
7623
7624
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007625static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
7626 unsigned int duration)
7627{
7628 struct i802_bss *bss = priv;
7629 struct wpa_driver_nl80211_data *drv = bss->drv;
7630 struct nl_msg *msg;
7631 int ret;
7632 u64 cookie;
7633
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007634 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
7635 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
7636 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
7637 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007638 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007639 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007640
7641 cookie = 0;
7642 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7643 if (ret == 0) {
7644 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
7645 "0x%llx for freq=%u MHz duration=%u",
7646 (long long unsigned int) cookie, freq, duration);
7647 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007648 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007649 return 0;
7650 }
7651 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
7652 "(freq=%d duration=%u): %d (%s)",
7653 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007654 return -1;
7655}
7656
7657
7658static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
7659{
7660 struct i802_bss *bss = priv;
7661 struct wpa_driver_nl80211_data *drv = bss->drv;
7662 struct nl_msg *msg;
7663 int ret;
7664
7665 if (!drv->pending_remain_on_chan) {
7666 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
7667 "to cancel");
7668 return -1;
7669 }
7670
7671 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
7672 "0x%llx",
7673 (long long unsigned int) drv->remain_on_chan_cookie);
7674
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007675 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
7676 if (!msg ||
7677 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
7678 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007679 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007680 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007681
7682 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7683 if (ret == 0)
7684 return 0;
7685 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
7686 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007687 return -1;
7688}
7689
7690
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007691static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007692{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007693 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007695 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007696 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07007697 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
7698 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007699 /*
7700 * Do not disable Probe Request reporting that was
7701 * enabled in nl80211_setup_ap().
7702 */
7703 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
7704 "Probe Request reporting nl_preq=%p while "
7705 "in AP mode", bss->nl_preq);
7706 } else if (bss->nl_preq) {
7707 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
7708 "reporting nl_preq=%p", bss->nl_preq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07007709 nl80211_destroy_eloop_handle(&bss->nl_preq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007710 }
7711 return 0;
7712 }
7713
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007714 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007715 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007716 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007717 return 0;
7718 }
7719
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007720 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
7721 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007722 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007723 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
7724 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007725
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007726 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007727 (WLAN_FC_TYPE_MGMT << 2) |
7728 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007729 NULL, 0) < 0)
7730 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07007731
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007732 nl80211_register_eloop_read(&bss->nl_preq,
7733 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007734 bss->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007735
7736 return 0;
7737
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007738 out_err:
7739 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007740 return -1;
7741}
7742
7743
7744static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
7745 int ifindex, int disabled)
7746{
7747 struct nl_msg *msg;
7748 struct nlattr *bands, *band;
7749 int ret;
7750
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007751 wpa_printf(MSG_DEBUG,
7752 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7753 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
7754 "no NL80211_TXRATE_LEGACY constraint");
7755
7756 msg = nl80211_ifindex_msg(drv, ifindex, 0,
7757 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007758 if (!msg)
7759 return -1;
7760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007761 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
7762 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007763 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007764
7765 /*
7766 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7767 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7768 * rates. All 5 GHz rates are left enabled.
7769 */
7770 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007771 if (!band ||
7772 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
7773 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7774 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007775 nla_nest_end(msg, band);
7776
7777 nla_nest_end(msg, bands);
7778
7779 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007780 if (ret) {
7781 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
7782 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007783 } else
7784 drv->disabled_11b_rates = disabled;
7785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007786 return ret;
7787
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007788fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007789 nlmsg_free(msg);
7790 return -1;
7791}
7792
7793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007794static int wpa_driver_nl80211_deinit_ap(void *priv)
7795{
7796 struct i802_bss *bss = priv;
7797 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007798 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007799 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08007800 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007801 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007802
7803 /*
7804 * If the P2P GO interface was dynamically added, then it is
7805 * possible that the interface change to station is not possible.
7806 */
7807 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
7808 return 0;
7809
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007810 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007811}
7812
7813
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007814static int wpa_driver_nl80211_stop_ap(void *priv)
7815{
7816 struct i802_bss *bss = priv;
7817 struct wpa_driver_nl80211_data *drv = bss->drv;
7818 if (!is_ap_interface(drv->nlmode))
7819 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08007820 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007821 bss->beacon_set = 0;
7822 return 0;
7823}
7824
7825
Dmitry Shmidt04949592012-07-19 12:16:46 -07007826static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
7827{
7828 struct i802_bss *bss = priv;
7829 struct wpa_driver_nl80211_data *drv = bss->drv;
7830 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
7831 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007832
7833 /*
7834 * If the P2P Client interface was dynamically added, then it is
7835 * possible that the interface change to station is not possible.
7836 */
7837 if (bss->if_dynamic)
7838 return 0;
7839
Dmitry Shmidt04949592012-07-19 12:16:46 -07007840 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
7841}
7842
7843
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007844static void wpa_driver_nl80211_resume(void *priv)
7845{
7846 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007847 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007848
7849 if (i802_set_iface_flags(bss, 1))
7850 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007851
7852 if (is_p2p_net_interface(nlmode))
7853 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007854}
7855
7856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007857static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
7858{
7859 struct i802_bss *bss = priv;
7860 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007861 struct nl_msg *msg;
7862 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007863
7864 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
7865 "hysteresis=%d", threshold, hysteresis);
7866
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007867 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
7868 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
7869 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
7870 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
7871 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007872 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007873 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007874 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007875
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007876 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007877}
7878
7879
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007880static int get_channel_width(struct nl_msg *msg, void *arg)
7881{
7882 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7883 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7884 struct wpa_signal_info *sig_change = arg;
7885
7886 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7887 genlmsg_attrlen(gnlh, 0), NULL);
7888
7889 sig_change->center_frq1 = -1;
7890 sig_change->center_frq2 = -1;
7891 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
7892
7893 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
7894 sig_change->chanwidth = convert2width(
7895 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
7896 if (tb[NL80211_ATTR_CENTER_FREQ1])
7897 sig_change->center_frq1 =
7898 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
7899 if (tb[NL80211_ATTR_CENTER_FREQ2])
7900 sig_change->center_frq2 =
7901 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
7902 }
7903
7904 return NL_SKIP;
7905}
7906
7907
7908static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
7909 struct wpa_signal_info *sig)
7910{
7911 struct nl_msg *msg;
7912
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007913 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007914 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007915}
7916
7917
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007918static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
7919{
7920 struct i802_bss *bss = priv;
7921 struct wpa_driver_nl80211_data *drv = bss->drv;
7922 int res;
7923
7924 os_memset(si, 0, sizeof(*si));
7925 res = nl80211_get_link_signal(drv, si);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007926 if (res) {
7927 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
7928 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
7929 return res;
7930 si->current_signal = 0;
7931 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007932
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007933 res = nl80211_get_channel_width(drv, si);
7934 if (res != 0)
7935 return res;
7936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007937 return nl80211_get_link_noise(drv, si);
7938}
7939
7940
7941static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
7942 int encrypt)
7943{
7944 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007945 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007946 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007947}
7948
7949
7950static int nl80211_set_param(void *priv, const char *param)
7951{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007952 struct i802_bss *bss = priv;
7953 struct wpa_driver_nl80211_data *drv = bss->drv;
7954
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007955 if (param == NULL)
7956 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007957 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007958
7959#ifdef CONFIG_P2P
7960 if (os_strstr(param, "use_p2p_group_interface=1")) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007961 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
7962 "interface");
7963 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
7964 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
7965 }
7966#endif /* CONFIG_P2P */
7967
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007968 if (os_strstr(param, "use_monitor=1"))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007969 drv->use_monitor = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007970
7971 if (os_strstr(param, "force_connect_cmd=1")) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007972 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007973 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007974 }
7975
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007976 if (os_strstr(param, "force_bss_selection=1"))
7977 drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
7978
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08007979 if (os_strstr(param, "no_offchannel_tx=1")) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08007980 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
7981 drv->test_use_roc_tx = 1;
7982 }
7983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007984 return 0;
7985}
7986
7987
Dmitry Shmidte4663042016-04-04 10:07:49 -07007988static void * nl80211_global_init(void *ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007989{
7990 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007991 struct netlink_config *cfg;
7992
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007993 global = os_zalloc(sizeof(*global));
7994 if (global == NULL)
7995 return NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -07007996 global->ctx = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007997 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007998 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007999 global->if_add_ifindex = -1;
8000
8001 cfg = os_zalloc(sizeof(*cfg));
8002 if (cfg == NULL)
8003 goto err;
8004
8005 cfg->ctx = global;
8006 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
8007 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
8008 global->netlink = netlink_init(cfg);
8009 if (global->netlink == NULL) {
8010 os_free(cfg);
8011 goto err;
8012 }
8013
8014 if (wpa_driver_nl80211_init_nl_global(global) < 0)
8015 goto err;
8016
8017 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
8018 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008019 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
8020 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008021 goto err;
8022 }
8023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008024 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008025
8026err:
8027 nl80211_global_deinit(global);
8028 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008029}
8030
8031
8032static void nl80211_global_deinit(void *priv)
8033{
8034 struct nl80211_global *global = priv;
8035 if (global == NULL)
8036 return;
8037 if (!dl_list_empty(&global->interfaces)) {
8038 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
8039 "nl80211_global_deinit",
8040 dl_list_len(&global->interfaces));
8041 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008042
8043 if (global->netlink)
8044 netlink_deinit(global->netlink);
8045
8046 nl_destroy_handles(&global->nl);
8047
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008048 if (global->nl_event)
Roshan Pius3a1667e2018-07-03 15:17:14 -07008049 nl80211_destroy_eloop_handle(&global->nl_event, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008050
8051 nl_cb_put(global->nl_cb);
8052
8053 if (global->ioctl_sock >= 0)
8054 close(global->ioctl_sock);
8055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008056 os_free(global);
8057}
8058
8059
8060static const char * nl80211_get_radio_name(void *priv)
8061{
8062 struct i802_bss *bss = priv;
8063 struct wpa_driver_nl80211_data *drv = bss->drv;
8064 return drv->phyname;
8065}
8066
8067
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008068static int nl80211_pmkid(struct i802_bss *bss, int cmd,
8069 struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008070{
8071 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008072 const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */
Jouni Malinen75ecf522011-06-27 15:19:46 -07008073
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008074 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008075 (params->pmkid &&
8076 nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) ||
8077 (params->bssid &&
8078 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) ||
8079 (params->ssid_len &&
8080 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
8081 (params->fils_cache_id &&
8082 nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2,
8083 params->fils_cache_id)) ||
Hai Shalom021b0b52019-04-10 11:17:58 -07008084 (cmd != NL80211_CMD_DEL_PMKSA &&
8085 params->pmk_len && params->pmk_len <= PMK_MAX_LEN &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008086 nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) {
Hai Shalom74f70d42019-02-11 14:42:39 -08008087 nl80211_nlmsg_clear(msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008088 nlmsg_free(msg);
8089 return -ENOBUFS;
8090 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07008091
Hai Shalom74f70d42019-02-11 14:42:39 -08008092 return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008093}
8094
8095
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008096static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008097{
8098 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008099 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008100
8101 if (params->bssid)
8102 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR,
8103 MAC2STR(params->bssid));
8104 else if (params->fils_cache_id && params->ssid_len) {
8105 wpa_printf(MSG_DEBUG,
8106 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
8107 params->fils_cache_id[0], params->fils_cache_id[1],
8108 wpa_ssid_txt(params->ssid, params->ssid_len));
8109 }
8110
Roshan Pius3a1667e2018-07-03 15:17:14 -07008111 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params);
8112 if (ret < 0) {
8113 wpa_printf(MSG_DEBUG,
8114 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
8115 ret, strerror(-ret));
8116 }
8117
8118 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008119}
8120
8121
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008122static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008123{
8124 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008125 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008126
8127 if (params->bssid)
8128 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
8129 MAC2STR(params->bssid));
8130 else if (params->fils_cache_id && params->ssid_len) {
8131 wpa_printf(MSG_DEBUG,
8132 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
8133 params->fils_cache_id[0], params->fils_cache_id[1],
8134 wpa_ssid_txt(params->ssid, params->ssid_len));
8135 }
8136
Roshan Pius3a1667e2018-07-03 15:17:14 -07008137 ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params);
8138 if (ret < 0) {
8139 wpa_printf(MSG_DEBUG,
8140 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
8141 ret, strerror(-ret));
8142 }
8143
8144 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008145}
8146
8147
8148static int nl80211_flush_pmkid(void *priv)
8149{
8150 struct i802_bss *bss = priv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008151 struct nl_msg *msg;
8152
Jouni Malinen75ecf522011-06-27 15:19:46 -07008153 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008154 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA);
8155 if (!msg)
8156 return -ENOBUFS;
8157 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008158}
8159
8160
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008161static void clean_survey_results(struct survey_results *survey_results)
8162{
8163 struct freq_survey *survey, *tmp;
8164
8165 if (dl_list_empty(&survey_results->survey_list))
8166 return;
8167
8168 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
8169 struct freq_survey, list) {
8170 dl_list_del(&survey->list);
8171 os_free(survey);
8172 }
8173}
8174
8175
8176static void add_survey(struct nlattr **sinfo, u32 ifidx,
8177 struct dl_list *survey_list)
8178{
8179 struct freq_survey *survey;
8180
8181 survey = os_zalloc(sizeof(struct freq_survey));
8182 if (!survey)
8183 return;
8184
8185 survey->ifidx = ifidx;
8186 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8187 survey->filled = 0;
8188
8189 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
8190 survey->nf = (int8_t)
8191 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
8192 survey->filled |= SURVEY_HAS_NF;
8193 }
8194
8195 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
8196 survey->channel_time =
8197 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
8198 survey->filled |= SURVEY_HAS_CHAN_TIME;
8199 }
8200
8201 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
8202 survey->channel_time_busy =
8203 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
8204 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
8205 }
8206
8207 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
8208 survey->channel_time_rx =
8209 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
8210 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
8211 }
8212
8213 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
8214 survey->channel_time_tx =
8215 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
8216 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
8217 }
8218
8219 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)",
8220 survey->freq,
8221 survey->nf,
8222 (unsigned long int) survey->channel_time,
8223 (unsigned long int) survey->channel_time_busy,
8224 (unsigned long int) survey->channel_time_tx,
8225 (unsigned long int) survey->channel_time_rx,
8226 survey->filled);
8227
8228 dl_list_add_tail(survey_list, &survey->list);
8229}
8230
8231
8232static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
8233 unsigned int freq_filter)
8234{
8235 if (!freq_filter)
8236 return 1;
8237
8238 return freq_filter == surveyed_freq;
8239}
8240
8241
8242static int survey_handler(struct nl_msg *msg, void *arg)
8243{
8244 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8245 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8246 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
8247 struct survey_results *survey_results;
8248 u32 surveyed_freq = 0;
8249 u32 ifidx;
8250
8251 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
8252 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
8253 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
8254 };
8255
8256 survey_results = (struct survey_results *) arg;
8257
8258 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8259 genlmsg_attrlen(gnlh, 0), NULL);
8260
Dmitry Shmidt97672262014-02-03 13:02:54 -08008261 if (!tb[NL80211_ATTR_IFINDEX])
8262 return NL_SKIP;
8263
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008264 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
8265
8266 if (!tb[NL80211_ATTR_SURVEY_INFO])
8267 return NL_SKIP;
8268
8269 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
8270 tb[NL80211_ATTR_SURVEY_INFO],
8271 survey_policy))
8272 return NL_SKIP;
8273
8274 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
8275 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
8276 return NL_SKIP;
8277 }
8278
8279 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8280
8281 if (!check_survey_ok(sinfo, surveyed_freq,
8282 survey_results->freq_filter))
8283 return NL_SKIP;
8284
8285 if (survey_results->freq_filter &&
8286 survey_results->freq_filter != surveyed_freq) {
8287 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
8288 surveyed_freq);
8289 return NL_SKIP;
8290 }
8291
8292 add_survey(sinfo, ifidx, &survey_results->survey_list);
8293
8294 return NL_SKIP;
8295}
8296
8297
8298static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
8299{
8300 struct i802_bss *bss = priv;
8301 struct wpa_driver_nl80211_data *drv = bss->drv;
8302 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008303 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008304 union wpa_event_data data;
8305 struct survey_results *survey_results;
8306
8307 os_memset(&data, 0, sizeof(data));
8308 survey_results = &data.survey_results;
8309
8310 dl_list_init(&survey_results->survey_list);
8311
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008312 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008313 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008314 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008315
8316 if (freq)
8317 data.survey_results.freq_filter = freq;
8318
8319 do {
8320 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
8321 err = send_and_recv_msgs(drv, msg, survey_handler,
8322 survey_results);
8323 } while (err > 0);
8324
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008325 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008326 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008327 else
8328 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008329
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008330 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008331 return err;
8332}
8333
8334
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008335static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
8336 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008337 const u8 *replay_ctr)
8338{
8339 struct i802_bss *bss = priv;
8340 struct wpa_driver_nl80211_data *drv = bss->drv;
8341 struct nlattr *replay_nested;
8342 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008343 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008344
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008345 if (!drv->set_rekey_offload)
8346 return;
8347
8348 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008349 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
8350 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008351 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008352 (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008353 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
8354 replay_ctr)) {
8355 nl80211_nlmsg_clear(msg);
8356 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008357 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008358 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008359
8360 nla_nest_end(msg, replay_nested);
8361
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008362 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
8363 if (ret == -EOPNOTSUPP) {
8364 wpa_printf(MSG_DEBUG,
8365 "nl80211: Driver does not support rekey offload");
8366 drv->set_rekey_offload = 0;
8367 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008368}
8369
8370
8371static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
8372 const u8 *addr, int qos)
8373{
8374 /* send data frame to poll STA and check whether
8375 * this frame is ACKed */
8376 struct {
8377 struct ieee80211_hdr hdr;
8378 u16 qos_ctl;
8379 } STRUCT_PACKED nulldata;
8380 size_t size;
8381
8382 /* Send data frame to poll STA and check whether this frame is ACKed */
8383
8384 os_memset(&nulldata, 0, sizeof(nulldata));
8385
8386 if (qos) {
8387 nulldata.hdr.frame_control =
8388 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8389 WLAN_FC_STYPE_QOS_NULL);
8390 size = sizeof(nulldata);
8391 } else {
8392 nulldata.hdr.frame_control =
8393 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8394 WLAN_FC_STYPE_NULLFUNC);
8395 size = sizeof(struct ieee80211_hdr);
8396 }
8397
8398 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
8399 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
8400 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
8401 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
8402
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008403 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008404 0, 0, NULL, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008405 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
8406 "send poll frame");
8407}
8408
8409static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
8410 int qos)
8411{
8412 struct i802_bss *bss = priv;
8413 struct wpa_driver_nl80211_data *drv = bss->drv;
8414 struct nl_msg *msg;
Hai Shalom5f92bc92019-04-18 11:54:11 -07008415 u64 cookie;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008416 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008417
8418 if (!drv->poll_command_supported) {
8419 nl80211_send_null_frame(bss, own_addr, addr, qos);
8420 return;
8421 }
8422
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008423 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
8424 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8425 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008426 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008427 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008428
Hai Shalom5f92bc92019-04-18 11:54:11 -07008429 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008430 if (ret < 0) {
8431 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
8432 MACSTR " failed: ret=%d (%s)",
8433 MAC2STR(addr), ret, strerror(-ret));
Hai Shalom5f92bc92019-04-18 11:54:11 -07008434 } else {
8435 wpa_printf(MSG_DEBUG,
8436 "nl80211: Client probe request addr=" MACSTR
8437 " cookie=%llu", MAC2STR(addr),
8438 (long long unsigned int) cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008439 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008440}
8441
8442
8443static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
8444{
8445 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008446 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008447
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008448 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
8449 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
8450 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
8451 nlmsg_free(msg);
8452 return -ENOBUFS;
8453 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07008454
8455 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
8456 if (ret < 0) {
8457 wpa_printf(MSG_DEBUG,
8458 "nl80211: Setting PS state %s failed: %d (%s)",
8459 enabled ? "enabled" : "disabled",
8460 ret, strerror(-ret));
8461 }
8462 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008463}
8464
8465
8466static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
8467 int ctwindow)
8468{
8469 struct i802_bss *bss = priv;
8470
8471 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
8472 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
8473
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008474 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08008475#ifdef ANDROID_P2P
8476 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008477#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008478 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008479#endif /* ANDROID_P2P */
8480 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008481
8482 if (legacy_ps == -1)
8483 return 0;
8484 if (legacy_ps != 0 && legacy_ps != 1)
8485 return -1; /* Not yet supported */
8486
8487 return nl80211_set_power_save(bss, legacy_ps);
8488}
8489
8490
Dmitry Shmidt051af732013-10-22 13:52:46 -07008491static int nl80211_start_radar_detection(void *priv,
8492 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008493{
8494 struct i802_bss *bss = priv;
8495 struct wpa_driver_nl80211_data *drv = bss->drv;
8496 struct nl_msg *msg;
8497 int ret;
8498
Hai Shalom81f62d82019-07-22 12:10:00 -07008499 wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
8500 freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07008501 freq->bandwidth, freq->center_freq1, freq->center_freq2);
8502
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008503 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
8504 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
8505 "detection");
8506 return -1;
8507 }
8508
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008509 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
8510 nl80211_put_freq_params(msg, freq) < 0) {
8511 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008512 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008513 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008514
8515 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8516 if (ret == 0)
8517 return 0;
8518 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
8519 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008520 return -1;
8521}
8522
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008523#ifdef CONFIG_TDLS
8524
8525static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
8526 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07008527 u32 peer_capab, int initiator, const u8 *buf,
8528 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008529{
8530 struct i802_bss *bss = priv;
8531 struct wpa_driver_nl80211_data *drv = bss->drv;
8532 struct nl_msg *msg;
8533
8534 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8535 return -EOPNOTSUPP;
8536
8537 if (!dst)
8538 return -EINVAL;
8539
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008540 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
8541 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
8542 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
8543 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
8544 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
8545 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008546 if (peer_capab) {
8547 /*
8548 * The internal enum tdls_peer_capability definition is
8549 * currently identical with the nl80211 enum
8550 * nl80211_tdls_peer_capability, so no conversion is needed
8551 * here.
8552 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008553 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
8554 peer_capab))
8555 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008556 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008557 if ((initiator &&
8558 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
8559 nla_put(msg, NL80211_ATTR_IE, len, buf))
8560 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008561
8562 return send_and_recv_msgs(drv, msg, NULL, NULL);
8563
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008564fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008565 nlmsg_free(msg);
8566 return -ENOBUFS;
8567}
8568
8569
8570static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
8571{
8572 struct i802_bss *bss = priv;
8573 struct wpa_driver_nl80211_data *drv = bss->drv;
8574 struct nl_msg *msg;
8575 enum nl80211_tdls_operation nl80211_oper;
Paul Stewart092955c2017-02-06 09:13:09 -08008576 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008577
8578 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8579 return -EOPNOTSUPP;
8580
8581 switch (oper) {
8582 case TDLS_DISCOVERY_REQ:
8583 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
8584 break;
8585 case TDLS_SETUP:
8586 nl80211_oper = NL80211_TDLS_SETUP;
8587 break;
8588 case TDLS_TEARDOWN:
8589 nl80211_oper = NL80211_TDLS_TEARDOWN;
8590 break;
8591 case TDLS_ENABLE_LINK:
8592 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
8593 break;
8594 case TDLS_DISABLE_LINK:
8595 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
8596 break;
8597 case TDLS_ENABLE:
8598 return 0;
8599 case TDLS_DISABLE:
8600 return 0;
8601 default:
8602 return -EINVAL;
8603 }
8604
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008605 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
8606 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
8607 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
8608 nlmsg_free(msg);
8609 return -ENOBUFS;
8610 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008611
Paul Stewart092955c2017-02-06 09:13:09 -08008612 res = send_and_recv_msgs(drv, msg, NULL, NULL);
8613 wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8614 " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res,
8615 strerror(-res));
8616 return res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008617}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008618
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008619
8620static int
8621nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
8622 const struct hostapd_freq_params *params)
8623{
8624 struct i802_bss *bss = priv;
8625 struct wpa_driver_nl80211_data *drv = bss->drv;
8626 struct nl_msg *msg;
8627 int ret = -ENOBUFS;
8628
8629 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8630 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8631 return -EOPNOTSUPP;
8632
8633 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
8634 " oper_class=%u freq=%u",
8635 MAC2STR(addr), oper_class, params->freq);
8636 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
8637 if (!msg ||
8638 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8639 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
8640 (ret = nl80211_put_freq_params(msg, params))) {
8641 nlmsg_free(msg);
8642 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
8643 return ret;
8644 }
8645
8646 return send_and_recv_msgs(drv, msg, NULL, NULL);
8647}
8648
8649
8650static int
8651nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
8652{
8653 struct i802_bss *bss = priv;
8654 struct wpa_driver_nl80211_data *drv = bss->drv;
8655 struct nl_msg *msg;
8656
8657 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8658 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8659 return -EOPNOTSUPP;
8660
8661 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
8662 MAC2STR(addr));
8663 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
8664 if (!msg ||
8665 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8666 nlmsg_free(msg);
8667 wpa_printf(MSG_DEBUG,
8668 "nl80211: Could not build TDLS cancel chan switch");
8669 return -ENOBUFS;
8670 }
8671
8672 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008673}
8674
8675#endif /* CONFIG TDLS */
8676
8677
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008678static int driver_nl80211_set_key(const char *ifname, void *priv,
8679 enum wpa_alg alg, const u8 *addr,
8680 int key_idx, int set_tx,
8681 const u8 *seq, size_t seq_len,
8682 const u8 *key, size_t key_len)
8683{
8684 struct i802_bss *bss = priv;
8685 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
8686 set_tx, seq, seq_len, key, key_len);
8687}
8688
8689
8690static int driver_nl80211_scan2(void *priv,
8691 struct wpa_driver_scan_params *params)
8692{
8693 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008694#ifdef CONFIG_DRIVER_NL80211_QCA
8695 struct wpa_driver_nl80211_data *drv = bss->drv;
8696
8697 /*
8698 * Do a vendor specific scan if possible. If only_new_results is
8699 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8700 * cannot be achieved through a vendor scan. The below condition may
8701 * need to be modified if new scan flags are added in the future whose
8702 * functionality can only be achieved through a normal scan.
8703 */
8704 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
8705 return wpa_driver_nl80211_vendor_scan(bss, params);
8706#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008707 return wpa_driver_nl80211_scan(bss, params);
8708}
8709
8710
8711static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07008712 u16 reason_code)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008713{
8714 struct i802_bss *bss = priv;
8715 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
8716}
8717
8718
8719static int driver_nl80211_authenticate(void *priv,
8720 struct wpa_driver_auth_params *params)
8721{
8722 struct i802_bss *bss = priv;
8723 return wpa_driver_nl80211_authenticate(bss, params);
8724}
8725
8726
8727static void driver_nl80211_deinit(void *priv)
8728{
8729 struct i802_bss *bss = priv;
8730 wpa_driver_nl80211_deinit(bss);
8731}
8732
8733
8734static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
8735 const char *ifname)
8736{
8737 struct i802_bss *bss = priv;
8738 return wpa_driver_nl80211_if_remove(bss, type, ifname);
8739}
8740
8741
8742static int driver_nl80211_send_mlme(void *priv, const u8 *data,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07008743 size_t data_len, int noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008744 unsigned int freq,
8745 const u16 *csa_offs, size_t csa_offs_len)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008746{
8747 struct i802_bss *bss = priv;
8748 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008749 freq, 0, 0, 0, csa_offs,
8750 csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008751}
8752
8753
8754static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
8755{
8756 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008757 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008758}
8759
8760
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008761static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
8762 const char *ifname, int vlan_id)
8763{
8764 struct i802_bss *bss = priv;
8765 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
8766}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008767
8768
8769static int driver_nl80211_read_sta_data(void *priv,
8770 struct hostap_sta_driver_data *data,
8771 const u8 *addr)
8772{
8773 struct i802_bss *bss = priv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08008774
8775 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008776 return i802_read_sta_data(bss, data, addr);
8777}
8778
8779
8780static int driver_nl80211_send_action(void *priv, unsigned int freq,
8781 unsigned int wait_time,
8782 const u8 *dst, const u8 *src,
8783 const u8 *bssid,
8784 const u8 *data, size_t data_len,
8785 int no_cck)
8786{
8787 struct i802_bss *bss = priv;
8788 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
8789 bssid, data, data_len, no_cck);
8790}
8791
8792
8793static int driver_nl80211_probe_req_report(void *priv, int report)
8794{
8795 struct i802_bss *bss = priv;
8796 return wpa_driver_nl80211_probe_req_report(bss, report);
8797}
8798
8799
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008800static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
8801 const u8 *ies, size_t ies_len)
8802{
8803 int ret;
8804 struct nl_msg *msg;
8805 struct i802_bss *bss = priv;
8806 struct wpa_driver_nl80211_data *drv = bss->drv;
8807 u16 mdid = WPA_GET_LE16(md);
8808
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008809 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008810 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
8811 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
8812 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
8813 nlmsg_free(msg);
8814 return -ENOBUFS;
8815 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008816
8817 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8818 if (ret) {
8819 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
8820 "err=%d (%s)", ret, strerror(-ret));
8821 }
8822
8823 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008824}
8825
8826
Hai Shalom81f62d82019-07-22 12:10:00 -07008827static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac,
8828 u16 reason_code, const u8 *ie, size_t ie_len)
8829{
8830 int ret;
8831 struct nl_msg *msg;
8832 struct i802_bss *bss = priv;
8833 struct wpa_driver_nl80211_data *drv = bss->drv;
8834
8835 wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR
8836 " reason %u", MAC2STR(peer_mac), reason_code);
8837 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) ||
8838 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) ||
8839 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) ||
8840 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) {
8841 nlmsg_free(msg);
8842 return -ENOBUFS;
8843 }
8844
8845 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8846 if (ret) {
8847 wpa_printf(MSG_DEBUG,
8848 "nl80211: update_dh_ie failed err=%d (%s)",
8849 ret, strerror(-ret));
8850 }
8851
8852 return ret;
8853}
8854
8855
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008856static const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008857{
8858 struct i802_bss *bss = priv;
8859 struct wpa_driver_nl80211_data *drv = bss->drv;
8860
8861 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
8862 return NULL;
8863
8864 return bss->addr;
8865}
8866
8867
Dmitry Shmidt56052862013-10-04 10:23:25 -07008868static const char * scan_state_str(enum scan_states scan_state)
8869{
8870 switch (scan_state) {
8871 case NO_SCAN:
8872 return "NO_SCAN";
8873 case SCAN_REQUESTED:
8874 return "SCAN_REQUESTED";
8875 case SCAN_STARTED:
8876 return "SCAN_STARTED";
8877 case SCAN_COMPLETED:
8878 return "SCAN_COMPLETED";
8879 case SCAN_ABORTED:
8880 return "SCAN_ABORTED";
8881 case SCHED_SCAN_STARTED:
8882 return "SCHED_SCAN_STARTED";
8883 case SCHED_SCAN_STOPPED:
8884 return "SCHED_SCAN_STOPPED";
8885 case SCHED_SCAN_RESULTS:
8886 return "SCHED_SCAN_RESULTS";
8887 }
8888
8889 return "??";
8890}
8891
8892
8893static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
8894{
8895 struct i802_bss *bss = priv;
8896 struct wpa_driver_nl80211_data *drv = bss->drv;
8897 int res;
8898 char *pos, *end;
Hai Shalom74f70d42019-02-11 14:42:39 -08008899 struct nl_msg *msg;
8900 char alpha2[3] = { 0, 0, 0 };
Dmitry Shmidt56052862013-10-04 10:23:25 -07008901
8902 pos = buf;
8903 end = buf + buflen;
8904
8905 res = os_snprintf(pos, end - pos,
8906 "ifindex=%d\n"
8907 "ifname=%s\n"
8908 "brname=%s\n"
8909 "addr=" MACSTR "\n"
8910 "freq=%d\n"
Hai Shalomc9e41a12018-07-31 14:41:42 -07008911 "%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008912 bss->ifindex,
8913 bss->ifname,
8914 bss->brname,
8915 MAC2STR(bss->addr),
8916 bss->freq,
8917 bss->beacon_set ? "beacon_set=1\n" : "",
8918 bss->added_if_into_bridge ?
8919 "added_if_into_bridge=1\n" : "",
Hai Shalomc9e41a12018-07-31 14:41:42 -07008920 bss->already_in_bridge ? "already_in_bridge=1\n" : "",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008921 bss->added_bridge ? "added_bridge=1\n" : "",
8922 bss->in_deinit ? "in_deinit=1\n" : "",
8923 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008924 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008925 return pos - buf;
8926 pos += res;
8927
8928 if (bss->wdev_id_set) {
8929 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
8930 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008931 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008932 return pos - buf;
8933 pos += res;
8934 }
8935
8936 res = os_snprintf(pos, end - pos,
8937 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008938 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07008939 "drv_ifindex=%d\n"
8940 "operstate=%d\n"
8941 "scan_state=%s\n"
8942 "auth_bssid=" MACSTR "\n"
8943 "auth_attempt_bssid=" MACSTR "\n"
8944 "bssid=" MACSTR "\n"
8945 "prev_bssid=" MACSTR "\n"
8946 "associated=%d\n"
8947 "assoc_freq=%u\n"
8948 "monitor_sock=%d\n"
8949 "monitor_ifidx=%d\n"
8950 "monitor_refcount=%d\n"
8951 "last_mgmt_freq=%u\n"
8952 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008953 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07008954 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008955 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07008956 drv->ifindex,
8957 drv->operstate,
8958 scan_state_str(drv->scan_state),
8959 MAC2STR(drv->auth_bssid),
8960 MAC2STR(drv->auth_attempt_bssid),
8961 MAC2STR(drv->bssid),
8962 MAC2STR(drv->prev_bssid),
8963 drv->associated,
8964 drv->assoc_freq,
8965 drv->monitor_sock,
8966 drv->monitor_ifidx,
8967 drv->monitor_refcount,
8968 drv->last_mgmt_freq,
8969 drv->eapol_tx_sock,
8970 drv->ignore_if_down_event ?
8971 "ignore_if_down_event=1\n" : "",
8972 drv->scan_complete_events ?
8973 "scan_complete_events=1\n" : "",
8974 drv->disabled_11b_rates ?
8975 "disabled_11b_rates=1\n" : "",
8976 drv->pending_remain_on_chan ?
8977 "pending_remain_on_chan=1\n" : "",
8978 drv->in_interface_list ? "in_interface_list=1\n" : "",
8979 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
8980 drv->poll_command_supported ?
8981 "poll_command_supported=1\n" : "",
8982 drv->data_tx_status ? "data_tx_status=1\n" : "",
8983 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
8984 drv->retry_auth ? "retry_auth=1\n" : "",
8985 drv->use_monitor ? "use_monitor=1\n" : "",
8986 drv->ignore_next_local_disconnect ?
8987 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008988 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008989 "ignore_next_local_deauth=1\n" : "");
8990 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07008991 return pos - buf;
8992 pos += res;
8993
8994 if (drv->has_capability) {
8995 res = os_snprintf(pos, end - pos,
8996 "capa.key_mgmt=0x%x\n"
8997 "capa.enc=0x%x\n"
8998 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008999 "capa.flags=0x%llx\n"
9000 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07009001 "capa.max_scan_ssids=%d\n"
9002 "capa.max_sched_scan_ssids=%d\n"
9003 "capa.sched_scan_supported=%d\n"
9004 "capa.max_match_sets=%d\n"
9005 "capa.max_remain_on_chan=%u\n"
9006 "capa.max_stations=%u\n"
9007 "capa.probe_resp_offloads=0x%x\n"
9008 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009009 "capa.num_multichan_concurrent=%u\n"
9010 "capa.mac_addr_rand_sched_scan_supported=%d\n"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009011 "capa.mac_addr_rand_scan_supported=%d\n"
9012 "capa.conc_capab=%u\n"
9013 "capa.max_conc_chan_2_4=%u\n"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009014 "capa.max_conc_chan_5_0=%u\n"
9015 "capa.max_sched_scan_plans=%u\n"
9016 "capa.max_sched_scan_plan_interval=%u\n"
9017 "capa.max_sched_scan_plan_iterations=%u\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07009018 drv->capa.key_mgmt,
9019 drv->capa.enc,
9020 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009021 (unsigned long long) drv->capa.flags,
9022 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07009023 drv->capa.max_scan_ssids,
9024 drv->capa.max_sched_scan_ssids,
9025 drv->capa.sched_scan_supported,
9026 drv->capa.max_match_sets,
9027 drv->capa.max_remain_on_chan,
9028 drv->capa.max_stations,
9029 drv->capa.probe_resp_offloads,
9030 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009031 drv->capa.num_multichan_concurrent,
9032 drv->capa.mac_addr_rand_sched_scan_supported,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009033 drv->capa.mac_addr_rand_scan_supported,
9034 drv->capa.conc_capab,
9035 drv->capa.max_conc_chan_2_4,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009036 drv->capa.max_conc_chan_5_0,
9037 drv->capa.max_sched_scan_plans,
9038 drv->capa.max_sched_scan_plan_interval,
9039 drv->capa.max_sched_scan_plan_iterations);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009040 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07009041 return pos - buf;
9042 pos += res;
9043 }
9044
Hai Shalom74f70d42019-02-11 14:42:39 -08009045 msg = nlmsg_alloc();
9046 if (msg &&
9047 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) &&
9048 nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) {
9049 if (send_and_recv_msgs(drv, msg, nl80211_get_country,
9050 alpha2) == 0 &&
9051 alpha2[0]) {
9052 res = os_snprintf(pos, end - pos, "country=%s\n",
9053 alpha2);
9054 if (os_snprintf_error(end - pos, res))
9055 return pos - buf;
9056 pos += res;
9057 }
9058 } else {
9059 nlmsg_free(msg);
9060 }
9061
Dmitry Shmidt56052862013-10-04 10:23:25 -07009062 return pos - buf;
9063}
9064
9065
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009066static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
9067{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009068 if ((settings->head &&
9069 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
9070 settings->head_len, settings->head)) ||
9071 (settings->tail &&
9072 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
9073 settings->tail_len, settings->tail)) ||
9074 (settings->beacon_ies &&
9075 nla_put(msg, NL80211_ATTR_IE,
9076 settings->beacon_ies_len, settings->beacon_ies)) ||
9077 (settings->proberesp_ies &&
9078 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
9079 settings->proberesp_ies_len, settings->proberesp_ies)) ||
9080 (settings->assocresp_ies &&
9081 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
9082 settings->assocresp_ies_len, settings->assocresp_ies)) ||
9083 (settings->probe_resp &&
9084 nla_put(msg, NL80211_ATTR_PROBE_RESP,
9085 settings->probe_resp_len, settings->probe_resp)))
9086 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009087
9088 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009089}
9090
9091
9092static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
9093{
9094 struct nl_msg *msg;
9095 struct i802_bss *bss = priv;
9096 struct wpa_driver_nl80211_data *drv = bss->drv;
9097 struct nlattr *beacon_csa;
9098 int ret = -ENOBUFS;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009099 int csa_off_len = 0;
9100 int i;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009101
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08009102 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 -08009103 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08009104 settings->freq_params.freq, settings->freq_params.bandwidth,
9105 settings->freq_params.center_freq1,
9106 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009107
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009108 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009109 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
9110 return -EOPNOTSUPP;
9111 }
9112
Roshan Pius3a1667e2018-07-03 15:17:14 -07009113 if (drv->nlmode != NL80211_IFTYPE_AP &&
9114 drv->nlmode != NL80211_IFTYPE_P2P_GO &&
9115 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009116 return -EOPNOTSUPP;
9117
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009118 /*
9119 * Remove empty counters, assuming Probe Response and Beacon frame
9120 * counters match. This implementation assumes that there are only two
9121 * counters.
9122 */
9123 if (settings->counter_offset_beacon[0] &&
9124 !settings->counter_offset_beacon[1]) {
9125 csa_off_len = 1;
9126 } else if (settings->counter_offset_beacon[1] &&
9127 !settings->counter_offset_beacon[0]) {
9128 csa_off_len = 1;
9129 settings->counter_offset_beacon[0] =
9130 settings->counter_offset_beacon[1];
9131 settings->counter_offset_presp[0] =
9132 settings->counter_offset_presp[1];
9133 } else if (settings->counter_offset_beacon[1] &&
9134 settings->counter_offset_beacon[0]) {
9135 csa_off_len = 2;
9136 } else {
9137 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
9138 return -EINVAL;
9139 }
9140
9141 /* Check CSA counters validity */
9142 if (drv->capa.max_csa_counters &&
9143 csa_off_len > drv->capa.max_csa_counters) {
9144 wpa_printf(MSG_ERROR,
9145 "nl80211: Too many CSA counters provided");
9146 return -EINVAL;
9147 }
9148
9149 if (!settings->beacon_csa.tail)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009150 return -EINVAL;
9151
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009152 for (i = 0; i < csa_off_len; i++) {
9153 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
9154 u16 csa_c_off_presp = settings->counter_offset_presp[i];
9155
9156 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
9157 (settings->beacon_csa.tail[csa_c_off_bcn] !=
9158 settings->cs_count))
9159 return -EINVAL;
9160
9161 if (settings->beacon_csa.probe_resp &&
9162 ((settings->beacon_csa.probe_resp_len <=
9163 csa_c_off_presp) ||
9164 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
9165 settings->cs_count)))
9166 return -EINVAL;
9167 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009168
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009169 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
9170 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
9171 settings->cs_count) ||
9172 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
9173 (settings->block_tx &&
9174 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009175 goto error;
9176
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009177 /* beacon_after params */
9178 ret = set_beacon_data(msg, &settings->beacon_after);
9179 if (ret)
9180 goto error;
9181
9182 /* beacon_csa params */
9183 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
9184 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009185 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009186
9187 ret = set_beacon_data(msg, &settings->beacon_csa);
9188 if (ret)
9189 goto error;
9190
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009191 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
9192 csa_off_len * sizeof(u16),
9193 settings->counter_offset_beacon) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009194 (settings->beacon_csa.probe_resp &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009195 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
9196 csa_off_len * sizeof(u16),
9197 settings->counter_offset_presp)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009198 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009199
9200 nla_nest_end(msg, beacon_csa);
9201 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9202 if (ret) {
9203 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
9204 ret, strerror(-ret));
9205 }
9206 return ret;
9207
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009208fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009209 ret = -ENOBUFS;
9210error:
9211 nlmsg_free(msg);
9212 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
9213 return ret;
9214}
9215
9216
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009217static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
9218 u8 user_priority, u16 admitted_time)
9219{
9220 struct i802_bss *bss = priv;
9221 struct wpa_driver_nl80211_data *drv = bss->drv;
9222 struct nl_msg *msg;
9223 int ret;
9224
9225 wpa_printf(MSG_DEBUG,
9226 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
9227 tsid, admitted_time, user_priority);
9228
9229 if (!is_sta_interface(drv->nlmode))
9230 return -ENOTSUP;
9231
9232 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
9233 if (!msg ||
9234 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9235 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9236 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
9237 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
9238 nlmsg_free(msg);
9239 return -ENOBUFS;
9240 }
9241
9242 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9243 if (ret)
9244 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
9245 ret, strerror(-ret));
9246 return ret;
9247}
9248
9249
9250static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
9251{
9252 struct i802_bss *bss = priv;
9253 struct wpa_driver_nl80211_data *drv = bss->drv;
9254 struct nl_msg *msg;
9255 int ret;
9256
9257 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
9258
9259 if (!is_sta_interface(drv->nlmode))
9260 return -ENOTSUP;
9261
9262 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
9263 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9264 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
9265 nlmsg_free(msg);
9266 return -ENOBUFS;
9267 }
9268
9269 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9270 if (ret)
9271 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
9272 ret, strerror(-ret));
9273 return ret;
9274}
9275
9276
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009277#ifdef CONFIG_TESTING_OPTIONS
9278static int cmd_reply_handler(struct nl_msg *msg, void *arg)
9279{
9280 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9281 struct wpabuf *buf = arg;
9282
9283 if (!buf)
9284 return NL_SKIP;
9285
9286 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
9287 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
9288 return NL_SKIP;
9289 }
9290
9291 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
9292 genlmsg_attrlen(gnlh, 0));
9293
9294 return NL_SKIP;
9295}
9296#endif /* CONFIG_TESTING_OPTIONS */
9297
9298
9299static int vendor_reply_handler(struct nl_msg *msg, void *arg)
9300{
9301 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9302 struct nlattr *nl_vendor_reply, *nl;
9303 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9304 struct wpabuf *buf = arg;
9305 int rem;
9306
9307 if (!buf)
9308 return NL_SKIP;
9309
9310 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9311 genlmsg_attrlen(gnlh, 0), NULL);
9312 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
9313
9314 if (!nl_vendor_reply)
9315 return NL_SKIP;
9316
9317 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
9318 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
9319 return NL_SKIP;
9320 }
9321
9322 nla_for_each_nested(nl, nl_vendor_reply, rem) {
9323 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
9324 }
9325
9326 return NL_SKIP;
9327}
9328
9329
9330static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
9331 unsigned int subcmd, const u8 *data,
9332 size_t data_len, struct wpabuf *buf)
9333{
9334 struct i802_bss *bss = priv;
9335 struct wpa_driver_nl80211_data *drv = bss->drv;
9336 struct nl_msg *msg;
9337 int ret;
9338
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009339#ifdef CONFIG_TESTING_OPTIONS
9340 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009341 msg = nlmsg_alloc();
9342 if (!msg)
9343 return -ENOMEM;
9344
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009345 nl80211_cmd(drv, msg, 0, subcmd);
9346 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
9347 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009348 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009349 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
9350 if (ret)
9351 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
9352 ret);
9353 return ret;
9354 }
9355#endif /* CONFIG_TESTING_OPTIONS */
9356
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009357 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
9358 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
9359 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
9360 (data &&
9361 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
9362 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009363
9364 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
9365 if (ret)
9366 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
9367 ret);
9368 return ret;
9369
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009370fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009371 nlmsg_free(msg);
9372 return -ENOBUFS;
9373}
9374
9375
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009376static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
9377 u8 qos_map_set_len)
9378{
9379 struct i802_bss *bss = priv;
9380 struct wpa_driver_nl80211_data *drv = bss->drv;
9381 struct nl_msg *msg;
9382 int ret;
9383
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009384 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
9385 qos_map_set, qos_map_set_len);
9386
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009387 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
9388 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
9389 nlmsg_free(msg);
9390 return -ENOBUFS;
9391 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009392
9393 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9394 if (ret)
9395 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
9396
9397 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009398}
9399
9400
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009401static int nl80211_set_wowlan(void *priv,
9402 const struct wowlan_triggers *triggers)
9403{
9404 struct i802_bss *bss = priv;
9405 struct wpa_driver_nl80211_data *drv = bss->drv;
9406 struct nl_msg *msg;
9407 struct nlattr *wowlan_triggers;
9408 int ret;
9409
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009410 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
9411
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07009412 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009413 !(wowlan_triggers = nla_nest_start(msg,
9414 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
9415 (triggers->any &&
9416 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
9417 (triggers->disconnect &&
9418 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
9419 (triggers->magic_pkt &&
9420 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
9421 (triggers->gtk_rekey_failure &&
9422 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
9423 (triggers->eap_identity_req &&
9424 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
9425 (triggers->four_way_handshake &&
9426 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
9427 (triggers->rfkill_release &&
9428 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
9429 nlmsg_free(msg);
9430 return -ENOBUFS;
9431 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009432
9433 nla_nest_end(msg, wowlan_triggers);
9434
9435 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9436 if (ret)
9437 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
9438
9439 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009440}
9441
9442
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009443#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009444static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
9445{
9446 struct i802_bss *bss = priv;
9447 struct wpa_driver_nl80211_data *drv = bss->drv;
9448 struct nl_msg *msg;
9449 struct nlattr *params;
9450
9451 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
9452
9453 if (!drv->roaming_vendor_cmd_avail) {
9454 wpa_printf(MSG_DEBUG,
9455 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
9456 return -1;
9457 }
9458
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009459 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9460 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9461 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9462 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
9463 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9464 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
9465 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
9466 QCA_ROAMING_NOT_ALLOWED) ||
9467 (bssid &&
9468 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
9469 nlmsg_free(msg);
9470 return -1;
9471 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009472 nla_nest_end(msg, params);
9473
9474 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009475}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009476
9477
Roshan Pius3a1667e2018-07-03 15:17:14 -07009478static int nl80211_disable_fils(void *priv, int disable)
9479{
9480 struct i802_bss *bss = priv;
9481 struct wpa_driver_nl80211_data *drv = bss->drv;
9482 struct nl_msg *msg;
9483 struct nlattr *params;
9484
9485 wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable);
9486
9487 if (!drv->set_wifi_conf_vendor_cmd_avail)
9488 return -1;
9489
9490 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9491 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9492 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9493 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
9494 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9495 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS,
9496 disable)) {
9497 nlmsg_free(msg);
9498 return -1;
9499 }
9500 nla_nest_end(msg, params);
9501
9502 return send_and_recv_msgs(drv, msg, NULL, NULL);
9503}
9504
9505
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009506/* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
9507#define WPA_SUPPLICANT_CLIENT_ID 1
9508
9509static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid,
9510 const u8 *bssid)
9511{
9512 struct i802_bss *bss = priv;
9513 struct wpa_driver_nl80211_data *drv = bss->drv;
9514 struct nl_msg *msg;
9515 struct nlattr *params, *nlbssids, *attr;
9516 unsigned int i;
9517
9518 wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)",
9519 num_bssid);
9520
9521 if (!drv->roam_vendor_cmd_avail)
9522 return -1;
9523
9524 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9525 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9526 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9527 QCA_NL80211_VENDOR_SUBCMD_ROAM) ||
9528 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9529 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
Hai Shalomc3565922019-10-28 11:58:20 -07009530 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009531 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID,
9532 WPA_SUPPLICANT_CLIENT_ID) ||
9533 nla_put_u32(msg,
9534 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
9535 num_bssid))
9536 goto fail;
9537
9538 nlbssids = nla_nest_start(
9539 msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
9540 if (!nlbssids)
9541 goto fail;
9542
9543 for (i = 0; i < num_bssid; i++) {
9544 attr = nla_nest_start(msg, i);
9545 if (!attr)
9546 goto fail;
9547 if (nla_put(msg,
9548 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
9549 ETH_ALEN, &bssid[i * ETH_ALEN]))
9550 goto fail;
9551 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i,
9552 MAC2STR(&bssid[i * ETH_ALEN]));
9553 nla_nest_end(msg, attr);
9554 }
9555 nla_nest_end(msg, nlbssids);
9556 nla_nest_end(msg, params);
9557
9558 return send_and_recv_msgs(drv, msg, NULL, NULL);
9559
9560fail:
9561 nlmsg_free(msg);
9562 return -1;
9563}
9564
Hai Shalomc3565922019-10-28 11:58:20 -07009565
9566static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
9567{
9568 struct i802_bss *bss = priv;
9569 struct wpa_driver_nl80211_data *drv = bss->drv;
9570 struct nl_msg *msg;
9571 struct nlattr *params;
9572
9573 if (!drv->add_sta_node_vendor_cmd_avail)
9574 return -EOPNOTSUPP;
9575
9576 wpa_printf(MSG_DEBUG, "nl80211: Add STA node");
9577
9578 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9579 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9580 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9581 QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) ||
9582 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9583 (addr &&
9584 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN,
9585 addr)) ||
9586 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO,
9587 auth_alg)) {
9588 nlmsg_free(msg);
9589 wpa_printf(MSG_ERROR,
9590 "%s: err in adding vendor_cmd and vendor_data",
9591 __func__);
9592 return -1;
9593 }
9594 nla_nest_end(msg, params);
9595
9596 return send_and_recv_msgs(drv, msg, NULL, NULL);
9597}
9598
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009599#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009600
9601
9602static int nl80211_set_mac_addr(void *priv, const u8 *addr)
9603{
9604 struct i802_bss *bss = priv;
9605 struct wpa_driver_nl80211_data *drv = bss->drv;
9606 int new_addr = addr != NULL;
9607
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009608 if (TEST_FAIL())
9609 return -1;
9610
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009611 if (!addr)
9612 addr = drv->perm_addr;
9613
9614 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
9615 return -1;
9616
9617 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
9618 {
9619 wpa_printf(MSG_DEBUG,
9620 "nl80211: failed to set_mac_addr for %s to " MACSTR,
9621 bss->ifname, MAC2STR(addr));
9622 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
9623 1) < 0) {
9624 wpa_printf(MSG_DEBUG,
9625 "nl80211: Could not restore interface UP after failed set_mac_addr");
9626 }
9627 return -1;
9628 }
9629
9630 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
9631 bss->ifname, MAC2STR(addr));
9632 drv->addr_changed = new_addr;
9633 os_memcpy(bss->addr, addr, ETH_ALEN);
9634
9635 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
9636 {
9637 wpa_printf(MSG_DEBUG,
9638 "nl80211: Could not restore interface UP after set_mac_addr");
9639 }
9640
9641 return 0;
9642}
9643
9644
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009645#ifdef CONFIG_MESH
9646
9647static int wpa_driver_nl80211_init_mesh(void *priv)
9648{
9649 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
9650 wpa_printf(MSG_INFO,
9651 "nl80211: Failed to set interface into mesh mode");
9652 return -1;
9653 }
9654 return 0;
9655}
9656
9657
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009658static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
9659 size_t mesh_id_len)
9660{
9661 if (mesh_id) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009662 wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s",
9663 wpa_ssid_txt(mesh_id, mesh_id_len));
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009664 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
9665 }
9666
9667 return 0;
9668}
9669
9670
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009671static int nl80211_put_mesh_config(struct nl_msg *msg,
9672 struct wpa_driver_mesh_bss_params *params)
9673{
9674 struct nlattr *container;
9675
9676 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
9677 if (!container)
9678 return -1;
9679
9680 if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07009681 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
9682 params->auto_plinks)) ||
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009683 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
9684 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009685 params->max_peer_links)) ||
9686 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) &&
9687 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
9688 params->rssi_threshold)))
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009689 return -1;
9690
9691 /*
9692 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9693 * the timer could disconnect stations even in that case.
9694 */
9695 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) &&
9696 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
9697 params->peer_link_timeout)) {
9698 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
9699 return -1;
9700 }
9701
9702 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) &&
9703 nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) {
9704 wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE");
9705 return -1;
9706 }
9707
9708 nla_nest_end(msg, container);
9709
9710 return 0;
9711}
9712
9713
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009714static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009715 struct wpa_driver_mesh_join_params *params)
9716{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009717 struct wpa_driver_nl80211_data *drv = bss->drv;
9718 struct nl_msg *msg;
9719 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08009720 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009721
9722 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
9723 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009724 if (!msg ||
9725 nl80211_put_freq_params(msg, &params->freq) ||
9726 nl80211_put_basic_rates(msg, params->basic_rates) ||
9727 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009728 nl80211_put_beacon_int(msg, params->beacon_int) ||
9729 nl80211_put_dtim_period(msg, params->dtim_period))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009730 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009731
9732 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
9733
9734 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
9735 if (!container)
9736 goto fail;
9737
9738 if (params->ies) {
9739 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
9740 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
9741 params->ies))
9742 goto fail;
9743 }
9744 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
9745 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
9746 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
9747 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
9748 goto fail;
9749 }
9750 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
9751 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
9752 goto fail;
9753 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
9754 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
9755 goto fail;
9756 nla_nest_end(msg, container);
9757
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009758 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
9759 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT;
9760 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS;
9761 if (nl80211_put_mesh_config(msg, &params->conf) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009762 goto fail;
9763
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009764 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9765 msg = NULL;
9766 if (ret) {
9767 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
9768 ret, strerror(-ret));
9769 goto fail;
9770 }
9771 ret = 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07009772 drv->assoc_freq = bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009773 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
9774
9775fail:
9776 nlmsg_free(msg);
9777 return ret;
9778}
9779
9780
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009781static int
9782wpa_driver_nl80211_join_mesh(void *priv,
9783 struct wpa_driver_mesh_join_params *params)
9784{
9785 struct i802_bss *bss = priv;
9786 int ret, timeout;
9787
9788 timeout = params->conf.peer_link_timeout;
9789
9790 /* Disable kernel inactivity timer */
9791 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
9792 params->conf.peer_link_timeout = 0;
9793
9794 ret = nl80211_join_mesh(bss, params);
9795 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
9796 wpa_printf(MSG_DEBUG,
9797 "nl80211: Mesh join retry for peer_link_timeout");
9798 /*
9799 * Old kernel does not support setting
9800 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
9801 * into future from peer_link_timeout.
9802 */
9803 params->conf.peer_link_timeout = timeout + 60;
9804 ret = nl80211_join_mesh(priv, params);
9805 }
9806
9807 params->conf.peer_link_timeout = timeout;
9808 return ret;
9809}
9810
9811
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009812static int wpa_driver_nl80211_leave_mesh(void *priv)
9813{
9814 struct i802_bss *bss = priv;
9815 struct wpa_driver_nl80211_data *drv = bss->drv;
9816 struct nl_msg *msg;
9817 int ret;
9818
9819 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
9820 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
9821 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9822 if (ret) {
9823 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
9824 ret, strerror(-ret));
9825 } else {
9826 wpa_printf(MSG_DEBUG,
9827 "nl80211: mesh leave request send successfully");
9828 }
9829
9830 if (wpa_driver_nl80211_set_mode(drv->first_bss,
9831 NL80211_IFTYPE_STATION)) {
9832 wpa_printf(MSG_INFO,
9833 "nl80211: Failed to set interface into station mode");
9834 }
9835 return ret;
9836}
9837
Hai Shalom81f62d82019-07-22 12:10:00 -07009838
9839static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth,
9840 size_t len)
9841{
9842 struct i802_bss *bss = priv;
9843 struct wpa_driver_nl80211_data *drv = bss->drv;
9844 struct nl_msg *msg;
9845 int ret;
9846
9847 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK);
9848 if (!msg ||
9849 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9850 nla_put(msg, NL80211_ATTR_FRAME, len, eth)) {
9851 nlmsg_free(msg);
9852 return -ENOBUFS;
9853 }
9854
9855 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9856 if (ret) {
9857 wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR
9858 " failed: ret=%d (%s)",
9859 MAC2STR(addr), ret, strerror(-ret));
9860 } else {
9861 wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR
9862 " probed successfully", MAC2STR(addr));
9863 }
9864
9865 return ret;
9866}
9867
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009868#endif /* CONFIG_MESH */
9869
9870
9871static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
9872 const u8 *ipaddr, int prefixlen,
9873 const u8 *addr)
9874{
9875#ifdef CONFIG_LIBNL3_ROUTE
9876 struct i802_bss *bss = priv;
9877 struct wpa_driver_nl80211_data *drv = bss->drv;
9878 struct rtnl_neigh *rn;
9879 struct nl_addr *nl_ipaddr = NULL;
9880 struct nl_addr *nl_lladdr = NULL;
9881 int family, addrsize;
9882 int res;
9883
9884 if (!ipaddr || prefixlen == 0 || !addr)
9885 return -EINVAL;
9886
9887 if (bss->br_ifindex == 0) {
9888 wpa_printf(MSG_DEBUG,
9889 "nl80211: bridge must be set before adding an ip neigh to it");
9890 return -1;
9891 }
9892
9893 if (!drv->rtnl_sk) {
9894 wpa_printf(MSG_DEBUG,
9895 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9896 return -1;
9897 }
9898
9899 if (version == 4) {
9900 family = AF_INET;
9901 addrsize = 4;
9902 } else if (version == 6) {
9903 family = AF_INET6;
9904 addrsize = 16;
9905 } else {
9906 return -EINVAL;
9907 }
9908
9909 rn = rtnl_neigh_alloc();
9910 if (rn == NULL)
9911 return -ENOMEM;
9912
9913 /* set the destination ip address for neigh */
9914 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
9915 if (nl_ipaddr == NULL) {
9916 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
9917 res = -ENOMEM;
9918 goto errout;
9919 }
9920 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
9921 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
9922 if (res) {
9923 wpa_printf(MSG_DEBUG,
9924 "nl80211: neigh set destination addr failed");
9925 goto errout;
9926 }
9927
9928 /* set the corresponding lladdr for neigh */
9929 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
9930 if (nl_lladdr == NULL) {
9931 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
9932 res = -ENOMEM;
9933 goto errout;
9934 }
9935 rtnl_neigh_set_lladdr(rn, nl_lladdr);
9936
9937 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
9938 rtnl_neigh_set_state(rn, NUD_PERMANENT);
9939
9940 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
9941 if (res) {
9942 wpa_printf(MSG_DEBUG,
9943 "nl80211: Adding bridge ip neigh failed: %s",
9944 strerror(errno));
9945 }
9946errout:
9947 if (nl_lladdr)
9948 nl_addr_put(nl_lladdr);
9949 if (nl_ipaddr)
9950 nl_addr_put(nl_ipaddr);
9951 if (rn)
9952 rtnl_neigh_put(rn);
9953 return res;
9954#else /* CONFIG_LIBNL3_ROUTE */
9955 return -1;
9956#endif /* CONFIG_LIBNL3_ROUTE */
9957}
9958
9959
9960static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
9961 const u8 *ipaddr)
9962{
9963#ifdef CONFIG_LIBNL3_ROUTE
9964 struct i802_bss *bss = priv;
9965 struct wpa_driver_nl80211_data *drv = bss->drv;
9966 struct rtnl_neigh *rn;
9967 struct nl_addr *nl_ipaddr;
9968 int family, addrsize;
9969 int res;
9970
9971 if (!ipaddr)
9972 return -EINVAL;
9973
9974 if (version == 4) {
9975 family = AF_INET;
9976 addrsize = 4;
9977 } else if (version == 6) {
9978 family = AF_INET6;
9979 addrsize = 16;
9980 } else {
9981 return -EINVAL;
9982 }
9983
9984 if (bss->br_ifindex == 0) {
9985 wpa_printf(MSG_DEBUG,
9986 "nl80211: bridge must be set to delete an ip neigh");
9987 return -1;
9988 }
9989
9990 if (!drv->rtnl_sk) {
9991 wpa_printf(MSG_DEBUG,
9992 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9993 return -1;
9994 }
9995
9996 rn = rtnl_neigh_alloc();
9997 if (rn == NULL)
9998 return -ENOMEM;
9999
10000 /* set the destination ip address for neigh */
10001 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
10002 if (nl_ipaddr == NULL) {
10003 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
10004 res = -ENOMEM;
10005 goto errout;
10006 }
10007 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
10008 if (res) {
10009 wpa_printf(MSG_DEBUG,
10010 "nl80211: neigh set destination addr failed");
10011 goto errout;
10012 }
10013
10014 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
10015
10016 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
10017 if (res) {
10018 wpa_printf(MSG_DEBUG,
10019 "nl80211: Deleting bridge ip neigh failed: %s",
10020 strerror(errno));
10021 }
10022errout:
10023 if (nl_ipaddr)
10024 nl_addr_put(nl_ipaddr);
10025 if (rn)
10026 rtnl_neigh_put(rn);
10027 return res;
10028#else /* CONFIG_LIBNL3_ROUTE */
10029 return -1;
10030#endif /* CONFIG_LIBNL3_ROUTE */
10031}
10032
10033
10034static int linux_write_system_file(const char *path, unsigned int val)
10035{
10036 char buf[50];
10037 int fd, len;
10038
10039 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
10040 if (os_snprintf_error(sizeof(buf), len))
10041 return -1;
10042
10043 fd = open(path, O_WRONLY);
10044 if (fd < 0)
10045 return -1;
10046
10047 if (write(fd, buf, len) < 0) {
10048 wpa_printf(MSG_DEBUG,
10049 "nl80211: Failed to write Linux system file: %s with the value of %d",
10050 path, val);
10051 close(fd);
10052 return -1;
10053 }
10054 close(fd);
10055
10056 return 0;
10057}
10058
10059
10060static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
10061{
10062 switch (attr) {
10063 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -070010064 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010065 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
10066 return "hairpin_mode";
10067 }
10068
10069 return NULL;
10070}
10071
10072
10073static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
10074 unsigned int val)
10075{
10076 struct i802_bss *bss = priv;
10077 char path[128];
10078 const char *attr_txt;
10079
10080 attr_txt = drv_br_port_attr_str(attr);
10081 if (attr_txt == NULL)
10082 return -EINVAL;
10083
10084 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
10085 bss->ifname, attr_txt);
10086
10087 if (linux_write_system_file(path, val))
10088 return -1;
10089
10090 return 0;
10091}
10092
10093
10094static const char * drv_br_net_param_str(enum drv_br_net_param param)
10095{
10096 switch (param) {
10097 case DRV_BR_NET_PARAM_GARP_ACCEPT:
10098 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -070010099 default:
10100 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010101 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010102}
10103
10104
10105static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
10106 unsigned int val)
10107{
10108 struct i802_bss *bss = priv;
10109 char path[128];
10110 const char *param_txt;
10111 int ip_version = 4;
10112
Dmitry Shmidt83474442015-04-15 13:47:09 -070010113 if (param == DRV_BR_MULTICAST_SNOOPING) {
10114 os_snprintf(path, sizeof(path),
10115 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
10116 bss->brname);
10117 goto set_val;
10118 }
10119
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010120 param_txt = drv_br_net_param_str(param);
10121 if (param_txt == NULL)
10122 return -EINVAL;
10123
10124 switch (param) {
10125 case DRV_BR_NET_PARAM_GARP_ACCEPT:
10126 ip_version = 4;
10127 break;
10128 default:
10129 return -EINVAL;
10130 }
10131
10132 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
10133 ip_version, bss->brname, param_txt);
10134
Dmitry Shmidt83474442015-04-15 13:47:09 -070010135set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010136 if (linux_write_system_file(path, val))
10137 return -1;
10138
10139 return 0;
10140}
10141
10142
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010143#ifdef CONFIG_DRIVER_NL80211_QCA
10144
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010145static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
10146{
10147 switch (hw_mode) {
10148 case HOSTAPD_MODE_IEEE80211B:
10149 return QCA_ACS_MODE_IEEE80211B;
10150 case HOSTAPD_MODE_IEEE80211G:
10151 return QCA_ACS_MODE_IEEE80211G;
10152 case HOSTAPD_MODE_IEEE80211A:
10153 return QCA_ACS_MODE_IEEE80211A;
10154 case HOSTAPD_MODE_IEEE80211AD:
10155 return QCA_ACS_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -070010156 case HOSTAPD_MODE_IEEE80211ANY:
10157 return QCA_ACS_MODE_IEEE80211ANY;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010158 default:
10159 return -1;
10160 }
10161}
10162
10163
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010164static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list)
10165{
10166 int num_channels = 0, num_freqs;
10167 u8 *ch_list;
10168 enum hostapd_hw_mode hw_mode;
10169 int ret = 0;
10170 int i;
10171
10172 if (!freq_list)
10173 return 0;
10174
10175 num_freqs = int_array_len(freq_list);
10176 ch_list = os_malloc(sizeof(u8) * num_freqs);
10177 if (!ch_list)
10178 return -1;
10179
10180 for (i = 0; i < num_freqs; i++) {
10181 const int freq = freq_list[i];
10182
10183 if (freq == 0)
10184 break;
10185 /* Send 2.4 GHz and 5 GHz channels with
10186 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards
10187 * compatibility.
10188 */
10189 if (!(freq >= 2412 && freq <= 2484) &&
10190 !(freq >= 5180 && freq <= 5900))
10191 continue;
10192 hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]);
10193 if (hw_mode != NUM_HOSTAPD_MODES)
10194 num_channels++;
10195 }
10196
10197 if (num_channels)
10198 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST,
10199 num_channels, ch_list);
10200
10201 os_free(ch_list);
10202 return ret;
10203}
10204
10205
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010206static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
10207{
10208 int i, len, ret;
10209 u32 *freqs;
10210
10211 if (!freq_list)
10212 return 0;
10213 len = int_array_len(freq_list);
10214 freqs = os_malloc(sizeof(u32) * len);
10215 if (!freqs)
10216 return -1;
10217 for (i = 0; i < len; i++)
10218 freqs[i] = freq_list[i];
10219 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
10220 sizeof(u32) * len, freqs);
10221 os_free(freqs);
10222 return ret;
10223}
10224
10225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010226static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
10227{
10228 struct i802_bss *bss = priv;
10229 struct wpa_driver_nl80211_data *drv = bss->drv;
10230 struct nl_msg *msg;
10231 struct nlattr *data;
10232 int ret;
10233 int mode;
10234
10235 mode = hw_mode_to_qca_acs(params->hw_mode);
10236 if (mode < 0)
10237 return -1;
10238
10239 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10240 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10241 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10242 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
10243 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10244 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
10245 (params->ht_enabled &&
10246 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
10247 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010248 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
10249 (params->vht_enabled &&
10250 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
10251 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
10252 params->ch_width) ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010253 add_acs_ch_list(msg, params->freq_list) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010254 add_acs_freq_list(msg, params->freq_list)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010255 nlmsg_free(msg);
10256 return -ENOBUFS;
10257 }
10258 nla_nest_end(msg, data);
10259
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010260 wpa_printf(MSG_DEBUG,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010261 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d",
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010262 params->hw_mode, params->ht_enabled, params->ht40_enabled,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010263 params->vht_enabled, params->ch_width);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010264
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010265 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10266 if (ret) {
10267 wpa_printf(MSG_DEBUG,
10268 "nl80211: Failed to invoke driver ACS function: %s",
10269 strerror(errno));
10270 }
10271 return ret;
10272}
10273
10274
Ravi Joshie6ccb162015-07-16 17:45:41 -070010275static int nl80211_set_band(void *priv, enum set_band band)
10276{
10277 struct i802_bss *bss = priv;
10278 struct wpa_driver_nl80211_data *drv = bss->drv;
10279 struct nl_msg *msg;
10280 struct nlattr *data;
10281 int ret;
10282 enum qca_set_band qca_band;
10283
10284 if (!drv->setband_vendor_cmd_avail)
10285 return -1;
10286
10287 switch (band) {
10288 case WPA_SETBAND_AUTO:
10289 qca_band = QCA_SETBAND_AUTO;
10290 break;
10291 case WPA_SETBAND_5G:
10292 qca_band = QCA_SETBAND_5G;
10293 break;
10294 case WPA_SETBAND_2G:
10295 qca_band = QCA_SETBAND_2G;
10296 break;
10297 default:
10298 return -1;
10299 }
10300
10301 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10302 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10303 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10304 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
10305 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10306 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
10307 nlmsg_free(msg);
10308 return -ENOBUFS;
10309 }
10310 nla_nest_end(msg, data);
10311
10312 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10313 if (ret) {
10314 wpa_printf(MSG_DEBUG,
10315 "nl80211: Driver setband function failed: %s",
10316 strerror(errno));
10317 }
10318 return ret;
10319}
10320
10321
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010322struct nl80211_pcl {
10323 unsigned int num;
10324 unsigned int *freq_list;
10325};
10326
10327static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
10328{
10329 struct nlattr *tb[NL80211_ATTR_MAX + 1];
10330 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10331 struct nl80211_pcl *param = arg;
10332 struct nlattr *nl_vend, *attr;
10333 enum qca_iface_type iface_type;
10334 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10335 unsigned int num, max_num;
10336 u32 *freqs;
10337
10338 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10339 genlmsg_attrlen(gnlh, 0), NULL);
10340
10341 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
10342 if (!nl_vend)
10343 return NL_SKIP;
10344
10345 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10346 nla_data(nl_vend), nla_len(nl_vend), NULL);
10347
10348 attr = tb_vendor[
10349 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
10350 if (!attr) {
10351 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
10352 param->num = 0;
10353 return NL_SKIP;
10354 }
10355
10356 iface_type = (enum qca_iface_type) nla_get_u32(attr);
10357 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
10358 iface_type);
10359
10360 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
10361 if (!attr) {
10362 wpa_printf(MSG_ERROR,
10363 "nl80211: preferred_freq_list couldn't be found");
10364 param->num = 0;
10365 return NL_SKIP;
10366 }
10367
10368 /*
10369 * param->num has the maximum number of entries for which there
10370 * is room in the freq_list provided by the caller.
10371 */
10372 freqs = nla_data(attr);
10373 max_num = nla_len(attr) / sizeof(u32);
10374 if (max_num > param->num)
10375 max_num = param->num;
10376 for (num = 0; num < max_num; num++)
10377 param->freq_list[num] = freqs[num];
10378 param->num = num;
10379
10380 return NL_SKIP;
10381}
10382
10383
10384static int nl80211_get_pref_freq_list(void *priv,
10385 enum wpa_driver_if_type if_type,
10386 unsigned int *num,
10387 unsigned int *freq_list)
10388{
10389 struct i802_bss *bss = priv;
10390 struct wpa_driver_nl80211_data *drv = bss->drv;
10391 struct nl_msg *msg;
10392 int ret;
10393 unsigned int i;
10394 struct nlattr *params;
10395 struct nl80211_pcl param;
10396 enum qca_iface_type iface_type;
10397
10398 if (!drv->get_pref_freq_list)
10399 return -1;
10400
10401 switch (if_type) {
10402 case WPA_IF_STATION:
10403 iface_type = QCA_IFACE_TYPE_STA;
10404 break;
10405 case WPA_IF_AP_BSS:
10406 iface_type = QCA_IFACE_TYPE_AP;
10407 break;
10408 case WPA_IF_P2P_GO:
10409 iface_type = QCA_IFACE_TYPE_P2P_GO;
10410 break;
10411 case WPA_IF_P2P_CLIENT:
10412 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
10413 break;
10414 case WPA_IF_IBSS:
10415 iface_type = QCA_IFACE_TYPE_IBSS;
10416 break;
10417 case WPA_IF_TDLS:
10418 iface_type = QCA_IFACE_TYPE_TDLS;
10419 break;
10420 default:
10421 return -1;
10422 }
10423
10424 param.num = *num;
10425 param.freq_list = freq_list;
10426
10427 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10428 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
10429 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10430 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10431 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
10432 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10433 nla_put_u32(msg,
10434 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
10435 iface_type)) {
10436 wpa_printf(MSG_ERROR,
10437 "%s: err in adding vendor_cmd and vendor_data",
10438 __func__);
10439 nlmsg_free(msg);
10440 return -1;
10441 }
10442 nla_nest_end(msg, params);
10443
10444 os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
10445 ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
10446 if (ret) {
10447 wpa_printf(MSG_ERROR,
10448 "%s: err in send_and_recv_msgs", __func__);
10449 return ret;
10450 }
10451
10452 *num = param.num;
10453
10454 for (i = 0; i < *num; i++) {
10455 wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
10456 i, freq_list[i]);
10457 }
10458
10459 return 0;
10460}
10461
10462
10463static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
10464{
10465 struct i802_bss *bss = priv;
10466 struct wpa_driver_nl80211_data *drv = bss->drv;
10467 struct nl_msg *msg;
10468 int ret;
10469 struct nlattr *params;
10470
10471 if (!drv->set_prob_oper_freq)
10472 return -1;
10473
10474 wpa_printf(MSG_DEBUG,
10475 "nl80211: Set P2P probable operating freq %u for ifindex %d",
10476 freq, bss->ifindex);
10477
10478 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10479 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10480 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10481 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
10482 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10483 nla_put_u32(msg,
10484 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
10485 QCA_IFACE_TYPE_P2P_CLIENT) ||
10486 nla_put_u32(msg,
10487 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
10488 freq)) {
10489 wpa_printf(MSG_ERROR,
10490 "%s: err in adding vendor_cmd and vendor_data",
10491 __func__);
10492 nlmsg_free(msg);
10493 return -1;
10494 }
10495 nla_nest_end(msg, params);
10496
10497 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10498 msg = NULL;
10499 if (ret) {
10500 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
10501 __func__);
10502 return ret;
10503 }
10504 nlmsg_free(msg);
10505 return 0;
10506}
10507
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010508
10509static int nl80211_p2p_lo_start(void *priv, unsigned int freq,
10510 unsigned int period, unsigned int interval,
10511 unsigned int count, const u8 *device_types,
10512 size_t dev_types_len,
10513 const u8 *ies, size_t ies_len)
10514{
10515 struct i802_bss *bss = priv;
10516 struct wpa_driver_nl80211_data *drv = bss->drv;
10517 struct nl_msg *msg;
10518 struct nlattr *container;
10519 int ret;
10520
10521 wpa_printf(MSG_DEBUG,
10522 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
10523 freq, period, interval, count);
10524
10525 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10526 return -1;
10527
10528 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10529 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10530 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10531 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START))
10532 goto fail;
10533
10534 container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10535 if (!container)
10536 goto fail;
10537
10538 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL,
10539 freq) ||
10540 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD,
10541 period) ||
10542 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL,
10543 interval) ||
10544 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT,
10545 count) ||
10546 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES,
10547 dev_types_len, device_types) ||
10548 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE,
10549 ies_len, ies))
10550 goto fail;
10551
10552 nla_nest_end(msg, container);
10553 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10554 msg = NULL;
10555 if (ret) {
10556 wpa_printf(MSG_DEBUG,
10557 "nl80211: Failed to send P2P Listen offload vendor command");
10558 goto fail;
10559 }
10560
10561 return 0;
10562
10563fail:
10564 nlmsg_free(msg);
10565 return -1;
10566}
10567
10568
10569static int nl80211_p2p_lo_stop(void *priv)
10570{
10571 struct i802_bss *bss = priv;
10572 struct wpa_driver_nl80211_data *drv = bss->drv;
10573 struct nl_msg *msg;
10574
10575 wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload");
10576
10577 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10578 return -1;
10579
10580 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10581 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10582 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10583 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) {
10584 nlmsg_free(msg);
10585 return -1;
10586 }
10587
10588 return send_and_recv_msgs(drv, msg, NULL, NULL);
10589}
10590
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080010591
10592static int nl80211_set_tdls_mode(void *priv, int tdls_external_control)
10593{
10594 struct i802_bss *bss = priv;
10595 struct wpa_driver_nl80211_data *drv = bss->drv;
10596 struct nl_msg *msg;
10597 struct nlattr *params;
10598 int ret;
10599 u32 tdls_mode;
10600
10601 wpa_printf(MSG_DEBUG,
10602 "nl80211: Set TDKS mode: tdls_external_control=%d",
10603 tdls_external_control);
10604
10605 if (tdls_external_control == 1)
10606 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT |
10607 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL;
10608 else
10609 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT;
10610
10611 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10612 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10613 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10614 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS))
10615 goto fail;
10616
10617 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10618 if (!params)
10619 goto fail;
10620
10621 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE,
10622 tdls_mode))
10623 goto fail;
10624
10625 nla_nest_end(msg, params);
10626
10627 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10628 msg = NULL;
10629 if (ret) {
10630 wpa_printf(MSG_ERROR,
10631 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10632 ret, strerror(-ret));
10633 goto fail;
10634 }
10635 return 0;
10636fail:
10637 nlmsg_free(msg);
10638 return -1;
10639}
10640
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010641
10642#ifdef CONFIG_MBO
10643
10644static enum mbo_transition_reject_reason
10645nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status)
10646{
10647 switch (status) {
10648 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED:
10649 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS;
10650 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED:
10651 return MBO_TRANSITION_REJECT_REASON_DELAY;
10652 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY:
10653 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY;
10654 case QCA_STATUS_REJECT_LOW_RSSI:
10655 return MBO_TRANSITION_REJECT_REASON_RSSI;
10656 case QCA_STATUS_REJECT_HIGH_INTERFERENCE:
10657 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE;
10658 case QCA_STATUS_REJECT_UNKNOWN:
10659 default:
10660 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
10661 }
10662}
10663
10664
10665static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate,
10666 struct nlattr *tb[], int num)
10667{
10668 enum qca_wlan_btm_candidate_status status;
10669 char buf[50];
10670
10671 os_memcpy(candidate->bssid,
10672 nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]),
10673 ETH_ALEN);
10674
10675 status = nla_get_u32(
10676 tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]);
10677 candidate->is_accept = status == QCA_STATUS_ACCEPT;
10678 candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status);
10679
10680 if (candidate->is_accept)
10681 os_snprintf(buf, sizeof(buf), "Accepted");
10682 else
10683 os_snprintf(buf, sizeof(buf),
10684 "Rejected, Reject_reason: %d",
10685 candidate->reject_reason);
10686 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s",
10687 num, MAC2STR(candidate->bssid), buf);
10688}
10689
10690
10691static int
10692nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg)
10693{
10694 struct wpa_bss_candidate_info *info = arg;
10695 struct candidate_list *candidate = info->candidates;
10696 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
10697 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10698 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1];
10699 static struct nla_policy policy[
10700 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = {
10701 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = {
10702 .minlen = ETH_ALEN
10703 },
10704 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = {
10705 .type = NLA_U32,
10706 },
10707 };
10708 struct nlattr *attr;
10709 int rem;
10710 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10711 u8 num;
10712
10713 num = info->num; /* number of candidates sent to driver */
10714 info->num = 0;
10715 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10716 genlmsg_attrlen(gnlh, 0), NULL);
10717
10718 if (!tb_msg[NL80211_ATTR_VENDOR_DATA] ||
10719 nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10720 tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) ||
10721 !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO])
10722 return NL_SKIP;
10723
10724 wpa_printf(MSG_DEBUG,
10725 "nl80211: WNM Candidate list received from driver");
10726 nla_for_each_nested(attr,
10727 tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO],
10728 rem) {
10729 if (info->num >= num ||
10730 nla_parse_nested(
10731 tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX,
10732 attr, policy) ||
10733 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] ||
10734 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS])
10735 break;
10736
10737 nl80211_parse_btm_candidate_info(candidate, tb, info->num);
10738
10739 candidate++;
10740 info->num++;
10741 }
10742
10743 return NL_SKIP;
10744}
10745
10746
10747static struct wpa_bss_candidate_info *
10748nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params)
10749{
10750 struct i802_bss *bss = priv;
10751 struct wpa_driver_nl80211_data *drv = bss->drv;
10752 struct nl_msg *msg;
10753 struct nlattr *attr, *attr1, *attr2;
10754 struct wpa_bss_candidate_info *info;
10755 u8 i;
10756 int ret;
10757 u8 *pos;
10758
10759 if (!drv->fetch_bss_trans_status)
10760 return NULL;
10761
10762 info = os_zalloc(sizeof(*info));
10763 if (!info)
10764 return NULL;
10765 /* Allocate memory for number of candidates sent to driver */
10766 info->candidates = os_calloc(params->n_candidates,
10767 sizeof(*info->candidates));
10768 if (!info->candidates) {
10769 os_free(info);
10770 return NULL;
10771 }
10772
10773 /* Copy the number of candidates being sent to driver. This is used in
10774 * nl80211_get_bss_transition_status_handler() to limit the number of
10775 * candidates that can be populated in info->candidates and will be
10776 * later overwritten with the actual number of candidates received from
10777 * the driver.
10778 */
10779 info->num = params->n_candidates;
10780
10781 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10782 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10783 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10784 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS))
10785 goto fail;
10786
10787 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10788 if (!attr)
10789 goto fail;
10790
10791 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON,
10792 params->mbo_transition_reason))
10793 goto fail;
10794
10795 attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO);
10796 if (!attr1)
10797 goto fail;
10798
10799 wpa_printf(MSG_DEBUG,
10800 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
10801 params->mbo_transition_reason, params->n_candidates);
10802 pos = params->bssid;
10803 for (i = 0; i < params->n_candidates; i++) {
10804 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i,
10805 MAC2STR(pos));
10806 attr2 = nla_nest_start(msg, i);
10807 if (!attr2 ||
10808 nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID,
10809 ETH_ALEN, pos))
10810 goto fail;
10811 pos += ETH_ALEN;
10812 nla_nest_end(msg, attr2);
10813 }
10814
10815 nla_nest_end(msg, attr1);
10816 nla_nest_end(msg, attr);
10817
10818 ret = send_and_recv_msgs(drv, msg,
10819 nl80211_get_bss_transition_status_handler,
10820 info);
10821 msg = NULL;
10822 if (ret) {
10823 wpa_printf(MSG_ERROR,
10824 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
10825 ret, strerror(-ret));
10826 goto fail;
10827 }
10828 return info;
10829
10830fail:
10831 nlmsg_free(msg);
10832 os_free(info->candidates);
10833 os_free(info);
10834 return NULL;
10835}
10836
10837
10838/**
10839 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
10840 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
10841 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
10842 * Returns: 0 on success, -1 on failure
10843 */
10844static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow)
10845{
10846 struct i802_bss *bss = priv;
10847 struct wpa_driver_nl80211_data *drv = bss->drv;
10848 struct nl_msg *msg;
10849 struct nlattr *attr;
10850 int ret = -1;
10851
10852 if (!drv->set_wifi_conf_vendor_cmd_avail)
10853 return -1;
10854
10855 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10856 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10857 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10858 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION))
10859 goto fail;
10860
10861 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10862 if (!attr)
10863 goto fail;
10864
10865 wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d",
10866 ignore_disallow);
10867 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED,
10868 ignore_disallow))
10869 goto fail;
10870
10871 nla_nest_end(msg, attr);
10872
10873 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10874 msg = NULL;
10875 if (ret) {
10876 wpa_printf(MSG_ERROR,
10877 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
10878 ret, strerror(-ret));
10879 goto fail;
10880 }
10881
10882fail:
10883 nlmsg_free(msg);
10884 return ret;
10885}
10886
10887#endif /* CONFIG_MBO */
10888
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010889#endif /* CONFIG_DRIVER_NL80211_QCA */
10890
10891
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010892static int nl80211_write_to_file(const char *name, unsigned int val)
10893{
10894 int fd, len;
10895 char tmp[128];
Hai Shalomc3565922019-10-28 11:58:20 -070010896 int ret = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010897
10898 fd = open(name, O_RDWR);
10899 if (fd < 0) {
Hai Shalomc3565922019-10-28 11:58:20 -070010900 int level;
10901 /*
10902 * Flags may not exist on older kernels, or while we're tearing
10903 * down a disappearing device.
10904 */
10905 if (errno == ENOENT) {
10906 ret = 0;
10907 level = MSG_DEBUG;
10908 } else {
10909 ret = -1;
10910 level = MSG_ERROR;
10911 }
10912 wpa_printf(level, "nl80211: Failed to open %s: %s",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010913 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070010914 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010915 }
10916
10917 len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
10918 len = write(fd, tmp, len);
Hai Shalomc3565922019-10-28 11:58:20 -070010919 if (len < 0) {
10920 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010921 wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
10922 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070010923 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010924 close(fd);
10925
Hai Shalomc3565922019-10-28 11:58:20 -070010926 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010927}
10928
10929
10930static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags)
10931{
10932 struct i802_bss *bss = priv;
10933 char path[128];
10934 int ret;
10935
10936 wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x",
10937 filter_flags);
10938
10939 /* Configure filtering of unicast frame encrypted using GTK */
10940 ret = os_snprintf(path, sizeof(path),
10941 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
10942 bss->ifname);
10943 if (os_snprintf_error(sizeof(path), ret))
10944 return -1;
10945
10946 ret = nl80211_write_to_file(path,
10947 !!(filter_flags &
10948 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10949 if (ret) {
10950 wpa_printf(MSG_ERROR,
10951 "nl80211: Failed to set IPv4 unicast in multicast filter");
10952 return ret;
10953 }
10954
10955 os_snprintf(path, sizeof(path),
10956 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
10957 bss->ifname);
10958 ret = nl80211_write_to_file(path,
10959 !!(filter_flags &
10960 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10961
10962 if (ret) {
10963 wpa_printf(MSG_ERROR,
10964 "nl80211: Failed to set IPv6 unicast in multicast filter");
10965 return ret;
10966 }
10967
10968 /* Configure filtering of unicast frame encrypted using GTK */
10969 os_snprintf(path, sizeof(path),
10970 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
10971 bss->ifname);
10972 ret = nl80211_write_to_file(path,
10973 !!(filter_flags &
10974 WPA_DATA_FRAME_FILTER_FLAG_ARP));
10975 if (ret) {
10976 wpa_printf(MSG_ERROR,
10977 "nl80211: Failed set gratuitous ARP filter");
10978 return ret;
10979 }
10980
10981 /* Configure filtering of IPv6 NA frames */
10982 os_snprintf(path, sizeof(path),
10983 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
10984 bss->ifname);
10985 ret = nl80211_write_to_file(path,
10986 !!(filter_flags &
10987 WPA_DATA_FRAME_FILTER_FLAG_NA));
10988 if (ret) {
10989 wpa_printf(MSG_ERROR,
10990 "nl80211: Failed to set unsolicited NA filter");
10991 return ret;
10992 }
10993
10994 return 0;
10995}
10996
10997
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070010998static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type,
10999 const u8 **ext_capa, const u8 **ext_capa_mask,
11000 unsigned int *ext_capa_len)
11001{
11002 struct i802_bss *bss = priv;
11003 struct wpa_driver_nl80211_data *drv = bss->drv;
11004 enum nl80211_iftype nlmode;
11005 unsigned int i;
11006
11007 if (!ext_capa || !ext_capa_mask || !ext_capa_len)
11008 return -1;
11009
11010 nlmode = wpa_driver_nl80211_if_type(type);
11011
11012 /* By default, use the per-radio values */
11013 *ext_capa = drv->extended_capa;
11014 *ext_capa_mask = drv->extended_capa_mask;
11015 *ext_capa_len = drv->extended_capa_len;
11016
11017 /* Replace the default value if a per-interface type value exists */
11018 for (i = 0; i < drv->num_iface_ext_capa; i++) {
11019 if (nlmode == drv->iface_ext_capa[i].iftype) {
11020 *ext_capa = drv->iface_ext_capa[i].ext_capa;
11021 *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask;
11022 *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len;
11023 break;
11024 }
11025 }
11026
11027 return 0;
11028}
11029
11030
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011031static int nl80211_update_connection_params(
11032 void *priv, struct wpa_driver_associate_params *params,
11033 enum wpa_drv_update_connect_params_mask mask)
11034{
11035 struct i802_bss *bss = priv;
11036 struct wpa_driver_nl80211_data *drv = bss->drv;
11037 struct nl_msg *msg;
11038 int ret = -1;
11039 enum nl80211_auth_type type;
11040
Hai Shalomc3565922019-10-28 11:58:20 -070011041 /* Update Connection Params is intended for drivers that implement
11042 * internal SME and expect these updated connection params from
11043 * wpa_supplicant. Do not send this request for the drivers using
11044 * SME from wpa_supplicant.
11045 */
11046 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
11047 return 0;
11048
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011049 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS);
11050 if (!msg)
11051 goto fail;
11052
11053 wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)",
11054 drv->ifindex);
11055
11056 if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) {
11057 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
11058 params->wpa_ie))
11059 goto fail;
11060 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie,
11061 params->wpa_ie_len);
11062 }
11063
11064 if (mask & WPA_DRV_UPDATE_AUTH_TYPE) {
11065 type = get_nl_auth_type(params->auth_alg);
11066 if (type == NL80211_AUTHTYPE_MAX ||
11067 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
11068 goto fail;
11069 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
11070 }
11071
11072 if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) &&
11073 nl80211_put_fils_connect_params(drv, params, msg))
11074 goto fail;
11075
11076 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11077 msg = NULL;
11078 if (ret)
11079 wpa_dbg(drv->ctx, MSG_DEBUG,
11080 "nl80211: Update connect params command failed: ret=%d (%s)",
11081 ret, strerror(-ret));
11082
11083fail:
11084 nlmsg_free(msg);
11085 return ret;
11086}
11087
11088
Roshan Pius3a1667e2018-07-03 15:17:14 -070011089static int nl80211_send_external_auth_status(void *priv,
11090 struct external_auth *params)
11091{
11092 struct i802_bss *bss = priv;
11093 struct wpa_driver_nl80211_data *drv = bss->drv;
11094 struct nl_msg *msg = NULL;
11095 int ret = -1;
11096
Hai Shalom5f92bc92019-04-18 11:54:11 -070011097 /* External auth command/status is intended for drivers that implement
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080011098 * internal SME but want to offload authentication processing (e.g.,
11099 * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers
Hai Shalom5f92bc92019-04-18 11:54:11 -070011100 * which do not support AP SME or use wpa_supplicant/hostapd SME.
11101 */
Hai Shalom81f62d82019-07-22 12:10:00 -070011102 if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070011103 (drv->capa.flags & WPA_DRIVER_FLAGS_SME))
11104 return -1;
11105
Roshan Pius3a1667e2018-07-03 15:17:14 -070011106 wpa_dbg(drv->ctx, MSG_DEBUG,
11107 "nl80211: External auth status: %u", params->status);
11108
11109 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH);
11110 if (!msg ||
11111 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070011112 (params->ssid && params->ssid_len &&
11113 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
11114 (params->pmkid &&
11115 nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) ||
11116 (params->bssid &&
11117 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)))
Roshan Pius3a1667e2018-07-03 15:17:14 -070011118 goto fail;
11119 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11120 msg = NULL;
11121 if (ret) {
11122 wpa_printf(MSG_DEBUG,
11123 "nl80211: External Auth status update failed: ret=%d (%s)",
11124 ret, strerror(-ret));
11125 goto fail;
11126 }
11127fail:
11128 nlmsg_free(msg);
11129 return ret;
11130}
11131
11132
Hai Shalom74f70d42019-02-11 14:42:39 -080011133static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname,
11134 int val)
11135{
11136 struct i802_bss *bss = priv;
11137 struct wpa_driver_nl80211_data *drv = bss->drv;
11138 struct nl_msg *msg;
11139 int ret = -ENOBUFS;
11140
11141 wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)",
11142 val ? "Enable" : "Disable", bridge_ifname);
11143
11144 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
11145 if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val))
11146 goto fail;
11147
11148 if (bridge_ifname[0] && bss->added_if_into_bridge && !val) {
11149 if (linux_br_del_if(drv->global->ioctl_sock,
11150 bridge_ifname, bss->ifname)) {
11151 wpa_printf(MSG_ERROR,
11152 "nl80211: Failed to remove interface %s from bridge %s",
11153 bss->ifname, bridge_ifname);
11154 return -1;
11155 }
11156 bss->added_if_into_bridge = 0;
11157 }
11158
11159 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11160 msg = NULL;
11161 if (!ret) {
11162 if (bridge_ifname[0] && val &&
11163 i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0)
11164 return -1;
11165 return 0;
11166 }
11167
11168fail:
11169 nlmsg_free(msg);
11170 wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr");
11171
11172 return ret;
11173}
11174
11175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011176const struct wpa_driver_ops wpa_driver_nl80211_ops = {
11177 .name = "nl80211",
11178 .desc = "Linux nl80211/cfg80211",
11179 .get_bssid = wpa_driver_nl80211_get_bssid,
11180 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011181 .set_key = driver_nl80211_set_key,
11182 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011183 .sched_scan = wpa_driver_nl80211_sched_scan,
11184 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011185 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011186 .abort_scan = wpa_driver_nl80211_abort_scan,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011187 .deauthenticate = driver_nl80211_deauthenticate,
11188 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011189 .associate = wpa_driver_nl80211_associate,
11190 .global_init = nl80211_global_init,
11191 .global_deinit = nl80211_global_deinit,
11192 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011193 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011194 .get_capa = wpa_driver_nl80211_get_capa,
11195 .set_operstate = wpa_driver_nl80211_set_operstate,
11196 .set_supp_port = wpa_driver_nl80211_set_supp_port,
11197 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -080011198 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011199 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -070011200 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011201 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011202 .if_remove = driver_nl80211_if_remove,
11203 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011204 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011205 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011206 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011207 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
11208 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Hai Shalom81f62d82019-07-22 12:10:00 -070011209 .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011210 .hapd_init = i802_init,
11211 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -070011212 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011213 .get_seqnum = i802_get_seqnum,
11214 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011215 .get_inact_sec = i802_get_inact_sec,
11216 .sta_clear_stats = i802_sta_clear_stats,
11217 .set_rts = i802_set_rts,
11218 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011219 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011220 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011221 .sta_deauth = i802_sta_deauth,
11222 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011223 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011224 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011225 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011226 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
11227 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
11228 .cancel_remain_on_channel =
11229 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011230 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011231 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -070011232 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011233 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011234 .signal_monitor = nl80211_signal_monitor,
11235 .signal_poll = nl80211_signal_poll,
Hai Shalom74f70d42019-02-11 14:42:39 -080011236 .channel_info = nl80211_channel_info,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011237 .send_frame = nl80211_send_frame,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011238 .set_param = nl80211_set_param,
11239 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -070011240 .add_pmkid = nl80211_add_pmkid,
11241 .remove_pmkid = nl80211_remove_pmkid,
11242 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011243 .set_rekey_info = nl80211_set_rekey_info,
11244 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011245 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -070011246 .start_dfs_cac = nl80211_start_radar_detection,
11247 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011248#ifdef CONFIG_TDLS
11249 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
11250 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011251 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
11252 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011253#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -070011254 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Hai Shalom81f62d82019-07-22 12:10:00 -070011255 .update_dh_ie = nl80211_update_dh_ie,
Dmitry Shmidt34af3062013-07-11 10:46:32 -070011256 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011257 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -070011258 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011259 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011260#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070011261 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011262 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070011263 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011264#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070011265#ifdef ANDROID
Dmitry Shmidt41712582015-06-29 11:02:15 -070011266#ifndef ANDROID_LIB_STUB
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070011267 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt41712582015-06-29 11:02:15 -070011268#endif /* !ANDROID_LIB_STUB */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011269#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011270 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011271 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011272 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011273 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011274#ifdef CONFIG_MESH
11275 .init_mesh = wpa_driver_nl80211_init_mesh,
11276 .join_mesh = wpa_driver_nl80211_join_mesh,
11277 .leave_mesh = wpa_driver_nl80211_leave_mesh,
Hai Shalom81f62d82019-07-22 12:10:00 -070011278 .probe_mesh_link = nl80211_probe_mesh_link,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011279#endif /* CONFIG_MESH */
11280 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
11281 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
11282 .br_port_set_attr = wpa_driver_br_port_set_attr,
11283 .br_set_net_param = wpa_driver_br_set_net_param,
11284 .add_tx_ts = nl80211_add_ts,
11285 .del_tx_ts = nl80211_del_ts,
Dmitry Shmidte4663042016-04-04 10:07:49 -070011286 .get_ifindex = nl80211_get_ifindex,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011287#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011288 .roaming = nl80211_roaming,
Roshan Pius3a1667e2018-07-03 15:17:14 -070011289 .disable_fils = nl80211_disable_fils,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011290 .do_acs = wpa_driver_do_acs,
Ravi Joshie6ccb162015-07-16 17:45:41 -070011291 .set_band = nl80211_set_band,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011292 .get_pref_freq_list = nl80211_get_pref_freq_list,
11293 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011294 .p2p_lo_start = nl80211_p2p_lo_start,
11295 .p2p_lo_stop = nl80211_p2p_lo_stop,
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070011296 .set_default_scan_ies = nl80211_set_default_scan_ies,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080011297 .set_tdls_mode = nl80211_set_tdls_mode,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011298#ifdef CONFIG_MBO
11299 .get_bss_transition_status = nl80211_get_bss_transition_status,
11300 .ignore_assoc_disallow = nl80211_ignore_assoc_disallow,
11301#endif /* CONFIG_MBO */
11302 .set_bssid_blacklist = nl80211_set_bssid_blacklist,
Hai Shalomc3565922019-10-28 11:58:20 -070011303 .add_sta_node = nl80211_add_sta_node,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011304#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011305 .configure_data_frame_filters = nl80211_configure_data_frame_filters,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070011306 .get_ext_capab = nl80211_get_ext_capab,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011307 .update_connect_params = nl80211_update_connection_params,
Roshan Pius3a1667e2018-07-03 15:17:14 -070011308 .send_external_auth_status = nl80211_send_external_auth_status,
Hai Shalom74f70d42019-02-11 14:42:39 -080011309 .set_4addr_mode = nl80211_set_4addr_mode,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011310};