blob: 75792f340ac0748be809afddcbb49faafd61f543 [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 Shmidt8d520ff2011-05-09 14:06:53 -070033#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080034#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "linux_ioctl.h"
36#include "radiotap.h"
37#include "radiotap_iter.h"
38#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039#include "driver_nl80211.h"
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080040
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041
Hai Shalom74f70d42019-02-11 14:42:39 -080042#ifndef NETLINK_CAP_ACK
43#define NETLINK_CAP_ACK 10
44#endif /* NETLINK_CAP_ACK */
Hai Shalom39ba6fc2019-01-22 12:40:38 -080045/* support for extack if compilation headers are too old */
46#ifndef NETLINK_EXT_ACK
47#define NETLINK_EXT_ACK 11
48enum nlmsgerr_attrs {
49 NLMSGERR_ATTR_UNUSED,
50 NLMSGERR_ATTR_MSG,
51 NLMSGERR_ATTR_OFFS,
52 NLMSGERR_ATTR_COOKIE,
53
54 __NLMSGERR_ATTR_MAX,
55 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
56};
57#endif
58#ifndef NLM_F_CAPPED
59#define NLM_F_CAPPED 0x100
60#endif
61#ifndef NLM_F_ACK_TLVS
62#define NLM_F_ACK_TLVS 0x200
63#endif
64#ifndef SOL_NETLINK
65#define SOL_NETLINK 270
66#endif
67
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068
Dmitry Shmidt54605472013-11-08 11:10:19 -080069#ifdef ANDROID
70/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -080071#undef nl_socket_set_nonblocking
72#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080073
Dmitry Shmidt54605472013-11-08 11:10:19 -080074#endif /* ANDROID */
75
76
Hai Shalomfdcde762020-04-02 11:19:20 -070077static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080078{
Hai Shalomfdcde762020-04-02 11:19:20 -070079 struct nl_sock *handle;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080080
Hai Shalomfdcde762020-04-02 11:19:20 -070081 handle = nl_socket_alloc_cb(cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080082 if (handle == NULL) {
83 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
84 "callbacks (%s)", dbg);
85 return NULL;
86 }
87
88 if (genl_connect(handle)) {
89 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
90 "netlink (%s)", dbg);
Hai Shalomfdcde762020-04-02 11:19:20 -070091 nl_socket_free(handle);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080092 return NULL;
93 }
94
95 return handle;
96}
97
98
Hai Shalomfdcde762020-04-02 11:19:20 -070099static void nl_destroy_handles(struct nl_sock **handle)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800100{
101 if (*handle == NULL)
102 return;
Hai Shalomfdcde762020-04-02 11:19:20 -0700103 nl_socket_free(*handle);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800104 *handle = NULL;
105}
106
107
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700108#if __WORDSIZE == 64
109#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
110#else
111#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
112#endif
113
Hai Shalomfdcde762020-04-02 11:19:20 -0700114static void nl80211_register_eloop_read(struct nl_sock **handle,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700115 eloop_sock_handler handler,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700116 void *eloop_data, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700117{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800118 /*
119 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
120 * by default. It is possible to hit that limit in some cases where
121 * operations are blocked, e.g., with a burst of Deauthentication frames
122 * to hostapd and STA entry deletion. Try to increase the buffer to make
123 * this less likely to occur.
124 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700125 int err;
126
127 err = nl_socket_set_buffer_size(*handle, 262144, 0);
128 if (err < 0) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800129 wpa_printf(MSG_DEBUG,
130 "nl80211: Could not set nl_socket RX buffer size: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -0700131 nl_geterror(err));
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800132 /* continue anyway with the default (smaller) buffer */
133 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800134
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700135 nl_socket_set_nonblocking(*handle);
136 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
137 eloop_data, *handle);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700138 if (!persist)
139 *handle = (void *) (((intptr_t) *handle) ^
140 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700141}
142
143
Hai Shalomfdcde762020-04-02 11:19:20 -0700144static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700145{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700146 if (!persist)
147 *handle = (void *) (((intptr_t) *handle) ^
148 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700149 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
150 nl_destroy_handles(handle);
151}
152
153
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800154static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800155static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800156
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800157static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700158static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
159 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800162wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800163 const u8 *set_addr, int first,
164 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800165static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166 unsigned int freq, unsigned int wait,
Hai Shalomfdcde762020-04-02 11:19:20 -0700167 const u8 *buf, size_t buf_len,
168 int save_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800169 int no_cck, int no_ack, int offchanok,
170 const u16 *csa_offs, size_t csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800171static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
172 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800174#define IFIDX_ANY -1
175
176static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
177 int ifidx_reason);
178static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
179 int ifidx_reason);
180static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
181 int ifidx_reason);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700182
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700183static int nl80211_set_channel(struct i802_bss *bss,
184 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700185static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
186 int ifindex, int disabled);
187
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800188static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
189 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800190
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700191static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800192static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700193#ifdef CONFIG_MESH
194static int nl80211_put_mesh_config(struct nl_msg *msg,
195 struct wpa_driver_mesh_bss_params *params);
196#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -0800197static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -0700198 u16 reason);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700199
200
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800201/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800202enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800203{
204 switch (width) {
205 case NL80211_CHAN_WIDTH_20_NOHT:
206 return CHAN_WIDTH_20_NOHT;
207 case NL80211_CHAN_WIDTH_20:
208 return CHAN_WIDTH_20;
209 case NL80211_CHAN_WIDTH_40:
210 return CHAN_WIDTH_40;
211 case NL80211_CHAN_WIDTH_80:
212 return CHAN_WIDTH_80;
213 case NL80211_CHAN_WIDTH_80P80:
214 return CHAN_WIDTH_80P80;
215 case NL80211_CHAN_WIDTH_160:
216 return CHAN_WIDTH_160;
217 }
218 return CHAN_WIDTH_UNKNOWN;
219}
220
221
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800222int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800223{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700224 return nlmode == NL80211_IFTYPE_AP ||
225 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800226}
227
228
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800229int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800230{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700231 return nlmode == NL80211_IFTYPE_STATION ||
232 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800233}
234
235
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700236static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800237{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700238 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
239 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800240}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700241
242
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800243struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
244 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700245{
246 struct i802_bss *bss;
247
248 for (bss = drv->first_bss; bss; bss = bss->next) {
249 if (bss->ifindex == ifindex)
250 return bss;
251 }
252
253 return NULL;
254}
255
256
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800257static int is_mesh_interface(enum nl80211_iftype nlmode)
258{
259 return nlmode == NL80211_IFTYPE_MESH_POINT;
260}
261
262
263void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700264{
265 if (drv->associated)
266 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
267 drv->associated = 0;
268 os_memset(drv->bssid, 0, ETH_ALEN);
Hai Shalom5f92bc92019-04-18 11:54:11 -0700269 drv->first_bss->freq = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700270}
271
272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273/* nl80211 code */
274static int ack_handler(struct nl_msg *msg, void *arg)
275{
276 int *err = arg;
277 *err = 0;
278 return NL_STOP;
279}
280
281static int finish_handler(struct nl_msg *msg, void *arg)
282{
283 int *ret = arg;
284 *ret = 0;
285 return NL_SKIP;
286}
287
288static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
289 void *arg)
290{
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800291 struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1;
292 int len = nlh->nlmsg_len;
293 struct nlattr *attrs;
294 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 int *ret = arg;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800296 int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 *ret = err->error;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800299
300 if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
301 return NL_SKIP;
302
303 if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
304 ack_len += err->msg.nlmsg_len - sizeof(*nlh);
305
306 if (len <= ack_len)
307 return NL_STOP;
308
309 attrs = (void *) ((unsigned char *) nlh + ack_len);
310 len -= ack_len;
311
312 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
313 if (tb[NLMSGERR_ATTR_MSG]) {
314 len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]),
315 nla_len(tb[NLMSGERR_ATTR_MSG]));
316 wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s",
317 len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG]));
318 }
319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 return NL_SKIP;
321}
322
323
324static int no_seq_check(struct nl_msg *msg, void *arg)
325{
326 return NL_OK;
327}
328
329
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800330static void nl80211_nlmsg_clear(struct nl_msg *msg)
331{
332 /*
333 * Clear nlmsg data, e.g., to make sure key material is not left in
334 * heap memory for unnecessarily long time.
335 */
336 if (msg) {
337 struct nlmsghdr *hdr = nlmsg_hdr(msg);
338 void *data = nlmsg_data(hdr);
339 /*
340 * This would use nlmsg_datalen() or the older nlmsg_len() if
341 * only libnl were to maintain a stable API.. Neither will work
342 * with all released versions, so just calculate the length
343 * here.
344 */
345 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
346
347 os_memset(data, 0, len);
348 }
349}
350
351
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800352static int send_and_recv(struct nl80211_global *global,
Hai Shalomfdcde762020-04-02 11:19:20 -0700353 struct nl_sock *nl_handle, struct nl_msg *msg,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 int (*valid_handler)(struct nl_msg *, void *),
355 void *valid_data)
356{
357 struct nl_cb *cb;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800358 int err = -ENOMEM, opt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800360 if (!msg)
361 return -ENOMEM;
362
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800363 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 if (!cb)
365 goto out;
366
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800367 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
368 opt = 1;
369 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
370 NETLINK_EXT_ACK, &opt, sizeof(opt));
371
Hai Shalom74f70d42019-02-11 14:42:39 -0800372 /* try to set NETLINK_CAP_ACK to 1, ignoring errors */
373 opt = 1;
374 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
375 NETLINK_CAP_ACK, &opt, sizeof(opt));
376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 err = nl_send_auto_complete(nl_handle, msg);
Hai Shalomfdcde762020-04-02 11:19:20 -0700378 if (err < 0) {
379 wpa_printf(MSG_INFO,
380 "nl80211: nl_send_auto_complete() failed: %s",
381 nl_geterror(err));
382 /* Need to convert libnl error code to an errno value. For now,
383 * just hardcode this to EBADF; the real error reason is shown
384 * in that error print above. */
385 err = -EBADF;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386 goto out;
Hai Shalomfdcde762020-04-02 11:19:20 -0700387 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388
389 err = 1;
390
391 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
392 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
393 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
394
395 if (valid_handler)
396 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
397 valid_handler, valid_data);
398
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700399 while (err > 0) {
400 int res = nl_recvmsgs(nl_handle, cb);
Hai Shalomfdcde762020-04-02 11:19:20 -0700401
402 if (res == -NLE_DUMP_INTR) {
403 /* Most likely one of the nl80211 dump routines hit a
404 * case where internal results changed while the dump
405 * was being sent. The most common known case for this
406 * is scan results fetching while associated were every
407 * received Beacon frame from the AP may end up
408 * incrementing bss_generation. This
409 * NL80211_CMD_GET_SCAN case tries again in the caller;
410 * other cases (of which there are no known common ones)
411 * will stop and return an error. */
412 wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN",
413 nl_geterror(res));
414 err = -EAGAIN;
415 } else if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700416 wpa_printf(MSG_INFO,
Hai Shalomfdcde762020-04-02 11:19:20 -0700417 "nl80211: %s->nl_recvmsgs failed: %d (%s)",
418 __func__, res, nl_geterror(res));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700419 }
420 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 out:
422 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800423 if (!valid_handler && valid_data == (void *) -1)
424 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 nlmsg_free(msg);
426 return err;
427}
428
429
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800430int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
431 struct nl_msg *msg,
432 int (*valid_handler)(struct nl_msg *, void *),
433 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800435 return send_and_recv(drv->global, drv->global->nl, msg,
436 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700437}
438
439
Hai Shalomb755a2a2020-04-23 21:49:02 -0700440/* Use this method to mark that it is necessary to own the connection/interface
441 * for this operation.
442 * handle may be set to NULL, to get the same behavior as send_and_recv_msgs().
443 * set_owner can be used to mark this socket for receiving control port frames.
444 */
445static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv,
446 struct nl_msg *msg,
447 struct nl_sock *handle, int set_owner,
448 int (*valid_handler)(struct nl_msg *,
449 void *),
450 void *valid_data)
451{
452 /* Control port over nl80211 needs the flags and attributes below.
453 *
454 * The Linux kernel has initial checks for them (in nl80211.c) like:
455 * validate_pae_over_nl80211(...)
456 * or final checks like:
457 * dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid
458 *
459 * Final operations (e.g., disassociate) don't need to set these
460 * attributes, but they have to be performed on the socket, which has
461 * the connection owner property set in the kernel.
462 */
463 if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) &&
464 handle && set_owner &&
465 (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) ||
466 nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) ||
467 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
468 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH)))
469 return -1;
470
471 return send_and_recv(drv->global, handle ? handle : drv->global->nl,
472 msg, valid_handler, valid_data);
473}
474
475
476struct nl_sock * get_connect_handle(struct i802_bss *bss)
477{
478 if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) ||
479 bss->use_nl_connect)
480 return bss->nl_connect;
481
482 return NULL;
483}
484
485
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486struct family_data {
487 const char *group;
488 int id;
489};
490
491
492static int family_handler(struct nl_msg *msg, void *arg)
493{
494 struct family_data *res = arg;
495 struct nlattr *tb[CTRL_ATTR_MAX + 1];
496 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
497 struct nlattr *mcgrp;
498 int i;
499
500 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
501 genlmsg_attrlen(gnlh, 0), NULL);
502 if (!tb[CTRL_ATTR_MCAST_GROUPS])
503 return NL_SKIP;
504
505 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
506 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
507 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
508 nla_len(mcgrp), NULL);
509 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
510 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
511 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
512 res->group,
513 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
514 continue;
515 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
516 break;
517 };
518
519 return NL_SKIP;
520}
521
522
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800523static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700524 const char *family, const char *group)
525{
526 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800527 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528 struct family_data res = { group, -ENOENT };
529
530 msg = nlmsg_alloc();
531 if (!msg)
532 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800533 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
534 0, 0, CTRL_CMD_GETFAMILY, 0) ||
535 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
536 nlmsg_free(msg);
537 return -1;
538 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800540 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 if (ret == 0)
542 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 return ret;
544}
545
546
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800547void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
548 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800549{
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700550 if (TEST_FAIL())
551 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
553 0, flags, cmd, 0);
554}
555
556
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800557static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
558{
559 if (bss->wdev_id_set)
560 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
561 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
562}
563
564
565struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
566{
567 struct nl_msg *msg;
568
569 msg = nlmsg_alloc();
570 if (!msg)
571 return NULL;
572
573 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
574 nl80211_set_iface_id(msg, bss) < 0) {
575 nlmsg_free(msg);
576 return NULL;
577 }
578
579 return msg;
580}
581
582
583static struct nl_msg *
584nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
585 int flags, uint8_t cmd)
586{
587 struct nl_msg *msg;
588
589 msg = nlmsg_alloc();
590 if (!msg)
591 return NULL;
592
593 if (!nl80211_cmd(drv, msg, flags, cmd) ||
594 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
595 nlmsg_free(msg);
596 return NULL;
597 }
598
599 return msg;
600}
601
602
603struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
604 uint8_t cmd)
605{
606 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
607}
608
609
610struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
611{
612 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
613}
614
615
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800616struct wiphy_idx_data {
617 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700618 enum nl80211_iftype nlmode;
619 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620};
621
622
623static int netdev_info_handler(struct nl_msg *msg, void *arg)
624{
625 struct nlattr *tb[NL80211_ATTR_MAX + 1];
626 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
627 struct wiphy_idx_data *info = arg;
628
629 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
630 genlmsg_attrlen(gnlh, 0), NULL);
631
632 if (tb[NL80211_ATTR_WIPHY])
633 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
634
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700635 if (tb[NL80211_ATTR_IFTYPE])
636 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
637
638 if (tb[NL80211_ATTR_MAC] && info->macaddr)
639 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
640 ETH_ALEN);
641
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800642 return NL_SKIP;
643}
644
645
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800646int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800647{
648 struct nl_msg *msg;
649 struct wiphy_idx_data data = {
650 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700651 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800652 };
653
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800654 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
655 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656
657 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
658 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800659 return -1;
660}
661
662
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700663static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
664{
665 struct nl_msg *msg;
666 struct wiphy_idx_data data = {
667 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
668 .macaddr = NULL,
669 };
670
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800671 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
672 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700673
674 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
675 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700676 return NL80211_IFTYPE_UNSPECIFIED;
677}
678
679
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700680static int nl80211_get_macaddr(struct i802_bss *bss)
681{
682 struct nl_msg *msg;
683 struct wiphy_idx_data data = {
684 .macaddr = bss->addr,
685 };
686
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800687 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
688 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700689
690 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700691}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700692
693
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800694static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
695 struct nl80211_wiphy_data *w)
696{
697 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800698 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800699
700 msg = nlmsg_alloc();
701 if (!msg)
702 return -1;
703
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800704 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
705 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
706 nlmsg_free(msg);
707 return -1;
708 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800709
710 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711 if (ret) {
712 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
713 "failed: ret=%d (%s)",
714 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800715 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800716 return ret;
717}
718
719
720static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
721{
722 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700723 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800725 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800726
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700727 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700728 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700729 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
730 __func__, res);
731 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800732}
733
734
735static int process_beacon_event(struct nl_msg *msg, void *arg)
736{
737 struct nl80211_wiphy_data *w = arg;
738 struct wpa_driver_nl80211_data *drv;
739 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
740 struct nlattr *tb[NL80211_ATTR_MAX + 1];
741 union wpa_event_data event;
742
743 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
744 genlmsg_attrlen(gnlh, 0), NULL);
745
746 if (gnlh->cmd != NL80211_CMD_FRAME) {
747 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
748 gnlh->cmd);
749 return NL_SKIP;
750 }
751
752 if (!tb[NL80211_ATTR_FRAME])
753 return NL_SKIP;
754
755 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
756 wiphy_list) {
757 os_memset(&event, 0, sizeof(event));
758 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
759 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
760 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
761 }
762
763 return NL_SKIP;
764}
765
766
767static struct nl80211_wiphy_data *
768nl80211_get_wiphy_data_ap(struct i802_bss *bss)
769{
770 static DEFINE_DL_LIST(nl80211_wiphys);
771 struct nl80211_wiphy_data *w;
772 int wiphy_idx, found = 0;
773 struct i802_bss *tmp_bss;
Paul Stewart092955c2017-02-06 09:13:09 -0800774 u8 channel;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800775
776 if (bss->wiphy_data != NULL)
777 return bss->wiphy_data;
778
779 wiphy_idx = nl80211_get_wiphy_index(bss);
780
781 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
782 if (w->wiphy_idx == wiphy_idx)
783 goto add;
784 }
785
786 /* alloc new one */
787 w = os_zalloc(sizeof(*w));
788 if (w == NULL)
789 return NULL;
790 w->wiphy_idx = wiphy_idx;
791 dl_list_init(&w->bsss);
792 dl_list_init(&w->drvs);
793
Paul Stewart092955c2017-02-06 09:13:09 -0800794 /* Beacon frames not supported in IEEE 802.11ad */
795 if (ieee80211_freq_to_chan(bss->freq, &channel) !=
796 HOSTAPD_MODE_IEEE80211AD) {
797 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
798 if (!w->nl_cb) {
799 os_free(w);
800 return NULL;
801 }
802 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
803 no_seq_check, NULL);
804 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
805 process_beacon_event, w);
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000806
Paul Stewart092955c2017-02-06 09:13:09 -0800807 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
808 "wiphy beacons");
809 if (w->nl_beacons == NULL) {
810 os_free(w);
811 return NULL;
812 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000813
Paul Stewart092955c2017-02-06 09:13:09 -0800814 if (nl80211_register_beacons(bss->drv, w)) {
815 nl_destroy_handles(&w->nl_beacons);
816 os_free(w);
817 return NULL;
818 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000819
Paul Stewart092955c2017-02-06 09:13:09 -0800820 nl80211_register_eloop_read(&w->nl_beacons,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700821 nl80211_recv_beacons, w, 0);
Paul Stewart092955c2017-02-06 09:13:09 -0800822 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800823
824 dl_list_add(&nl80211_wiphys, &w->list);
825
826add:
827 /* drv entry for this bss already there? */
828 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
829 if (tmp_bss->drv == bss->drv) {
830 found = 1;
831 break;
832 }
833 }
834 /* if not add it */
835 if (!found)
836 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
837
838 dl_list_add(&w->bsss, &bss->wiphy_list);
839 bss->wiphy_data = w;
840 return w;
841}
842
843
844static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
845{
846 struct nl80211_wiphy_data *w = bss->wiphy_data;
847 struct i802_bss *tmp_bss;
848 int found = 0;
849
850 if (w == NULL)
851 return;
852 bss->wiphy_data = NULL;
853 dl_list_del(&bss->wiphy_list);
854
855 /* still any for this drv present? */
856 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
857 if (tmp_bss->drv == bss->drv) {
858 found = 1;
859 break;
860 }
861 }
862 /* if not remove it */
863 if (!found)
864 dl_list_del(&bss->drv->wiphy_list);
865
866 if (!dl_list_empty(&w->bsss))
867 return;
868
Paul Stewart092955c2017-02-06 09:13:09 -0800869 if (w->nl_beacons)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700870 nl80211_destroy_eloop_handle(&w->nl_beacons, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800871
872 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800873 dl_list_del(&w->list);
874 os_free(w);
875}
876
877
Dmitry Shmidte4663042016-04-04 10:07:49 -0700878static unsigned int nl80211_get_ifindex(void *priv)
879{
880 struct i802_bss *bss = priv;
881 struct wpa_driver_nl80211_data *drv = bss->drv;
882
883 return drv->ifindex;
884}
885
886
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700887static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
888{
889 struct i802_bss *bss = priv;
890 struct wpa_driver_nl80211_data *drv = bss->drv;
891 if (!drv->associated)
892 return -1;
893 os_memcpy(bssid, drv->bssid, ETH_ALEN);
894 return 0;
895}
896
897
898static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
899{
900 struct i802_bss *bss = priv;
901 struct wpa_driver_nl80211_data *drv = bss->drv;
902 if (!drv->associated)
903 return -1;
904 os_memcpy(ssid, drv->ssid, drv->ssid_len);
905 return drv->ssid_len;
906}
907
908
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800909static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700910 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
911 int ifindex, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912{
913 union wpa_event_data event;
914
Dmitry Shmidte4663042016-04-04 10:07:49 -0700915 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800916 if (if_nametoindex(drv->first_bss->ifname) == 0) {
917 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
918 drv->first_bss->ifname);
919 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700920 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800921 if (!drv->if_removed)
922 return;
923 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
924 drv->first_bss->ifname);
925 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 }
927
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800928 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700929 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800930 os_strlcpy(event.interface_status.ifname, ifname,
931 sizeof(event.interface_status.ifname));
932 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700933 if (drv)
934 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
935 else
936 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
937 &event);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800938}
939
940
941static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700942 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
943 int ifindex, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800944{
945 union wpa_event_data event;
946
Dmitry Shmidte4663042016-04-04 10:07:49 -0700947 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800948 if (drv->if_removed) {
949 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
950 ifname);
951 return;
952 }
953 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
954 ifname);
955 drv->if_removed = 1;
956 } else {
957 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
958 ifname);
959 }
960
961 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700962 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800963 os_strlcpy(event.interface_status.ifname, ifname,
964 sizeof(event.interface_status.ifname));
965 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700966 if (drv)
967 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
968 else
969 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
970 &event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971}
972
973
974static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
975 u8 *buf, size_t len)
976{
977 int attrlen, rta_len;
978 struct rtattr *attr;
979
980 attrlen = len;
981 attr = (struct rtattr *) buf;
982
983 rta_len = RTA_ALIGN(sizeof(struct rtattr));
984 while (RTA_OK(attr, attrlen)) {
985 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800986 if (os_strcmp(((char *) attr) + rta_len,
987 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 return 1;
989 else
990 break;
991 }
992 attr = RTA_NEXT(attr, attrlen);
993 }
994
995 return 0;
996}
997
998
999static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
1000 int ifindex, u8 *buf, size_t len)
1001{
1002 if (drv->ifindex == ifindex)
1003 return 1;
1004
1005 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001006 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
1008 "interface");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001009 if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0)
1010 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011 return 1;
1012 }
1013
1014 return 0;
1015}
1016
1017
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001018static struct wpa_driver_nl80211_data *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001019nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len,
1020 int *init_failed)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001021{
1022 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001023 int res;
1024
1025 if (init_failed)
1026 *init_failed = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001027 dl_list_for_each(drv, &global->interfaces,
1028 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001029 res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len);
1030 if (res < 0) {
1031 wpa_printf(MSG_DEBUG,
1032 "nl80211: Found matching own interface, but failed to complete reinitialization");
1033 if (init_failed)
1034 *init_failed = 1;
1035 return drv;
1036 }
1037 if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001038 return drv;
1039 }
1040 return NULL;
1041}
1042
1043
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001044static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001045 int ifindex, int notify)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001046{
1047 struct i802_bss *bss;
1048 u8 addr[ETH_ALEN];
1049
1050 bss = get_bss_ifindex(drv, ifindex);
1051 if (bss &&
1052 linux_get_ifhwaddr(drv->global->ioctl_sock,
1053 bss->ifname, addr) < 0) {
1054 wpa_printf(MSG_DEBUG,
1055 "nl80211: %s: failed to re-read MAC address",
1056 bss->ifname);
1057 } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1058 wpa_printf(MSG_DEBUG,
1059 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1060 MACSTR " to " MACSTR,
1061 ifindex, bss->ifname,
1062 MAC2STR(bss->addr), MAC2STR(addr));
1063 os_memcpy(bss->addr, addr, ETH_ALEN);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001064 if (notify)
1065 wpa_supplicant_event(drv->ctx,
1066 EVENT_INTERFACE_MAC_CHANGED, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001067 }
1068}
1069
1070
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
1072 struct ifinfomsg *ifi,
1073 u8 *buf, size_t len)
1074{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001075 struct nl80211_global *global = ctx;
1076 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001077 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078 struct rtattr *attr;
1079 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001080 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001081 char ifname[IFNAMSIZ + 1];
1082 char extra[100], *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001083 int init_failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001085 extra[0] = '\0';
1086 pos = extra;
1087 end = pos + sizeof(extra);
1088 ifname[0] = '\0';
1089
1090 attrlen = len;
1091 attr = (struct rtattr *) buf;
1092 while (RTA_OK(attr, attrlen)) {
1093 switch (attr->rta_type) {
1094 case IFLA_IFNAME:
Hai Shalomfdcde762020-04-02 11:19:20 -07001095 if (RTA_PAYLOAD(attr) > IFNAMSIZ)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001096 break;
1097 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1098 ifname[RTA_PAYLOAD(attr)] = '\0';
1099 break;
1100 case IFLA_MASTER:
1101 brid = nla_get_u32((struct nlattr *) attr);
1102 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1103 break;
1104 case IFLA_WIRELESS:
1105 pos += os_snprintf(pos, end - pos, " wext");
1106 break;
1107 case IFLA_OPERSTATE:
1108 pos += os_snprintf(pos, end - pos, " operstate=%u",
1109 nla_get_u32((struct nlattr *) attr));
1110 break;
1111 case IFLA_LINKMODE:
1112 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1113 nla_get_u32((struct nlattr *) attr));
1114 break;
1115 }
1116 attr = RTA_NEXT(attr, attrlen);
1117 }
1118 extra[sizeof(extra) - 1] = '\0';
1119
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001120 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1121 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1122 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1124 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1125 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1126 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1127
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001128 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001129 if (!drv)
1130 goto event_newlink;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001131 if (init_failed)
1132 return; /* do not update interface state */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001135 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001136 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001137 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001138 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1139 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001140 drv->ignore_if_down_event = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001141 /* Re-read MAC address as it may have changed */
1142 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001143 return;
1144 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001145 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
1146 namebuf, ifname);
1147 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1148 wpa_printf(MSG_DEBUG,
1149 "nl80211: Not the main interface (%s) - do not indicate interface down",
1150 drv->first_bss->ifname);
1151 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001152 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1153 "event generated by mode change");
1154 drv->ignore_if_down_event = 0;
1155 } else {
1156 drv->if_disabled = 1;
1157 wpa_supplicant_event(drv->ctx,
1158 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001159
1160 /*
1161 * Try to get drv again, since it may be removed as
1162 * part of the EVENT_INTERFACE_DISABLED handling for
1163 * dynamic interfaces
1164 */
1165 drv = nl80211_find_drv(global, ifi->ifi_index,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001166 buf, len, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001167 if (!drv)
1168 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001169 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170 }
1171
1172 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07001173 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001174 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001175 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1177 "event since interface %s is down",
1178 namebuf);
Hai Shalomc9e41a12018-07-31 14:41:42 -07001179 return;
1180 }
1181 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
1182 namebuf, ifname);
1183 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1184 wpa_printf(MSG_DEBUG,
1185 "nl80211: Not the main interface (%s) - do not indicate interface up",
1186 drv->first_bss->ifname);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001187 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001188 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1189 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001190 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001191 } else if (drv->if_removed) {
1192 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1193 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001194 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001196 /* Re-read MAC address as it may have changed */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001197 nl80211_refresh_mac(drv, ifi->ifi_index, 0);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001199 drv->if_disabled = 0;
1200 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1201 NULL);
1202 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001203 }
1204
1205 /*
1206 * Some drivers send the association event before the operup event--in
1207 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1208 * fails. This will hit us when wpa_supplicant does not need to do
1209 * IEEE 802.1X authentication
1210 */
1211 if (drv->operstate == 1 &&
1212 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001213 !(ifi->ifi_flags & IFF_RUNNING)) {
1214 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001215 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 }
1218
Dmitry Shmidte4663042016-04-04 10:07:49 -07001219event_newlink:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001220 if (ifname[0])
Dmitry Shmidte4663042016-04-04 10:07:49 -07001221 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1222 ifname);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001223
Dmitry Shmidte4663042016-04-04 10:07:49 -07001224 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001225 struct i802_bss *bss;
1226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001228 if (!if_indextoname(brid, namebuf)) {
1229 wpa_printf(MSG_DEBUG,
1230 "nl80211: Could not find bridge ifname for ifindex %u",
1231 brid);
1232 return;
1233 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1235 brid, namebuf);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001236 add_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001237
1238 for (bss = drv->first_bss; bss; bss = bss->next) {
1239 if (os_strcmp(ifname, bss->ifname) == 0) {
1240 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1241 break;
1242 }
1243 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245}
1246
1247
1248static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1249 struct ifinfomsg *ifi,
1250 u8 *buf, size_t len)
1251{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001252 struct nl80211_global *global = ctx;
1253 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001254 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 struct rtattr *attr;
1256 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001257 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001258 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001260 extra[0] = '\0';
1261 pos = extra;
1262 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001263 ifname[0] = '\0';
1264
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001265 attrlen = len;
1266 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001268 switch (attr->rta_type) {
1269 case IFLA_IFNAME:
Hai Shalomfdcde762020-04-02 11:19:20 -07001270 if (RTA_PAYLOAD(attr) > IFNAMSIZ)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001271 break;
1272 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1273 ifname[RTA_PAYLOAD(attr)] = '\0';
1274 break;
1275 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001277 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1278 break;
1279 case IFLA_OPERSTATE:
1280 pos += os_snprintf(pos, end - pos, " operstate=%u",
1281 nla_get_u32((struct nlattr *) attr));
1282 break;
1283 case IFLA_LINKMODE:
1284 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1285 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001286 break;
1287 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 attr = RTA_NEXT(attr, attrlen);
1289 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001290 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001292 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1293 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1294 ifi->ifi_flags,
1295 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1296 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1297 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1298 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1299
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001300 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001301
Dmitry Shmidte4663042016-04-04 10:07:49 -07001302 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 /* device has been removed from bridge */
1304 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001305
1306 if (!if_indextoname(brid, namebuf)) {
1307 wpa_printf(MSG_DEBUG,
1308 "nl80211: Could not find bridge ifname for ifindex %u",
1309 brid);
1310 } else {
1311 wpa_printf(MSG_DEBUG,
1312 "nl80211: Remove ifindex %u for bridge %s",
1313 brid, namebuf);
1314 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001315 del_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001317
1318 if (ifi->ifi_family != AF_BRIDGE || !brid)
1319 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1320 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321}
1322
1323
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001324struct nl80211_get_assoc_freq_arg {
1325 struct wpa_driver_nl80211_data *drv;
1326 unsigned int assoc_freq;
1327 unsigned int ibss_freq;
1328 u8 assoc_bssid[ETH_ALEN];
1329 u8 assoc_ssid[SSID_MAX_LEN];
1330 u8 assoc_ssid_len;
1331};
1332
1333static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg)
1334{
1335 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1336 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1337 struct nlattr *bss[NL80211_BSS_MAX + 1];
1338 static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
1339 [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC },
1340 [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
1341 [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC },
1342 [NL80211_BSS_STATUS] = { .type = NLA_U32 },
1343 };
1344 struct nl80211_get_assoc_freq_arg *ctx = arg;
1345 enum nl80211_bss_status status;
1346
1347 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1348 genlmsg_attrlen(gnlh, 0), NULL);
1349 if (!tb[NL80211_ATTR_BSS] ||
1350 nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS],
1351 bss_policy) ||
1352 !bss[NL80211_BSS_STATUS])
1353 return NL_SKIP;
1354
1355 status = nla_get_u32(bss[NL80211_BSS_STATUS]);
1356 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1357 bss[NL80211_BSS_FREQUENCY]) {
1358 ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1359 wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz",
1360 ctx->assoc_freq);
1361 }
1362 if (status == NL80211_BSS_STATUS_IBSS_JOINED &&
1363 bss[NL80211_BSS_FREQUENCY]) {
1364 ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1365 wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz",
1366 ctx->ibss_freq);
1367 }
1368 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1369 bss[NL80211_BSS_BSSID]) {
1370 os_memcpy(ctx->assoc_bssid,
1371 nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN);
1372 wpa_printf(MSG_DEBUG, "nl80211: Associated with "
1373 MACSTR, MAC2STR(ctx->assoc_bssid));
1374 }
1375
1376 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1377 bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
1378 const u8 *ie, *ssid;
1379 size_t ie_len;
1380
1381 ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1382 ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1383 ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
1384 if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) {
1385 ctx->assoc_ssid_len = ssid[1];
1386 os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]);
1387 }
1388 }
1389
1390 return NL_SKIP;
1391}
1392
1393
1394int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001395{
1396 struct nl_msg *msg;
1397 int ret;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001398 struct nl80211_get_assoc_freq_arg arg;
Hai Shalomfdcde762020-04-02 11:19:20 -07001399 int count = 0;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001400
Hai Shalomfdcde762020-04-02 11:19:20 -07001401try_again:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001402 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001403 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001404 arg.drv = drv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001405 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1406 &arg);
Hai Shalomfdcde762020-04-02 11:19:20 -07001407 if (ret == -EAGAIN) {
1408 count++;
1409 if (count >= 10) {
1410 wpa_printf(MSG_INFO,
1411 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid");
1412 } else {
1413 wpa_printf(MSG_DEBUG,
1414 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again");
1415 goto try_again;
1416 }
1417 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001418 if (ret == 0) {
1419 os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len);
1420 return arg.assoc_ssid_len;
1421 }
1422 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)",
1423 ret, strerror(-ret));
1424 return ret;
1425}
1426
1427
1428unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
1429{
1430 struct nl_msg *msg;
1431 int ret;
1432 struct nl80211_get_assoc_freq_arg arg;
Hai Shalomfdcde762020-04-02 11:19:20 -07001433 int count = 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001434
Hai Shalomfdcde762020-04-02 11:19:20 -07001435try_again:
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001436 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1437 os_memset(&arg, 0, sizeof(arg));
1438 arg.drv = drv;
1439 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1440 &arg);
Hai Shalomfdcde762020-04-02 11:19:20 -07001441 if (ret == -EAGAIN) {
1442 count++;
1443 if (count >= 10) {
1444 wpa_printf(MSG_INFO,
1445 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq");
1446 } else {
1447 wpa_printf(MSG_DEBUG,
1448 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again");
1449 goto try_again;
1450 }
1451 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001452 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001453 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1454 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001455 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001456 "associated BSS from scan results: %u MHz", freq);
1457 if (freq)
1458 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001459 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001460 }
1461 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1462 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001463 return drv->assoc_freq;
1464}
1465
1466
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467static int get_link_signal(struct nl_msg *msg, void *arg)
1468{
1469 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1470 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1471 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1472 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1473 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001474 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001475 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476 };
1477 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1478 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1479 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1480 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1481 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1482 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1483 };
1484 struct wpa_signal_info *sig_change = arg;
1485
1486 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1487 genlmsg_attrlen(gnlh, 0), NULL);
1488 if (!tb[NL80211_ATTR_STA_INFO] ||
1489 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1490 tb[NL80211_ATTR_STA_INFO], policy))
1491 return NL_SKIP;
1492 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1493 return NL_SKIP;
1494
1495 sig_change->current_signal =
1496 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1497
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001498 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1499 sig_change->avg_signal =
1500 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1501 else
1502 sig_change->avg_signal = 0;
1503
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001504 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1505 sig_change->avg_beacon_signal =
1506 (s8)
1507 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1508 else
1509 sig_change->avg_beacon_signal = 0;
1510
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001511 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1512 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1513 sinfo[NL80211_STA_INFO_TX_BITRATE],
1514 rate_policy)) {
1515 sig_change->current_txrate = 0;
1516 } else {
1517 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1518 sig_change->current_txrate =
1519 nla_get_u16(rinfo[
1520 NL80211_RATE_INFO_BITRATE]) * 100;
1521 }
1522 }
1523 }
1524
1525 return NL_SKIP;
1526}
1527
1528
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001529int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1530 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531{
1532 struct nl_msg *msg;
1533
Hai Shalom74f70d42019-02-11 14:42:39 -08001534 sig->current_signal = -WPA_INVALID_NOISE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 sig->current_txrate = 0;
1536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001537 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1538 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1539 nlmsg_free(msg);
1540 return -ENOBUFS;
1541 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542
1543 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544}
1545
1546
1547static int get_link_noise(struct nl_msg *msg, void *arg)
1548{
1549 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1550 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1551 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1552 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1553 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1554 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1555 };
1556 struct wpa_signal_info *sig_change = arg;
1557
1558 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1559 genlmsg_attrlen(gnlh, 0), NULL);
1560
1561 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1562 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1563 return NL_SKIP;
1564 }
1565
1566 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1567 tb[NL80211_ATTR_SURVEY_INFO],
1568 survey_policy)) {
1569 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1570 "attributes!");
1571 return NL_SKIP;
1572 }
1573
1574 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1575 return NL_SKIP;
1576
1577 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1578 sig_change->frequency)
1579 return NL_SKIP;
1580
1581 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1582 return NL_SKIP;
1583
1584 sig_change->current_noise =
1585 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1586
1587 return NL_SKIP;
1588}
1589
1590
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001591int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1592 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593{
1594 struct nl_msg *msg;
1595
Hai Shalom74f70d42019-02-11 14:42:39 -08001596 sig_change->current_noise = WPA_INVALID_NOISE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 sig_change->frequency = drv->assoc_freq;
1598
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001599 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001600 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601}
1602
1603
Hai Shalom74f70d42019-02-11 14:42:39 -08001604static int get_channel_info(struct nl_msg *msg, void *arg)
1605{
1606 struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 };
1607 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1608 struct wpa_channel_info *chan_info = arg;
1609
1610 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1611 genlmsg_attrlen(gnlh, 0), NULL);
1612
1613 os_memset(chan_info, 0, sizeof(struct wpa_channel_info));
1614 chan_info->chanwidth = CHAN_WIDTH_UNKNOWN;
1615
1616 if (tb[NL80211_ATTR_WIPHY_FREQ])
1617 chan_info->frequency =
1618 nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
1619 if (tb[NL80211_ATTR_CHANNEL_WIDTH])
1620 chan_info->chanwidth = convert2width(
1621 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
1622 if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1623 enum nl80211_channel_type ct =
1624 nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1625
1626 switch (ct) {
1627 case NL80211_CHAN_HT40MINUS:
1628 chan_info->sec_channel = -1;
1629 break;
1630 case NL80211_CHAN_HT40PLUS:
1631 chan_info->sec_channel = 1;
1632 break;
1633 default:
1634 chan_info->sec_channel = 0;
1635 break;
1636 }
1637 }
1638 if (tb[NL80211_ATTR_CENTER_FREQ1])
1639 chan_info->center_frq1 =
1640 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
1641 if (tb[NL80211_ATTR_CENTER_FREQ2])
1642 chan_info->center_frq2 =
1643 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
1644
1645 if (chan_info->center_frq2) {
1646 u8 seg1_idx = 0;
1647
1648 if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) !=
1649 NUM_HOSTAPD_MODES)
1650 chan_info->seg1_idx = seg1_idx;
1651 }
1652
1653 return NL_SKIP;
1654}
1655
1656
1657static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci)
1658{
1659 struct i802_bss *bss = priv;
1660 struct wpa_driver_nl80211_data *drv = bss->drv;
1661 struct nl_msg *msg;
1662
1663 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
1664 return send_and_recv_msgs(drv, msg, get_channel_info, ci);
1665}
1666
1667
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1669 void *handle)
1670{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001671 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001672 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001673
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001674 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001676 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001677 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001678 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1679 __func__, res);
1680 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681}
1682
1683
1684/**
1685 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1686 * @priv: driver_nl80211 private data
1687 * @alpha2_arg: country to which to switch to
1688 * Returns: 0 on success, -1 on failure
1689 *
1690 * This asks nl80211 to set the regulatory domain for given
1691 * country ISO / IEC alpha2.
1692 */
1693static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1694{
1695 struct i802_bss *bss = priv;
1696 struct wpa_driver_nl80211_data *drv = bss->drv;
1697 char alpha2[3];
1698 struct nl_msg *msg;
1699
1700 msg = nlmsg_alloc();
1701 if (!msg)
1702 return -ENOMEM;
1703
1704 alpha2[0] = alpha2_arg[0];
1705 alpha2[1] = alpha2_arg[1];
1706 alpha2[2] = '\0';
1707
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001708 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1709 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1710 nlmsg_free(msg);
1711 return -EINVAL;
1712 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1714 return -EINVAL;
1715 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001716}
1717
1718
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001719static int nl80211_get_country(struct nl_msg *msg, void *arg)
1720{
1721 char *alpha2 = arg;
1722 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1723 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1724
1725 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1726 genlmsg_attrlen(gnlh, 0), NULL);
1727 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1728 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1729 return NL_SKIP;
1730 }
1731 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1732 return NL_SKIP;
1733}
1734
1735
1736static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1737{
1738 struct i802_bss *bss = priv;
1739 struct wpa_driver_nl80211_data *drv = bss->drv;
1740 struct nl_msg *msg;
1741 int ret;
1742
1743 msg = nlmsg_alloc();
1744 if (!msg)
1745 return -ENOMEM;
1746
1747 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1748 alpha2[0] = '\0';
1749 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1750 if (!alpha2[0])
1751 ret = -1;
1752
1753 return ret;
1754}
1755
1756
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001757static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001758{
1759 int ret;
1760
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001761 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1762 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1764 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001765 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766 }
1767
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001768 global->nl = nl_create_handle(global->nl_cb, "nl");
1769 if (global->nl == NULL)
1770 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001772 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1773 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1775 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001776 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 }
1778
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001779 global->nl_event = nl_create_handle(global->nl_cb, "event");
1780 if (global->nl_event == NULL)
1781 goto err;
1782
1783 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001785 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 if (ret < 0) {
1787 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1788 "membership for scan events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001789 ret, nl_geterror(ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001790 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001791 }
1792
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001793 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001795 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796 if (ret < 0) {
1797 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1798 "membership for mlme events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001799 ret, nl_geterror(ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001800 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 }
1802
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001803 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001804 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001805 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001806 if (ret < 0) {
1807 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1808 "membership for regulatory events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001809 ret, nl_geterror(ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810 /* Continue without regulatory events */
1811 }
1812
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001813 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1814 if (ret >= 0)
1815 ret = nl_socket_add_membership(global->nl_event, ret);
1816 if (ret < 0) {
1817 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1818 "membership for vendor events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001819 ret, nl_geterror(ret));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001820 /* Continue without vendor events */
1821 }
1822
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001823 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1824 no_seq_check, NULL);
1825 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1826 process_global_event, global);
1827
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001828 nl80211_register_eloop_read(&global->nl_event,
1829 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001830 global->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831
1832 return 0;
1833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001834err:
1835 nl_destroy_handles(&global->nl_event);
1836 nl_destroy_handles(&global->nl);
1837 nl_cb_put(global->nl_cb);
1838 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 return -1;
1840}
1841
1842
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001843static void nl80211_check_global(struct nl80211_global *global)
1844{
Hai Shalomfdcde762020-04-02 11:19:20 -07001845 struct nl_sock *handle;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001846 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1847 int ret;
1848 unsigned int i;
1849
1850 /*
1851 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1852 * and all registration having been cleared.
1853 */
1854 handle = (void *) (((intptr_t) global->nl_event) ^
1855 ELOOP_SOCKET_INVALID);
1856
1857 for (i = 0; groups[i]; i++) {
1858 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1859 if (ret >= 0)
1860 ret = nl_socket_add_membership(handle, ret);
1861 if (ret < 0) {
1862 wpa_printf(MSG_INFO,
1863 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001864 groups[i], ret, nl_geterror(ret));
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001865 }
1866 }
1867}
1868
1869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001870static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1871{
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001872 struct wpa_driver_nl80211_data *drv = ctx;
1873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 /*
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001877 * rtnetlink ifdown handler will report interfaces other than the P2P
1878 * Device interface as disabled.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001879 */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001880 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1881 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882}
1883
1884
1885static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1886{
1887 struct wpa_driver_nl80211_data *drv = ctx;
1888 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001889 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1891 "after rfkill unblock");
1892 return;
1893 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001894
1895 if (is_p2p_net_interface(drv->nlmode))
1896 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
1897
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001898 /*
1899 * rtnetlink ifup handler will report interfaces other than the P2P
1900 * Device interface as enabled.
1901 */
1902 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1903 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001904}
1905
1906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001907static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1908 void *eloop_ctx,
1909 void *handle)
1910{
1911 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1912 u8 data[2048];
1913 struct msghdr msg;
1914 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001915 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001916 struct cmsghdr *cmsg;
1917 int res, found_ee = 0, found_wifi = 0, acked = 0;
1918 union wpa_event_data event;
1919
1920 memset(&msg, 0, sizeof(msg));
1921 msg.msg_iov = &entry;
1922 msg.msg_iovlen = 1;
1923 entry.iov_base = data;
1924 entry.iov_len = sizeof(data);
1925 msg.msg_control = &control;
1926 msg.msg_controllen = sizeof(control);
1927
1928 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1929 /* if error or not fitting 802.3 header, return */
1930 if (res < 14)
1931 return;
1932
1933 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1934 {
1935 if (cmsg->cmsg_level == SOL_SOCKET &&
1936 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1937 int *ack;
1938
1939 found_wifi = 1;
1940 ack = (void *)CMSG_DATA(cmsg);
1941 acked = *ack;
1942 }
1943
1944 if (cmsg->cmsg_level == SOL_PACKET &&
1945 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1946 struct sock_extended_err *err =
1947 (struct sock_extended_err *)CMSG_DATA(cmsg);
1948
1949 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1950 found_ee = 1;
1951 }
1952 }
1953
1954 if (!found_ee || !found_wifi)
1955 return;
1956
1957 memset(&event, 0, sizeof(event));
1958 event.eapol_tx_status.dst = data;
1959 event.eapol_tx_status.data = data + 14;
1960 event.eapol_tx_status.data_len = res - 14;
1961 event.eapol_tx_status.ack = acked;
1962 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1963}
1964
1965
Hai Shalomb755a2a2020-04-23 21:49:02 -07001966static int nl80211_init_connect_handle(struct i802_bss *bss)
1967{
1968 if (bss->nl_connect) {
1969 wpa_printf(MSG_DEBUG,
1970 "nl80211: Connect handle already created (nl_connect=%p)",
1971 bss->nl_connect);
1972 return -1;
1973 }
1974
1975 bss->nl_connect = nl_create_handle(bss->nl_cb, "connect");
1976 if (!bss->nl_connect)
1977 return -1;
1978 nl80211_register_eloop_read(&bss->nl_connect,
1979 wpa_driver_nl80211_event_receive,
1980 bss->nl_cb, 1);
1981 return 0;
1982}
1983
1984
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001985static int nl80211_init_bss(struct i802_bss *bss)
1986{
1987 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1988 if (!bss->nl_cb)
1989 return -1;
1990
1991 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1992 no_seq_check, NULL);
1993 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1994 process_bss_event, bss);
1995
Hai Shalomb755a2a2020-04-23 21:49:02 -07001996 nl80211_init_connect_handle(bss);
1997
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001998 return 0;
1999}
2000
2001
2002static void nl80211_destroy_bss(struct i802_bss *bss)
2003{
2004 nl_cb_put(bss->nl_cb);
2005 bss->nl_cb = NULL;
Hai Shalomb755a2a2020-04-23 21:49:02 -07002006
2007 if (bss->nl_connect)
2008 nl80211_destroy_eloop_handle(&bss->nl_connect, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002009}
2010
2011
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002012static void
2013wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
2014{
2015 struct rfkill_config *rcfg;
2016
2017 if (drv->rfkill)
2018 return;
2019
2020 rcfg = os_zalloc(sizeof(*rcfg));
2021 if (!rcfg)
2022 return;
2023
2024 rcfg->ctx = drv;
2025
2026 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
2027 * not associated with a netdev, so use the name of some other interface
2028 * sharing the same wiphy as the P2P Device interface.
2029 *
2030 * Note: This is valid, as a P2P Device interface is always dynamically
2031 * created and is created only once another wpa_s interface was added.
2032 */
2033 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
2034 struct nl80211_global *global = drv->global;
2035 struct wpa_driver_nl80211_data *tmp1;
2036
2037 dl_list_for_each(tmp1, &global->interfaces,
2038 struct wpa_driver_nl80211_data, list) {
2039 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
2040 !tmp1->rfkill)
2041 continue;
2042
2043 wpa_printf(MSG_DEBUG,
2044 "nl80211: Use (%s) to initialize P2P Device rfkill",
2045 tmp1->first_bss->ifname);
2046 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
2047 sizeof(rcfg->ifname));
2048 break;
2049 }
2050 } else {
2051 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
2052 sizeof(rcfg->ifname));
2053 }
2054
2055 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
2056 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
2057 drv->rfkill = rfkill_init(rcfg);
2058 if (!drv->rfkill) {
2059 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
2060 os_free(rcfg);
2061 }
2062}
2063
2064
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002065static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
2066 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002067 const u8 *set_addr,
2068 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069{
2070 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 struct i802_bss *bss;
2072
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002073 if (global_priv == NULL)
2074 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 drv = os_zalloc(sizeof(*drv));
2076 if (drv == NULL)
2077 return NULL;
2078 drv->global = global_priv;
2079 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002080 drv->hostapd = !!hostapd;
2081 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002082
2083 /*
2084 * There is no driver capability flag for this, so assume it is
2085 * supported and disable this on first attempt to use if the driver
2086 * rejects the command due to missing support.
2087 */
2088 drv->set_rekey_offload = 1;
2089
Hai Shalom81f62d82019-07-22 12:10:00 -07002090 drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002091 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002092
2093 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
2094 if (!drv->first_bss) {
2095 os_free(drv);
2096 return NULL;
2097 }
2098 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002100 bss->ctx = ctx;
2101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
2103 drv->monitor_ifidx = -1;
2104 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002105 drv->eapol_tx_sock = -1;
2106 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002108 if (nl80211_init_bss(bss))
2109 goto failed;
2110
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002111 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 goto failed;
2113
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002114 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
2115 if (drv->eapol_tx_sock < 0)
2116 goto failed;
2117
2118 if (drv->data_tx_status) {
2119 int enabled = 1;
2120
2121 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
2122 &enabled, sizeof(enabled)) < 0) {
2123 wpa_printf(MSG_DEBUG,
2124 "nl80211: wifi status sockopt failed\n");
2125 drv->data_tx_status = 0;
2126 if (!drv->use_monitor)
2127 drv->capa.flags &=
2128 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
2129 } else {
2130 eloop_register_read_sock(drv->eapol_tx_sock,
2131 wpa_driver_nl80211_handle_eapol_tx_status,
2132 drv, NULL);
2133 }
2134 }
2135
2136 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002137 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002139 drv->in_interface_list = 1;
2140 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141
2142 return bss;
2143
2144failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002145 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002146 return NULL;
2147}
2148
2149
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002150/**
2151 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2152 * @ctx: context to be used when calling wpa_supplicant functions,
2153 * e.g., wpa_supplicant_event()
2154 * @ifname: interface name, e.g., wlan0
2155 * @global_priv: private driver global data from global_init()
2156 * Returns: Pointer to private data, %NULL on failure
2157 */
2158static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
2159 void *global_priv)
2160{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002161 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
2162 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002163}
2164
2165
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002166static int nl80211_register_frame(struct i802_bss *bss,
Hai Shalomfdcde762020-04-02 11:19:20 -07002167 struct nl_sock *nl_handle,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168 u16 type, const u8 *match, size_t match_len)
2169{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002170 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002172 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002173 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002174
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002175 buf[0] = '\0';
2176 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07002177 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
2178 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002179
Hai Shalomfdcde762020-04-02 11:19:20 -07002180 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002181 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
2182 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
2183 nlmsg_free(msg);
2184 return -1;
2185 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002187 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188 if (ret) {
2189 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
2190 "failed (type=%u): ret=%d (%s)",
2191 type, ret, strerror(-ret));
2192 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
2193 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 return ret;
2196}
2197
2198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002199static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
2200{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002201 if (bss->nl_mgmt) {
2202 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
2203 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
2204 return -1;
2205 }
2206
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002207 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002208 if (bss->nl_mgmt == NULL)
2209 return -1;
2210
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002211 return 0;
2212}
2213
2214
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002215static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
2216{
2217 nl80211_register_eloop_read(&bss->nl_mgmt,
2218 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002219 bss->nl_cb, 0);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002220}
2221
2222
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002223static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002224 const u8 *match, size_t match_len)
2225{
2226 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002227 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002228 type, match, match_len);
2229}
2230
2231
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002234 struct wpa_driver_nl80211_data *drv = bss->drv;
Hai Shalomfdcde762020-04-02 11:19:20 -07002235 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002236 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002237
2238 if (nl80211_alloc_mgmt_handle(bss))
2239 return -1;
2240 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
2241 "handle %p", bss->nl_mgmt);
2242
Hai Shalomfdcde762020-04-02 11:19:20 -07002243 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002244 /* register for any AUTH message */
2245 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07002246 } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
2247 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
2248 /* register for SAE Authentication frames */
2249 nl80211_register_frame(bss, bss->nl_mgmt, type,
2250 (u8 *) "\x03\x00", 2);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002251 }
2252
Dmitry Shmidt051af732013-10-22 13:52:46 -07002253#ifdef CONFIG_INTERWORKING
2254 /* QoS Map Configure */
2255 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002256 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002257#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002258#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002259 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002260 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002261 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002263 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002264 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002266 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002267 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002269 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002270 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08002271 /* Protected GAS Initial Request */
2272 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
2273 ret = -1;
2274 /* Protected GAS Initial Response */
2275 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
2276 ret = -1;
2277 /* Protected GAS Comeback Request */
2278 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
2279 ret = -1;
2280 /* Protected GAS Comeback Response */
2281 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
2282 ret = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002283#endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002284#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002285 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002286 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002287 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
2288 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002289 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002291 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002292 (u8 *) "\x7f\x50\x6f\x9a\x09",
2293 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002294 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295#endif /* CONFIG_P2P */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002296#ifdef CONFIG_DPP
2297 /* DPP Public Action */
2298 if (nl80211_register_action_frame(bss,
2299 (u8 *) "\x04\x09\x50\x6f\x9a\x1a",
2300 6) < 0)
2301 ret = -1;
2302#endif /* CONFIG_DPP */
Hai Shalom74f70d42019-02-11 14:42:39 -08002303#ifdef CONFIG_OCV
2304 /* SA Query Request */
2305 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0)
2306 ret = -1;
2307#endif /* CONFIG_OCV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002309 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002310 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002311#ifdef CONFIG_TDLS
2312 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
2313 /* TDLS Discovery Response */
2314 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
2315 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002316 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002317 }
2318#endif /* CONFIG_TDLS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002319#ifdef CONFIG_FST
2320 /* FST Action frames */
2321 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2322 ret = -1;
2323#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324
2325 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002326 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002327 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328 else
2329 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
2330 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2331
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002332 /* WNM - BSS Transition Management Request */
2333 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002334 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002335 /* WNM-Sleep Mode Response */
2336 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002337 ret = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002338#ifdef CONFIG_WNM
2339 /* WNM - Collocated Interference Request */
2340 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0)
2341 ret = -1;
2342#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002343
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002344#ifdef CONFIG_HS20
2345 /* WNM-Notification */
2346 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002347 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002348#endif /* CONFIG_HS20 */
2349
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002350 /* WMM-AC ADDTS Response */
2351 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
2352 ret = -1;
2353
2354 /* WMM-AC DELTS */
2355 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
2356 ret = -1;
2357
2358 /* Radio Measurement - Neighbor Report Response */
2359 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
2360 ret = -1;
2361
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002362 /* Radio Measurement - Radio Measurement Request */
2363 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0)
2364 ret = -1;
2365
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002366 /* Radio Measurement - Link Measurement Request */
2367 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
2368 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
2369 ret = -1;
2370
2371 nl80211_mgmt_handle_register_eloop(bss);
2372
2373 return ret;
2374}
2375
2376
2377static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2378{
2379 int ret = 0;
2380
2381 if (nl80211_alloc_mgmt_handle(bss))
2382 return -1;
2383
2384 wpa_printf(MSG_DEBUG,
2385 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2386 bss->nl_mgmt);
2387
2388 /* Auth frames for mesh SAE */
2389 if (nl80211_register_frame(bss, bss->nl_mgmt,
2390 (WLAN_FC_TYPE_MGMT << 2) |
2391 (WLAN_FC_STYPE_AUTH << 4),
2392 NULL, 0) < 0)
2393 ret = -1;
2394
2395 /* Mesh peering open */
2396 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2397 ret = -1;
2398 /* Mesh peering confirm */
2399 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2400 ret = -1;
2401 /* Mesh peering close */
2402 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2403 ret = -1;
2404
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002405 nl80211_mgmt_handle_register_eloop(bss);
2406
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002407 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408}
2409
2410
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002411static int nl80211_register_spurious_class3(struct i802_bss *bss)
2412{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002413 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002414 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002415
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002416 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
2417 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002418 if (ret) {
2419 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2420 "failed: ret=%d (%s)",
2421 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002422 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002423 return ret;
2424}
2425
2426
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002427static int nl80211_action_subscribe_ap(struct i802_bss *bss)
2428{
2429 int ret = 0;
2430
2431 /* Public Action frames */
2432 if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0)
2433 ret = -1;
2434 /* RRM Measurement Report */
2435 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0)
2436 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08002437 /* RRM Link Measurement Report */
2438 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0)
2439 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002440 /* RRM Neighbor Report Request */
2441 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0)
2442 ret = -1;
2443 /* FT Action frames */
2444 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2445 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002446 /* SA Query */
2447 if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0)
2448 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002449 /* Protected Dual of Public Action */
2450 if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0)
2451 ret = -1;
2452 /* WNM */
2453 if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0)
2454 ret = -1;
2455 /* WMM */
2456 if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0)
2457 ret = -1;
2458#ifdef CONFIG_FST
2459 /* FST Action frames */
2460 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2461 ret = -1;
2462#endif /* CONFIG_FST */
2463 /* Vendor-specific */
2464 if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0)
2465 ret = -1;
2466
2467 return ret;
2468}
2469
2470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002471static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2472{
2473 static const int stypes[] = {
2474 WLAN_FC_STYPE_AUTH,
2475 WLAN_FC_STYPE_ASSOC_REQ,
2476 WLAN_FC_STYPE_REASSOC_REQ,
2477 WLAN_FC_STYPE_DISASSOC,
2478 WLAN_FC_STYPE_DEAUTH,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002479 WLAN_FC_STYPE_PROBE_REQ,
2480/* Beacon doesn't work as mac80211 doesn't currently allow
2481 * it, but it wouldn't really be the right thing anyway as
2482 * it isn't per interface ... maybe just dump the scan
2483 * results periodically for OLBC?
2484 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002485 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002486 };
2487 unsigned int i;
2488
2489 if (nl80211_alloc_mgmt_handle(bss))
2490 return -1;
2491 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2492 "handle %p", bss->nl_mgmt);
2493
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002494 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002495 if (nl80211_register_frame(bss, bss->nl_mgmt,
2496 (WLAN_FC_TYPE_MGMT << 2) |
2497 (stypes[i] << 4),
2498 NULL, 0) < 0) {
2499 goto out_err;
2500 }
2501 }
2502
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002503 if (nl80211_action_subscribe_ap(bss))
2504 goto out_err;
2505
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002506 if (nl80211_register_spurious_class3(bss))
2507 goto out_err;
2508
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002509 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002510 return 0;
2511
2512out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002513 nl_destroy_handles(&bss->nl_mgmt);
2514 return -1;
2515}
2516
2517
2518static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2519{
2520 if (nl80211_alloc_mgmt_handle(bss))
2521 return -1;
2522 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2523 "handle %p (device SME)", bss->nl_mgmt);
2524
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002525 if (nl80211_action_subscribe_ap(bss))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002526 goto out_err;
2527
Hai Shalom5f92bc92019-04-18 11:54:11 -07002528 if (bss->drv->device_ap_sme) {
2529 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2530
2531 /* Register for all Authentication frames */
2532 if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0)
2533 < 0)
2534 wpa_printf(MSG_DEBUG,
2535 "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work");
2536 }
2537
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002538 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002539 return 0;
2540
2541out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002542 nl_destroy_handles(&bss->nl_mgmt);
2543 return -1;
2544}
2545
2546
2547static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2548{
2549 if (bss->nl_mgmt == NULL)
2550 return;
2551 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2552 "(%s)", bss->nl_mgmt, reason);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002553 nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002554
2555 nl80211_put_wiphy_data_ap(bss);
2556}
2557
2558
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002559static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2560{
2561 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2562}
2563
2564
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002565static void nl80211_del_p2pdev(struct i802_bss *bss)
2566{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002567 struct nl_msg *msg;
2568 int ret;
2569
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002570 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2571 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002572
2573 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2574 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002575 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002576}
2577
2578
2579static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2580{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002581 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002582 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002583
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002584 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2585 NL80211_CMD_STOP_P2P_DEVICE);
2586 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002587
2588 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2589 start ? "Start" : "Stop",
2590 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002591 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002592 return ret;
2593}
2594
2595
2596static int i802_set_iface_flags(struct i802_bss *bss, int up)
2597{
2598 enum nl80211_iftype nlmode;
2599
2600 nlmode = nl80211_get_ifmode(bss);
2601 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2602 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2603 bss->ifname, up);
2604 }
2605
2606 /* P2P Device has start/stop which is equivalent */
2607 return nl80211_set_p2pdev(bss, up);
2608}
2609
2610
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002611#ifdef CONFIG_TESTING_OPTIONS
2612static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2613{
2614 /* struct wpa_driver_nl80211_data *drv = arg; */
2615 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2616 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2617
2618
2619 wpa_printf(MSG_DEBUG,
2620 "nl80211: QCA vendor test command response received");
2621
2622 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2623 genlmsg_attrlen(gnlh, 0), NULL);
2624 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2625 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2626 return NL_SKIP;
2627 }
2628
2629 wpa_hexdump(MSG_DEBUG,
2630 "nl80211: Received QCA vendor test command response",
2631 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2632 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2633
2634 return NL_SKIP;
2635}
2636#endif /* CONFIG_TESTING_OPTIONS */
2637
2638
2639static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2640{
2641#ifdef CONFIG_TESTING_OPTIONS
2642 struct nl_msg *msg;
2643 struct nlattr *params;
2644 int ret;
2645
2646 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2647 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2648 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2649 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2650 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2651 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2652 nlmsg_free(msg);
2653 return;
2654 }
2655 nla_nest_end(msg, params);
2656
2657 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2658 wpa_printf(MSG_DEBUG,
2659 "nl80211: QCA vendor test command returned %d (%s)",
2660 ret, strerror(-ret));
2661#endif /* CONFIG_TESTING_OPTIONS */
2662}
2663
2664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002666wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002667 const u8 *set_addr, int first,
2668 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002669{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002670 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002671 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002672 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673
2674 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002675 bss->ifindex = drv->ifindex;
2676 bss->wdev_id = drv->global->if_add_wdevid;
2677 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2678
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002679 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2680 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002681 drv->global->if_add_wdevid_set = 0;
2682
Dmitry Shmidt03658832014-08-13 11:03:49 -07002683 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2684 bss->static_ap = 1;
2685
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002686 if (first &&
2687 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2688 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2689 drv->start_iface_up = 1;
2690
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002691 if (wpa_driver_nl80211_capa(drv))
2692 return -1;
2693
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002694 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2695 return -1;
2696
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002697 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2698 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002700 if (set_addr &&
2701 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2702 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2703 set_addr)))
2704 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002705
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002706 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2707 drv->start_mode_ap = 1;
2708
Dmitry Shmidt03658832014-08-13 11:03:49 -07002709 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002710 nlmode = NL80211_IFTYPE_AP;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002711 else if (bss->if_dynamic ||
2712 nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002713 nlmode = nl80211_get_ifmode(bss);
2714 else
2715 nlmode = NL80211_IFTYPE_STATION;
2716
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002717 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002718 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002719 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002720 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002721
Dmitry Shmidt98660862014-03-11 17:26:21 -07002722 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002723 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002725 wpa_driver_nl80211_drv_init_rfkill(drv);
2726
Dmitry Shmidt98660862014-03-11 17:26:21 -07002727 if (!rfkill_is_blocked(drv->rfkill)) {
2728 int ret = i802_set_iface_flags(bss, 1);
2729 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2731 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002732 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002734
2735 if (is_p2p_net_interface(nlmode))
2736 nl80211_disable_11b_rates(bss->drv,
2737 bss->drv->ifindex, 1);
2738
Dmitry Shmidt98660862014-03-11 17:26:21 -07002739 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2740 return ret;
2741 } else {
2742 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2743 "interface '%s' due to rfkill", bss->ifname);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002744 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
2745 drv->if_disabled = 1;
2746
Dmitry Shmidt98660862014-03-11 17:26:21 -07002747 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 }
2749
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002750 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002751 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2752 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002754 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2755 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2756 bss->addr))
2757 return -1;
2758 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
2759 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761 if (send_rfkill_event) {
2762 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2763 drv, drv->ctx);
2764 }
2765
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002766 if (drv->vendor_cmd_test_avail)
2767 qca_vendor_test(drv);
2768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 return 0;
2770}
2771
2772
Paul Stewart092955c2017-02-06 09:13:09 -08002773static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774{
2775 struct nl_msg *msg;
Paul Stewart092955c2017-02-06 09:13:09 -08002776 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002777
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002778 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2779 drv->ifindex);
Paul Stewart092955c2017-02-06 09:13:09 -08002780 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002781 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783}
2784
2785
2786/**
2787 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002788 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002789 *
2790 * Shut down driver interface and processing of driver events. Free
2791 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2792 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002793static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002795 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002796 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002797
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002798 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2799 bss->ifname, drv->disabled_11b_rates);
2800
Dmitry Shmidt04949592012-07-19 12:16:46 -07002801 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002802 if (drv->data_tx_status)
2803 eloop_unregister_read_sock(drv->eapol_tx_sock);
2804 if (drv->eapol_tx_sock >= 0)
2805 close(drv->eapol_tx_sock);
2806
2807 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808 wpa_driver_nl80211_probe_req_report(bss, 0);
2809 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002810 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2811 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002812 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2813 "interface %s from bridge %s: %s",
2814 bss->ifname, bss->brname, strerror(errno));
2815 }
Hai Shalomc9e41a12018-07-31 14:41:42 -07002816
2817 if (drv->rtnl_sk)
Hai Shalomfdcde762020-04-02 11:19:20 -07002818 nl_socket_free(drv->rtnl_sk);
Hai Shalomc9e41a12018-07-31 14:41:42 -07002819
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002821 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2822 0) < 0)
2823 wpa_printf(MSG_INFO,
2824 "nl80211: Could not set bridge %s down",
2825 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002826 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002827 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2828 "bridge %s: %s",
2829 bss->brname, strerror(errno));
2830 }
2831
2832 nl80211_remove_monitor_interface(drv);
2833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002834 if (is_ap_interface(drv->nlmode))
Paul Stewart092955c2017-02-06 09:13:09 -08002835 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 if (drv->eapol_sock >= 0) {
2838 eloop_unregister_read_sock(drv->eapol_sock);
2839 close(drv->eapol_sock);
2840 }
2841
2842 if (drv->if_indices != drv->default_if_indices)
2843 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002845 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002846 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2847
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002848 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2849 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002850 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851 rfkill_deinit(drv->rfkill);
2852
2853 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2854
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002855 if (!drv->start_iface_up)
2856 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002857
2858 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002859 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2860 0) < 0) {
2861 wpa_printf(MSG_DEBUG,
2862 "nl80211: Could not set interface down to restore permanent MAC address");
2863 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002864 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2865 drv->perm_addr) < 0) {
2866 wpa_printf(MSG_DEBUG,
2867 "nl80211: Could not restore permanent MAC address");
2868 }
2869 }
2870
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002871 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002872 if (!drv->hostapd || !drv->start_mode_ap)
2873 wpa_driver_nl80211_set_mode(bss,
2874 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002875 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002876 } else {
2877 nl80211_mgmt_unsubscribe(bss, "deinit");
2878 nl80211_del_p2pdev(bss);
2879 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002880
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002881 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002882
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002883 os_free(drv->filter_ssids);
2884
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002885 os_free(drv->auth_ie);
2886
2887 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002888 dl_list_del(&drv->list);
2889
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002890 os_free(drv->extended_capa);
2891 os_free(drv->extended_capa_mask);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002892 for (i = 0; i < drv->num_iface_ext_capa; i++) {
2893 os_free(drv->iface_ext_capa[i].ext_capa);
2894 os_free(drv->iface_ext_capa[i].ext_capa_mask);
2895 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002896 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002897 os_free(drv);
2898}
2899
2900
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002901static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2902{
2903 switch (alg) {
2904 case WPA_ALG_WEP:
2905 if (key_len == 5)
Paul Stewart092955c2017-02-06 09:13:09 -08002906 return RSN_CIPHER_SUITE_WEP40;
2907 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002908 case WPA_ALG_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002909 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002910 case WPA_ALG_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002911 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002912 case WPA_ALG_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002913 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002914 case WPA_ALG_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002915 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002916 case WPA_ALG_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002917 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002918 case WPA_ALG_IGTK:
Paul Stewart092955c2017-02-06 09:13:09 -08002919 return RSN_CIPHER_SUITE_AES_128_CMAC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002920 case WPA_ALG_BIP_GMAC_128:
Paul Stewart092955c2017-02-06 09:13:09 -08002921 return RSN_CIPHER_SUITE_BIP_GMAC_128;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002922 case WPA_ALG_BIP_GMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002923 return RSN_CIPHER_SUITE_BIP_GMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002924 case WPA_ALG_BIP_CMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002925 return RSN_CIPHER_SUITE_BIP_CMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002926 case WPA_ALG_SMS4:
Paul Stewart092955c2017-02-06 09:13:09 -08002927 return RSN_CIPHER_SUITE_SMS4;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002928 case WPA_ALG_KRK:
Paul Stewart092955c2017-02-06 09:13:09 -08002929 return RSN_CIPHER_SUITE_KRK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002930 case WPA_ALG_NONE:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002931 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2932 alg);
2933 return 0;
2934 }
2935
2936 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2937 alg);
2938 return 0;
2939}
2940
2941
2942static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2943{
2944 switch (cipher) {
2945 case WPA_CIPHER_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002946 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002947 case WPA_CIPHER_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08002948 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002949 case WPA_CIPHER_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002950 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002951 case WPA_CIPHER_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08002952 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002953 case WPA_CIPHER_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08002954 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002955 case WPA_CIPHER_WEP104:
Paul Stewart092955c2017-02-06 09:13:09 -08002956 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002957 case WPA_CIPHER_WEP40:
Paul Stewart092955c2017-02-06 09:13:09 -08002958 return RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002959 case WPA_CIPHER_GTK_NOT_USED:
Paul Stewart092955c2017-02-06 09:13:09 -08002960 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002961 }
2962
2963 return 0;
2964}
2965
2966
2967static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2968 int max_suites)
2969{
2970 int num_suites = 0;
2971
2972 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002973 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002974 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08002975 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002976 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002977 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002978 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08002979 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002980 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
Paul Stewart092955c2017-02-06 09:13:09 -08002981 suites[num_suites++] = RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002982 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
Paul Stewart092955c2017-02-06 09:13:09 -08002983 suites[num_suites++] = RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002984 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
Paul Stewart092955c2017-02-06 09:13:09 -08002985 suites[num_suites++] = RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002986
2987 return num_suites;
2988}
2989
2990
Hai Shalomfdcde762020-04-02 11:19:20 -07002991static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[],
2992 int max_suites)
2993{
2994 int num_suites = 0;
2995
2996#define __AKM(a, b) \
2997 if (num_suites < max_suites && \
2998 (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \
2999 suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b)
3000 __AKM(IEEE8021X, UNSPEC_802_1X);
3001 __AKM(PSK, PSK_OVER_802_1X);
3002 __AKM(FT_IEEE8021X, FT_802_1X);
3003 __AKM(FT_PSK, FT_PSK);
3004 __AKM(IEEE8021X_SHA256, 802_1X_SHA256);
3005 __AKM(PSK_SHA256, PSK_SHA256);
3006 __AKM(SAE, SAE);
3007 __AKM(FT_SAE, FT_SAE);
3008 __AKM(CCKM, CCKM);
3009 __AKM(OSEN, OSEN);
3010 __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B);
3011 __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192);
3012 __AKM(FILS_SHA256, FILS_SHA256);
3013 __AKM(FILS_SHA384, FILS_SHA384);
3014 __AKM(FT_FILS_SHA256, FT_FILS_SHA256);
3015 __AKM(FT_FILS_SHA384, FT_FILS_SHA384);
3016 __AKM(OWE, OWE);
3017 __AKM(DPP, DPP);
3018 __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384);
3019#undef __AKM
3020
3021 return num_suites;
3022}
3023
3024
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003025#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003026static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
3027 const u8 *key, size_t key_len)
3028{
3029 struct nl_msg *msg;
3030 int ret;
3031
3032 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
3033 return 0;
3034
3035 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
3036 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3037 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3038 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
3039 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
3040 nl80211_nlmsg_clear(msg);
3041 nlmsg_free(msg);
3042 return -1;
3043 }
3044 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
3045 if (ret) {
3046 wpa_printf(MSG_DEBUG,
3047 "nl80211: Key management set key failed: ret=%d (%s)",
3048 ret, strerror(-ret));
3049 }
3050
3051 return ret;
3052}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003053#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003054
3055
Roshan Pius3a1667e2018-07-03 15:17:14 -07003056static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv,
3057 const u8 *key, size_t key_len,
3058 const u8 *addr)
3059{
3060 struct nl_msg *msg = NULL;
3061 int ret;
3062
3063 /*
3064 * If the authenticator address is not set, assume it is
3065 * the current BSSID.
3066 */
3067 if (!addr && drv->associated)
3068 addr = drv->bssid;
3069 else if (!addr)
3070 return -1;
3071
3072 wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR,
3073 MAC2STR(addr));
3074 wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len);
3075 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK);
3076 if (!msg ||
3077 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3078 nla_put(msg, NL80211_ATTR_PMK, key_len, key)) {
3079 nl80211_nlmsg_clear(msg);
3080 nlmsg_free(msg);
3081 return -ENOBUFS;
3082 }
3083
3084 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
3085 if (ret) {
3086 wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)",
3087 ret, strerror(-ret));
3088 }
3089
3090 return ret;
3091}
3092
3093
Hai Shalomfdcde762020-04-02 11:19:20 -07003094static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
3095 struct wpa_driver_set_key_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003097 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003098 int ifindex;
Hai Shalomc3565922019-10-28 11:58:20 -07003099 struct nl_msg *msg;
3100 struct nl_msg *key_msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07003102 int skip_set_key = 1;
3103 const char *ifname = params->ifname;
3104 enum wpa_alg alg = params->alg;
3105 const u8 *addr = params->addr;
3106 int key_idx = params->key_idx;
3107 int set_tx = params->set_tx;
3108 const u8 *seq = params->seq;
3109 size_t seq_len = params->seq_len;
3110 const u8 *key = params->key;
3111 size_t key_len = params->key_len;
3112 int vlan_id = params->vlan_id;
3113 enum key_flag key_flag = params->key_flag;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003114
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003115 /* Ignore for P2P Device */
3116 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
3117 return 0;
3118
3119 ifindex = if_nametoindex(ifname);
3120 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Hai Shalomfdcde762020-04-02 11:19:20 -07003121 "set_tx=%d seq_len=%lu key_len=%lu key_flag=0x%x",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003122 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Hai Shalomfdcde762020-04-02 11:19:20 -07003123 (unsigned long) seq_len, (unsigned long) key_len, key_flag);
3124
3125 if (check_key_flag(key_flag)) {
3126 wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__);
3127 return -EINVAL;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003128 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003130#ifdef CONFIG_DRIVER_NL80211_QCA
Hai Shalomfdcde762020-04-02 11:19:20 -07003131 if ((key_flag & KEY_FLAG_PMK) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003132 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
3133 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
3134 __func__);
3135 ret = issue_key_mgmt_set_key(drv, key, key_len);
3136 return ret;
3137 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003138#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139
Hai Shalomfdcde762020-04-02 11:19:20 -07003140 if (key_flag & KEY_FLAG_PMK) {
3141 if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)
3142 return nl80211_set_pmk(drv, key, key_len, addr);
3143 /* The driver does not have any offload mechanism for PMK, so
3144 * there is no need to configure this key. */
3145 return 0;
3146 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003147
Hai Shalomfdcde762020-04-02 11:19:20 -07003148 ret = -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07003149 key_msg = nlmsg_alloc();
3150 if (!key_msg)
Hai Shalomfdcde762020-04-02 11:19:20 -07003151 return ret;
Hai Shalomc3565922019-10-28 11:58:20 -07003152
Hai Shalomfdcde762020-04-02 11:19:20 -07003153 if ((key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3154 KEY_FLAG_PAIRWISE_RX_TX_MODIFY) {
3155 wpa_printf(MSG_DEBUG,
3156 "nl80211: SET_KEY (pairwise RX/TX modify)");
3157 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
3158 if (!msg)
3159 goto fail2;
3160 } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) {
3161 wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key",
3162 __func__);
3163 ret = -EINVAL;
3164 goto fail2;
3165 } else if (alg == WPA_ALG_NONE) {
3166 wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003167 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
3168 if (!msg)
Hai Shalomc3565922019-10-28 11:58:20 -07003169 goto fail2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003170 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003171 u32 suite;
3172
3173 suite = wpa_alg_to_cipher_suite(alg, key_len);
Hai Shalomfdcde762020-04-02 11:19:20 -07003174 if (!suite) {
3175 ret = -EINVAL;
Hai Shalomc3565922019-10-28 11:58:20 -07003176 goto fail2;
Hai Shalomfdcde762020-04-02 11:19:20 -07003177 }
3178 wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003179 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003180 if (!msg)
3181 goto fail2;
3182 if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) ||
3183 nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003184 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003185 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003186
Hai Shalomfdcde762020-04-02 11:19:20 -07003187 if (seq && seq_len) {
3188 if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq))
3189 goto fail;
3190 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ",
3191 seq, seq_len);
3192 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07003193 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194
3195 if (addr && !is_broadcast_ether_addr(addr)) {
3196 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003197 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
3198 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199
Hai Shalomfdcde762020-04-02 11:19:20 -07003200 if ((key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3201 KEY_FLAG_PAIRWISE_RX ||
3202 (key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3203 KEY_FLAG_PAIRWISE_RX_TX_MODIFY) {
3204 if (nla_put_u8(key_msg, NL80211_KEY_MODE,
3205 key_flag == KEY_FLAG_PAIRWISE_RX ?
3206 NL80211_KEY_NO_TX : NL80211_KEY_SET_TX))
3207 goto fail;
3208 } else if ((key_flag & KEY_FLAG_GROUP_MASK) ==
3209 KEY_FLAG_GROUP_RX) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Hai Shalomc3565922019-10-28 11:58:20 -07003211 if (nla_put_u32(key_msg, NL80211_KEY_TYPE,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003212 NL80211_KEYTYPE_GROUP))
3213 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07003214 } else if (!(key_flag & KEY_FLAG_PAIRWISE)) {
3215 wpa_printf(MSG_DEBUG,
3216 " key_flag missing PAIRWISE when setting a pairwise key");
3217 ret = -EINVAL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003218 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07003219 } else if (alg == WPA_ALG_WEP &&
3220 (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) {
3221 wpa_printf(MSG_DEBUG, " unicast WEP key");
3222 skip_set_key = 0;
3223 } else {
3224 wpa_printf(MSG_DEBUG, " pairwise key");
3225 }
3226 } else if ((key_flag & KEY_FLAG_PAIRWISE) ||
3227 !(key_flag & KEY_FLAG_GROUP)) {
3228 wpa_printf(MSG_DEBUG,
3229 " invalid key_flag for a broadcast key");
3230 ret = -EINVAL;
3231 goto fail;
3232 } else {
3233 wpa_printf(MSG_DEBUG, " broadcast key");
3234 if (key_flag & KEY_FLAG_DEFAULT)
3235 skip_set_key = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003236 }
Hai Shalomc3565922019-10-28 11:58:20 -07003237 if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
3238 nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003239 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003240 nl80211_nlmsg_clear(key_msg);
3241 nlmsg_free(key_msg);
3242 key_msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003243
Hai Shalomfdcde762020-04-02 11:19:20 -07003244 if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
3245 wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id);
3246 if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id))
3247 goto fail;
3248 }
3249
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003250 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003251 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
3252 ret = 0;
3253 if (ret)
Hai Shalomfdcde762020-04-02 11:19:20 -07003254 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003255 ret, strerror(-ret));
3256
3257 /*
Hai Shalomfdcde762020-04-02 11:19:20 -07003258 * If we failed or don't need to set the key as default (below),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003259 * we're done here.
3260 */
Hai Shalomfdcde762020-04-02 11:19:20 -07003261 if (ret || skip_set_key)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003262 return ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07003263 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003264
Hai Shalomfdcde762020-04-02 11:19:20 -07003265 ret = -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07003266 key_msg = nlmsg_alloc();
3267 if (!key_msg)
Hai Shalomfdcde762020-04-02 11:19:20 -07003268 return ret;
Hai Shalomc3565922019-10-28 11:58:20 -07003269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003270 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003271 if (!msg)
3272 goto fail2;
3273 if (!key_msg ||
3274 nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
3275 nla_put_flag(key_msg, (alg == WPA_ALG_IGTK ||
3276 alg == WPA_ALG_BIP_GMAC_128 ||
3277 alg == WPA_ALG_BIP_GMAC_256 ||
3278 alg == WPA_ALG_BIP_CMAC_256) ?
Hai Shalomfdcde762020-04-02 11:19:20 -07003279 (key_idx == 6 || key_idx == 7 ?
3280 NL80211_KEY_DEFAULT_BEACON :
3281 NL80211_KEY_DEFAULT_MGMT) :
3282 NL80211_KEY_DEFAULT))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003283 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003284 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003285 struct nlattr *types;
3286
Hai Shalomc3565922019-10-28 11:58:20 -07003287 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003288 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003289 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003290 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003291 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003292 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003293 struct nlattr *types;
3294
Hai Shalomc3565922019-10-28 11:58:20 -07003295 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003296 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003297 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003298 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003299 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003300 }
3301
Hai Shalomc3565922019-10-28 11:58:20 -07003302 if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
3303 goto fail;
3304 nl80211_nlmsg_clear(key_msg);
3305 nlmsg_free(key_msg);
3306 key_msg = NULL;
3307
Hai Shalomfdcde762020-04-02 11:19:20 -07003308 if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
3309 wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d",
3310 vlan_id);
3311 if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id))
3312 goto fail;
3313 }
3314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003315 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003316 if (ret)
Hai Shalomfdcde762020-04-02 11:19:20 -07003317 wpa_printf(MSG_DEBUG,
3318 "nl80211: set_key default failed; err=%d %s",
3319 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003320 return ret;
3321
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003322fail:
3323 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003324 nlmsg_free(msg);
Hai Shalomc3565922019-10-28 11:58:20 -07003325fail2:
3326 nl80211_nlmsg_clear(key_msg);
3327 nlmsg_free(key_msg);
Hai Shalomfdcde762020-04-02 11:19:20 -07003328 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329}
3330
3331
3332static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
3333 int key_idx, int defkey,
3334 const u8 *seq, size_t seq_len,
3335 const u8 *key, size_t key_len)
3336{
3337 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003338 u32 suite;
3339
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003340 if (!key_attr)
3341 return -1;
3342
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003343 suite = wpa_alg_to_cipher_suite(alg, key_len);
3344 if (!suite)
3345 return -1;
3346
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003347 if (defkey && alg == WPA_ALG_IGTK) {
3348 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
3349 return -1;
3350 } else if (defkey) {
3351 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
3352 return -1;
3353 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003355 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003356 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003357 (seq && seq_len &&
3358 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
3359 nla_put(msg, NL80211_KEY_DATA, key_len, key))
3360 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003361
3362 nla_nest_end(msg, key_attr);
3363
3364 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003365}
3366
3367
3368static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
3369 struct nl_msg *msg)
3370{
3371 int i, privacy = 0;
3372 struct nlattr *nl_keys, *nl_key;
3373
3374 for (i = 0; i < 4; i++) {
3375 if (!params->wep_key[i])
3376 continue;
3377 privacy = 1;
3378 break;
3379 }
3380 if (params->wps == WPS_MODE_PRIVACY)
3381 privacy = 1;
3382 if (params->pairwise_suite &&
3383 params->pairwise_suite != WPA_CIPHER_NONE)
3384 privacy = 1;
3385
3386 if (!privacy)
3387 return 0;
3388
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003389 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3390 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003391
3392 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
3393 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003394 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003395
3396 for (i = 0; i < 4; i++) {
3397 if (!params->wep_key[i])
3398 continue;
3399
3400 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003401 if (!nl_key ||
3402 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
3403 params->wep_key[i]) ||
3404 nla_put_u32(msg, NL80211_KEY_CIPHER,
3405 params->wep_key_len[i] == 5 ?
Paul Stewart092955c2017-02-06 09:13:09 -08003406 RSN_CIPHER_SUITE_WEP40 :
3407 RSN_CIPHER_SUITE_WEP104) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003408 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
3409 (i == params->wep_tx_keyidx &&
3410 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
3411 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003412
3413 nla_nest_end(msg, nl_key);
3414 }
3415 nla_nest_end(msg, nl_keys);
3416
3417 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003418}
3419
3420
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003421int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
3422 const u8 *addr, int cmd, u16 reason_code,
Hai Shalom74f70d42019-02-11 14:42:39 -08003423 int local_state_change,
Hai Shalomfdcde762020-04-02 11:19:20 -07003424 struct nl_sock *nl_connect)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003425{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003426 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003427 struct nl_msg *msg;
3428
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003429 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
3430 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
3431 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
3432 (local_state_change &&
3433 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
3434 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003435 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003436 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003437
Hai Shalom74f70d42019-02-11 14:42:39 -08003438 if (nl_connect)
3439 ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL);
3440 else
3441 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003442 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003443 wpa_dbg(drv->ctx, MSG_DEBUG,
3444 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3445 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003446 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003447 return ret;
3448}
3449
3450
3451static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Hai Shalom81f62d82019-07-22 12:10:00 -07003452 u16 reason_code,
Hai Shalomfdcde762020-04-02 11:19:20 -07003453 struct nl_sock *nl_connect)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003454{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003455 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003456 int drv_associated = drv->associated;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003457
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003458 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003459 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003460 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003461 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
Hai Shalom74f70d42019-02-11 14:42:39 -08003462 reason_code, 0, nl_connect);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003463 /*
3464 * For locally generated disconnect, supplicant already generates a
3465 * DEAUTH event, so ignore the event from NL80211.
3466 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003467 drv->ignore_next_local_disconnect = drv_associated && (ret == 0);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003468
3469 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003470}
3471
3472
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003473static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
Hai Shalom81f62d82019-07-22 12:10:00 -07003474 const u8 *addr, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003475{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003476 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003477 int ret;
Hai Shalomce48b4a2018-09-05 11:41:35 -07003478 int drv_associated = drv->associated;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003479
3480 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
3481 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003482 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003483 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003484 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003485 return wpa_driver_nl80211_disconnect(drv, reason_code,
Hai Shalomb755a2a2020-04-23 21:49:02 -07003486 get_connect_handle(bss));
Hai Shalom74f70d42019-02-11 14:42:39 -08003487 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
3489 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003490 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003491 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
Hai Shalomb755a2a2020-04-23 21:49:02 -07003492 reason_code, 0, get_connect_handle(bss));
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003493 /*
3494 * For locally generated deauthenticate, supplicant already generates a
3495 * DEAUTH event, so ignore the event from NL80211.
3496 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003497 drv->ignore_next_local_deauth = drv_associated && (ret == 0);
3498
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003499 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003500}
3501
3502
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003503static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
3504 struct wpa_driver_auth_params *params)
3505{
3506 int i;
3507
3508 drv->auth_freq = params->freq;
3509 drv->auth_alg = params->auth_alg;
3510 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
3511 drv->auth_local_state_change = params->local_state_change;
3512 drv->auth_p2p = params->p2p;
3513
3514 if (params->bssid)
3515 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
3516 else
3517 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
3518
3519 if (params->ssid) {
3520 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
3521 drv->auth_ssid_len = params->ssid_len;
3522 } else
3523 drv->auth_ssid_len = 0;
3524
3525
3526 os_free(drv->auth_ie);
3527 drv->auth_ie = NULL;
3528 drv->auth_ie_len = 0;
3529 if (params->ie) {
3530 drv->auth_ie = os_malloc(params->ie_len);
3531 if (drv->auth_ie) {
3532 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
3533 drv->auth_ie_len = params->ie_len;
3534 }
3535 }
3536
3537 for (i = 0; i < 4; i++) {
3538 if (params->wep_key[i] && params->wep_key_len[i] &&
3539 params->wep_key_len[i] <= 16) {
3540 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
3541 params->wep_key_len[i]);
3542 drv->auth_wep_key_len[i] = params->wep_key_len[i];
3543 } else
3544 drv->auth_wep_key_len[i] = 0;
3545 }
3546}
3547
3548
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003549static void nl80211_unmask_11b_rates(struct i802_bss *bss)
3550{
3551 struct wpa_driver_nl80211_data *drv = bss->drv;
3552
3553 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
3554 return;
3555
3556 /*
3557 * Looks like we failed to unmask 11b rates previously. This could
3558 * happen, e.g., if the interface was down at the point in time when a
3559 * P2P group was terminated.
3560 */
3561 wpa_printf(MSG_DEBUG,
3562 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3563 bss->ifname);
3564 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
3565}
3566
3567
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003568static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg)
3569{
3570 if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
3571 return NL80211_AUTHTYPE_OPEN_SYSTEM;
3572 if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
3573 return NL80211_AUTHTYPE_SHARED_KEY;
3574 if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
3575 return NL80211_AUTHTYPE_NETWORK_EAP;
3576 if (wpa_auth_alg & WPA_AUTH_ALG_FT)
3577 return NL80211_AUTHTYPE_FT;
3578 if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
3579 return NL80211_AUTHTYPE_SAE;
3580 if (wpa_auth_alg & WPA_AUTH_ALG_FILS)
3581 return NL80211_AUTHTYPE_FILS_SK;
3582 if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS)
3583 return NL80211_AUTHTYPE_FILS_SK_PFS;
3584
3585 return NL80211_AUTHTYPE_MAX;
3586}
3587
3588
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003589static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003590 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003592 struct wpa_driver_nl80211_data *drv = bss->drv;
3593 int ret = -1, i;
3594 struct nl_msg *msg;
3595 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003596 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003598 int is_retry;
Hai Shalomfdcde762020-04-02 11:19:20 -07003599 struct wpa_driver_set_key_params p;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003600
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003601 nl80211_unmask_11b_rates(bss);
3602
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003603 is_retry = drv->retry_auth;
3604 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003605 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003606
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003607 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003608 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003609 if (params->bssid)
3610 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
3611 else
3612 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003613 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003614 nlmode = params->p2p ?
3615 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
3616 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003617 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003618 return -1;
3619
3620retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003621 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
3622 drv->ifindex);
3623
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003624 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
3625 if (!msg)
3626 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003627
Hai Shalomfdcde762020-04-02 11:19:20 -07003628 os_memset(&p, 0, sizeof(p));
3629 p.ifname = bss->ifname;
3630 p.alg = WPA_ALG_WEP;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 for (i = 0; i < 4; i++) {
3632 if (!params->wep_key[i])
3633 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07003634 p.key_idx = i;
3635 p.set_tx = i == params->wep_tx_keyidx;
3636 p.key = params->wep_key[i];
3637 p.key_len = params->wep_key_len[i];
3638 p.key_flag = i == params->wep_tx_keyidx ?
3639 KEY_FLAG_GROUP_RX_TX_DEFAULT :
3640 KEY_FLAG_GROUP_RX_TX;
3641 wpa_driver_nl80211_set_key(bss, &p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003642 if (params->wep_tx_keyidx != i)
3643 continue;
3644 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003645 params->wep_key[i], params->wep_key_len[i]))
3646 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003647 }
3648
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649 if (params->bssid) {
3650 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
3651 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003652 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
3653 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003654 }
3655 if (params->freq) {
3656 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003657 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
3658 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003659 }
3660 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003661 wpa_printf(MSG_DEBUG, " * SSID=%s",
3662 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003663 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
3664 params->ssid))
3665 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003666 }
3667 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003668 if (params->ie &&
3669 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
3670 goto fail;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003671 if (params->auth_data) {
3672 wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data,
3673 params->auth_data_len);
3674 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len,
3675 params->auth_data))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003676 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003677 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003678 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003679 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003680 if (type == NL80211_AUTHTYPE_MAX ||
3681 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003682 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003683 if (params->local_state_change) {
3684 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003685 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
3686 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003687 }
3688
3689 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3690 msg = NULL;
3691 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003692 wpa_dbg(drv->ctx, MSG_DEBUG,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003693 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
3694 count, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003695 count++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003696 if ((ret == -EALREADY || ret == -EEXIST) && count == 1 &&
3697 params->bssid && !params->local_state_change) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003698 /*
3699 * mac80211 does not currently accept new
3700 * authentication if we are already authenticated. As a
3701 * workaround, force deauthentication and try again.
3702 */
3703 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
3704 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07003705 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003706 wpa_driver_nl80211_deauthenticate(
3707 bss, params->bssid,
3708 WLAN_REASON_PREV_AUTH_NOT_VALID);
3709 nlmsg_free(msg);
3710 goto retry;
3711 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003712
3713 if (ret == -ENOENT && params->freq && !is_retry) {
3714 /*
3715 * cfg80211 has likely expired the BSS entry even
3716 * though it was previously available in our internal
3717 * BSS table. To recover quickly, start a single
3718 * channel scan on the specified channel.
3719 */
3720 struct wpa_driver_scan_params scan;
3721 int freqs[2];
3722
3723 os_memset(&scan, 0, sizeof(scan));
3724 scan.num_ssids = 1;
3725 if (params->ssid) {
3726 scan.ssids[0].ssid = params->ssid;
3727 scan.ssids[0].ssid_len = params->ssid_len;
3728 }
3729 freqs[0] = params->freq;
3730 freqs[1] = 0;
3731 scan.freqs = freqs;
3732 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3733 "channel scan to refresh cfg80211 BSS "
3734 "entry");
3735 ret = wpa_driver_nl80211_scan(bss, &scan);
3736 if (ret == 0) {
3737 nl80211_copy_auth_params(drv, params);
3738 drv->scan_for_auth = 1;
3739 }
3740 } else if (is_retry) {
3741 /*
3742 * Need to indicate this with an event since the return
3743 * value from the retry is not delivered to core code.
3744 */
3745 union wpa_event_data event;
3746 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3747 "failed");
3748 os_memset(&event, 0, sizeof(event));
3749 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3750 ETH_ALEN);
3751 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3752 &event);
3753 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003754 } else {
3755 wpa_printf(MSG_DEBUG,
3756 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003757 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003758
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003759fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003760 nlmsg_free(msg);
3761 return ret;
3762}
3763
3764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003765int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003766{
3767 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003768 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003769 int i;
3770
3771 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3772
3773 os_memset(&params, 0, sizeof(params));
3774 params.freq = drv->auth_freq;
3775 params.auth_alg = drv->auth_alg;
3776 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3777 params.local_state_change = drv->auth_local_state_change;
3778 params.p2p = drv->auth_p2p;
3779
3780 if (!is_zero_ether_addr(drv->auth_bssid_))
3781 params.bssid = drv->auth_bssid_;
3782
3783 if (drv->auth_ssid_len) {
3784 params.ssid = drv->auth_ssid;
3785 params.ssid_len = drv->auth_ssid_len;
3786 }
3787
3788 params.ie = drv->auth_ie;
3789 params.ie_len = drv->auth_ie_len;
3790
3791 for (i = 0; i < 4; i++) {
3792 if (drv->auth_wep_key_len[i]) {
3793 params.wep_key[i] = drv->auth_wep_key[i];
3794 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3795 }
3796 }
3797
3798 drv->retry_auth = 1;
3799 return wpa_driver_nl80211_authenticate(bss, &params);
3800}
3801
3802
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003803static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3804 size_t data_len, int noack,
3805 unsigned int freq, int no_cck,
3806 int offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003807 unsigned int wait_time,
3808 const u16 *csa_offs,
Hai Shalomfdcde762020-04-02 11:19:20 -07003809 size_t csa_offs_len, int no_encrypt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003810{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003811 struct wpa_driver_nl80211_data *drv = bss->drv;
3812 struct ieee80211_mgmt *mgmt;
Hai Shalomfdcde762020-04-02 11:19:20 -07003813 int encrypt = !no_encrypt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003814 u16 fc;
Hai Shalomfdcde762020-04-02 11:19:20 -07003815 int use_cookie = 1;
3816 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817
3818 mgmt = (struct ieee80211_mgmt *) data;
3819 fc = le_to_host16(mgmt->frame_control);
Hai Shalomfdcde762020-04-02 11:19:20 -07003820 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR
3821 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d",
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003822 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
Hai Shalomfdcde762020-04-02 11:19:20 -07003823 no_encrypt, fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003824
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003825 if ((is_sta_interface(drv->nlmode) ||
3826 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003827 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3828 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3829 /*
3830 * The use of last_mgmt_freq is a bit of a hack,
3831 * but it works due to the single-threaded nature
3832 * of wpa_supplicant.
3833 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003834 if (freq == 0) {
3835 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3836 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003837 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003838 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003839 wait_time = 0;
3840 use_cookie = 0;
3841 no_cck = 1;
3842 offchanok = 1;
3843 goto send_frame_cmd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003844 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003845
3846 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003847 if (freq == 0) {
3848 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3849 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003850 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003851 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003852 if ((int) freq == bss->freq)
3853 wait_time = 0;
3854 goto send_frame_cmd;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003855 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003857 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3858 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3859 /*
3860 * Only one of the authentication frame types is encrypted.
3861 * In order for static WEP encryption to work properly (i.e.,
3862 * to not encrypt the frame), we need to tell mac80211 about
3863 * the frames that must not be encrypted.
3864 */
3865 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3866 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3867 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3868 encrypt = 0;
3869 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003870
Hai Shalomfdcde762020-04-02 11:19:20 -07003871 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_STATION &&
3872 (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
3873 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME) &&
3874 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3875 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3876 freq = nl80211_get_assoc_freq(drv);
3877 wpa_printf(MSG_DEBUG,
3878 "nl80211: send_mlme - Use assoc_freq=%u for external auth",
3879 freq);
3880 }
3881
3882 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3883 freq = nl80211_get_assoc_freq(drv);
3884 wpa_printf(MSG_DEBUG,
3885 "nl80211: send_mlme - Use assoc_freq=%u for IBSS",
3886 freq);
3887 }
3888 if (freq == 0) {
3889 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u",
3890 bss->freq);
3891 freq = bss->freq;
3892 }
3893
3894 if (drv->use_monitor) {
3895 wpa_printf(MSG_DEBUG,
3896 "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3897 freq, bss->freq);
3898 return nl80211_send_monitor(drv, data, data_len, encrypt,
3899 noack);
3900 }
3901
3902 if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
3903 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
3904 use_cookie = 0;
3905send_frame_cmd:
3906#ifdef CONFIG_TESTING_OPTIONS
3907 if (no_encrypt && !encrypt && !drv->use_monitor) {
3908 wpa_printf(MSG_DEBUG,
3909 "nl80211: Request to send an unencrypted frame - use a monitor interface for this");
3910 if (nl80211_create_monitor_interface(drv) < 0)
3911 return -1;
3912 res = nl80211_send_monitor(drv, data, data_len, encrypt,
3913 noack);
3914 nl80211_remove_monitor_interface(drv);
3915 return res;
3916 }
3917#endif /* CONFIG_TESTING_OPTIONS */
3918
3919 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd");
3920 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len,
3921 use_cookie, no_cck, noack, offchanok,
3922 csa_offs, csa_offs_len);
3923
3924 return res;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003925}
3926
3927
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003928static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3929{
3930 u8 rates[NL80211_MAX_SUPP_RATES];
3931 u8 rates_len = 0;
3932 int i;
3933
3934 if (!basic_rates)
3935 return 0;
3936
3937 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3938 rates[rates_len++] = basic_rates[i] / 5;
3939
3940 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3941}
3942
3943
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003944static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3945 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003946 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003947{
3948 struct wpa_driver_nl80211_data *drv = bss->drv;
3949 struct nl_msg *msg;
3950
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003951 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3952 (cts >= 0 &&
3953 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3954 (preamble >= 0 &&
3955 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3956 (slot >= 0 &&
3957 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3958 (ht_opmode >= 0 &&
3959 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3960 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003961 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3962 nl80211_put_basic_rates(msg, basic_rates)) {
3963 nlmsg_free(msg);
3964 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003965 }
3966
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003967 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003968}
3969
3970
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003971static int wpa_driver_nl80211_set_acl(void *priv,
3972 struct hostapd_acl_params *params)
3973{
3974 struct i802_bss *bss = priv;
3975 struct wpa_driver_nl80211_data *drv = bss->drv;
3976 struct nl_msg *msg;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003977 struct nl_msg *acl;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003978 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003979 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003980
3981 if (!(drv->capa.max_acl_mac_addrs))
3982 return -ENOTSUP;
3983
3984 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3985 return -ENOTSUP;
3986
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003987 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3988 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3989
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003990 acl = nlmsg_alloc();
3991 if (!acl)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003992 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003993 for (i = 0; i < params->num_mac_acl; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003994 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3995 nlmsg_free(acl);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003996 return -ENOMEM;
3997 }
3998 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003999
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004000 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
4001 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
4002 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
4003 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
4004 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
4005 nlmsg_free(msg);
4006 nlmsg_free(acl);
4007 return -ENOMEM;
4008 }
4009 nlmsg_free(acl);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004010
4011 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004012 if (ret) {
4013 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
4014 ret, strerror(-ret));
4015 }
4016
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004017 return ret;
4018}
4019
4020
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004021static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
4022{
4023 if (beacon_int > 0) {
4024 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
4025 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
4026 beacon_int);
4027 }
4028
4029 return 0;
4030}
4031
4032
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004033static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period)
4034{
4035 if (dtim_period > 0) {
4036 wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period);
4037 return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
4038 }
4039
4040 return 0;
4041}
4042
4043
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004044#ifdef CONFIG_MESH
4045static int nl80211_set_mesh_config(void *priv,
4046 struct wpa_driver_mesh_bss_params *params)
4047{
4048 struct i802_bss *bss = priv;
4049 struct wpa_driver_nl80211_data *drv = bss->drv;
4050 struct nl_msg *msg;
4051 int ret;
4052
4053 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG);
4054 if (!msg)
4055 return -1;
4056
4057 ret = nl80211_put_mesh_config(msg, params);
4058 if (ret < 0) {
4059 nlmsg_free(msg);
4060 return ret;
4061 }
4062
4063 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4064 if (ret) {
4065 wpa_printf(MSG_ERROR,
4066 "nl80211: Mesh config set failed: %d (%s)",
4067 ret, strerror(-ret));
4068 return ret;
4069 }
4070 return 0;
4071}
4072#endif /* CONFIG_MESH */
4073
4074
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004075static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags,
4076 struct wpa_driver_ap_params *params)
4077{
4078 struct nlattr *bands, *band;
4079 struct nl80211_txrate_vht vht_rate;
4080
4081 if (!params->freq ||
4082 (params->beacon_rate == 0 &&
4083 params->rate_type == BEACON_RATE_LEGACY))
4084 return 0;
4085
4086 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
4087 if (!bands)
4088 return -1;
4089
4090 switch (params->freq->mode) {
4091 case HOSTAPD_MODE_IEEE80211B:
4092 case HOSTAPD_MODE_IEEE80211G:
4093 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
4094 break;
4095 case HOSTAPD_MODE_IEEE80211A:
4096 band = nla_nest_start(msg, NL80211_BAND_5GHZ);
4097 break;
4098 case HOSTAPD_MODE_IEEE80211AD:
4099 band = nla_nest_start(msg, NL80211_BAND_60GHZ);
4100 break;
4101 default:
4102 return 0;
4103 }
4104
4105 if (!band)
4106 return -1;
4107
4108 os_memset(&vht_rate, 0, sizeof(vht_rate));
4109
4110 switch (params->rate_type) {
4111 case BEACON_RATE_LEGACY:
4112 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) {
4113 wpa_printf(MSG_INFO,
4114 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
4115 return -1;
4116 }
4117
4118 if (nla_put_u8(msg, NL80211_TXRATE_LEGACY,
4119 (u8) params->beacon_rate / 5) ||
4120 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
4121 (params->freq->vht_enabled &&
4122 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4123 &vht_rate)))
4124 return -1;
4125
4126 wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)",
4127 params->beacon_rate);
4128 break;
4129 case BEACON_RATE_HT:
4130 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) {
4131 wpa_printf(MSG_INFO,
4132 "nl80211: Driver does not support setting Beacon frame rate (HT)");
4133 return -1;
4134 }
4135 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
4136 nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) ||
4137 (params->freq->vht_enabled &&
4138 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4139 &vht_rate)))
4140 return -1;
4141 wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u",
4142 params->beacon_rate);
4143 break;
4144 case BEACON_RATE_VHT:
4145 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) {
4146 wpa_printf(MSG_INFO,
4147 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
4148 return -1;
4149 }
4150 vht_rate.mcs[0] = BIT(params->beacon_rate);
4151 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL))
4152 return -1;
4153 if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL))
4154 return -1;
4155 if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4156 &vht_rate))
4157 return -1;
4158 wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u",
4159 params->beacon_rate);
4160 break;
4161 }
4162
4163 nla_nest_end(msg, band);
4164 nla_nest_end(msg, bands);
4165
4166 return 0;
4167}
4168
4169
4170static int nl80211_set_multicast_to_unicast(struct i802_bss *bss,
4171 int multicast_to_unicast)
4172{
4173 struct wpa_driver_nl80211_data *drv = bss->drv;
4174 struct nl_msg *msg;
4175 int ret;
4176
4177 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST);
4178 if (!msg ||
4179 (multicast_to_unicast &&
4180 nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) {
4181 wpa_printf(MSG_ERROR,
4182 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
4183 bss->ifname);
4184 nlmsg_free(msg);
4185 return -ENOBUFS;
4186 }
4187
4188 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4189
4190 switch (ret) {
4191 case 0:
4192 wpa_printf(MSG_DEBUG,
4193 "nl80211: multicast to unicast %s on interface %s",
4194 multicast_to_unicast ? "enabled" : "disabled",
4195 bss->ifname);
4196 break;
4197 case -EOPNOTSUPP:
4198 if (!multicast_to_unicast)
4199 break;
4200 wpa_printf(MSG_INFO,
4201 "nl80211: multicast to unicast not supported on interface %s",
4202 bss->ifname);
4203 break;
4204 default:
4205 wpa_printf(MSG_ERROR,
4206 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
4207 multicast_to_unicast ? "enabling" : "disabling",
4208 ret, strerror(-ret), bss->ifname);
4209 break;
4210 }
4211
4212 return ret;
4213}
4214
4215
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004216static int wpa_driver_nl80211_set_ap(void *priv,
4217 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004218{
4219 struct i802_bss *bss = priv;
4220 struct wpa_driver_nl80211_data *drv = bss->drv;
4221 struct nl_msg *msg;
4222 u8 cmd = NL80211_CMD_NEW_BEACON;
Hai Shalom74f70d42019-02-11 14:42:39 -08004223 int ret = -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004224 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004225 int num_suites;
Hai Shalomfdcde762020-04-02 11:19:20 -07004226 u32 suites[20], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004227 u32 ver;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004228#ifdef CONFIG_MESH
4229 struct wpa_driver_mesh_bss_params mesh_params;
4230#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004231
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004232 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
4235 beacon_set);
4236 if (beacon_set)
4237 cmd = NL80211_CMD_SET_BEACON;
Paul Stewart092955c2017-02-06 09:13:09 -08004238 else if (!drv->device_ap_sme && !drv->use_monitor &&
4239 !nl80211_get_wiphy_data_ap(bss))
4240 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004241
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004242 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
4243 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004244 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
4245 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004246 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004247 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004248 wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate);
4249 wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004250 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Hai Shalom74f70d42019-02-11 14:42:39 -08004251 wpa_printf(MSG_DEBUG, "nl80211: ssid=%s",
4252 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004253 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
4254 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
4255 params->head) ||
4256 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
4257 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004258 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004259 nl80211_put_beacon_rate(msg, drv->capa.flags, params) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004260 nl80211_put_dtim_period(msg, params->dtim_period) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004261 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4262 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004263 if (params->proberesp && params->proberesp_len) {
4264 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
4265 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004266 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
4267 params->proberesp))
4268 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004269 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004270 switch (params->hide_ssid) {
4271 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004272 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004273 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4274 NL80211_HIDDEN_SSID_NOT_IN_USE))
4275 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004276 break;
4277 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004278 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004279 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4280 NL80211_HIDDEN_SSID_ZERO_LEN))
4281 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004282 break;
4283 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004284 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004285 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4286 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
4287 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004288 break;
4289 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004290 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004291 if (params->privacy &&
4292 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
4293 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004294 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004295 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
4296 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
4297 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004298 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
4299 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4300 NL80211_AUTHTYPE_SHARED_KEY))
4301 goto fail;
4302 } else {
4303 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4304 NL80211_AUTHTYPE_OPEN_SYSTEM))
4305 goto fail;
4306 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004307
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004308 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004309 ver = 0;
4310 if (params->wpa_version & WPA_PROTO_WPA)
4311 ver |= NL80211_WPA_VERSION_1;
4312 if (params->wpa_version & WPA_PROTO_RSN)
4313 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004314 if (ver &&
4315 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4316 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004317
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004318 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
4319 params->key_mgmt_suites);
Hai Shalomfdcde762020-04-02 11:19:20 -07004320 num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites,
4321 suites, ARRAY_SIZE(suites));
4322 if (num_suites > NL80211_MAX_NR_AKM_SUITES)
4323 wpa_printf(MSG_WARNING,
4324 "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)",
4325 num_suites);
4326 else if (num_suites &&
4327 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
4328 suites))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004329 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004331 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004332 (!params->pairwise_ciphers ||
4333 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
4334 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
4335 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004336 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004337
Hai Shalom81f62d82019-07-22 12:10:00 -07004338 if (drv->device_ap_sme &&
4339 (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) &&
4340 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
4341 goto fail;
Hai Shalom5f92bc92019-04-18 11:54:11 -07004342
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004343 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
4344 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004345 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
4346 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004347 if (num_suites &&
4348 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4349 num_suites * sizeof(u32), suites))
4350 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004351
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004352 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
4353 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004354 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004355 if (suite &&
4356 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
4357 goto fail;
4358
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004359 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004360 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
4361 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004362 if (nla_put(msg, NL80211_ATTR_IE,
4363 wpabuf_len(params->beacon_ies),
4364 wpabuf_head(params->beacon_ies)))
4365 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004366 }
4367 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004368 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
4369 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004370 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
4371 wpabuf_len(params->proberesp_ies),
4372 wpabuf_head(params->proberesp_ies)))
4373 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004374 }
4375 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004376 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
4377 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004378 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
4379 wpabuf_len(params->assocresp_ies),
4380 wpabuf_head(params->assocresp_ies)))
4381 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004382 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004383
Dmitry Shmidt04949592012-07-19 12:16:46 -07004384 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004385 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
4386 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004387 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
4388 params->ap_max_inactivity))
4389 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004390 }
4391
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004392#ifdef CONFIG_P2P
4393 if (params->p2p_go_ctwindow > 0) {
4394 if (drv->p2p_go_ctwindow_supported) {
4395 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
4396 params->p2p_go_ctwindow);
4397 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
4398 params->p2p_go_ctwindow))
4399 goto fail;
4400 } else {
4401 wpa_printf(MSG_INFO,
4402 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4403 }
4404 }
4405#endif /* CONFIG_P2P */
4406
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004407 if (params->pbss) {
4408 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
4409 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
4410 goto fail;
4411 }
4412
Hai Shalom74f70d42019-02-11 14:42:39 -08004413 if (params->ftm_responder) {
4414 struct nlattr *ftm;
4415
4416 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) {
4417 ret = -ENOTSUP;
4418 goto fail;
4419 }
4420
4421 ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER);
4422 if (!ftm ||
4423 nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) ||
4424 (params->lci &&
4425 nla_put(msg, NL80211_FTM_RESP_ATTR_LCI,
4426 wpabuf_len(params->lci),
4427 wpabuf_head(params->lci))) ||
4428 (params->civic &&
4429 nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC,
4430 wpabuf_len(params->civic),
4431 wpabuf_head(params->civic))))
4432 goto fail;
4433 nla_nest_end(msg, ftm);
4434 }
4435
Hai Shalomc3565922019-10-28 11:58:20 -07004436#ifdef CONFIG_IEEE80211AX
4437 if (params->he_spr) {
4438 struct nlattr *spr;
4439
4440 spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD);
4441 wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr);
4442
Hai Shalomfdcde762020-04-02 11:19:20 -07004443 if (!spr ||
4444 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET,
Hai Shalomc3565922019-10-28 11:58:20 -07004445 params->he_spr_srg_obss_pd_min_offset) ||
4446 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET,
4447 params->he_spr_srg_obss_pd_max_offset))
4448 goto fail;
4449
4450 nla_nest_end(msg, spr);
4451 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004452
4453 if (params->freq && params->freq->he_enabled) {
4454 struct nlattr *bss_color;
4455
4456 bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR);
4457 if (!bss_color ||
4458 (params->he_bss_color_disabled &&
4459 nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) ||
4460 (params->he_bss_color_partial &&
4461 nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) ||
4462 nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR,
4463 params->he_bss_color))
4464 goto fail;
4465 nla_nest_end(msg, bss_color);
4466 }
4467
4468 if (params->twt_responder) {
4469 wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d",
4470 params->twt_responder);
4471 if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER))
4472 goto fail;
4473 }
Hai Shalomc3565922019-10-28 11:58:20 -07004474#endif /* CONFIG_IEEE80211AX */
4475
Hai Shalomb755a2a2020-04-23 21:49:02 -07004476 ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1,
4477 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478 if (ret) {
4479 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
4480 ret, strerror(-ret));
4481 } else {
4482 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004483 nl80211_set_bss(bss, params->cts_protect, params->preamble,
4484 params->short_slot_time, params->ht_opmode,
4485 params->isolate, params->basic_rates);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004486 nl80211_set_multicast_to_unicast(bss,
4487 params->multicast_to_unicast);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004488 if (beacon_set && params->freq &&
4489 params->freq->bandwidth != bss->bandwidth) {
4490 wpa_printf(MSG_DEBUG,
4491 "nl80211: Update BSS %s bandwidth: %d -> %d",
4492 bss->ifname, bss->bandwidth,
4493 params->freq->bandwidth);
4494 ret = nl80211_set_channel(bss, params->freq, 1);
4495 if (ret) {
4496 wpa_printf(MSG_DEBUG,
4497 "nl80211: Frequency set failed: %d (%s)",
4498 ret, strerror(-ret));
4499 } else {
4500 wpa_printf(MSG_DEBUG,
4501 "nl80211: Frequency set succeeded for ht2040 coex");
4502 bss->bandwidth = params->freq->bandwidth;
4503 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004504 } else if (!beacon_set && params->freq) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004505 /*
4506 * cfg80211 updates the driver on frequence change in AP
4507 * mode only at the point when beaconing is started, so
4508 * set the initial value here.
4509 */
4510 bss->bandwidth = params->freq->bandwidth;
4511 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004513
4514#ifdef CONFIG_MESH
4515 if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) {
4516 os_memset(&mesh_params, 0, sizeof(mesh_params));
4517 mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
4518 mesh_params.ht_opmode = params->ht_opmode;
4519 ret = nl80211_set_mesh_config(priv, &mesh_params);
4520 if (ret < 0)
4521 return ret;
4522 }
4523#endif /* CONFIG_MESH */
4524
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004525 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004526fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004527 nlmsg_free(msg);
Hai Shalom74f70d42019-02-11 14:42:39 -08004528 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004529}
4530
4531
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004532static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004533 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004534{
Hai Shalomc3565922019-10-28 11:58:20 -07004535 enum hostapd_hw_mode hw_mode;
4536 int is_24ghz;
4537 u8 channel;
4538
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004539 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
4541 return -ENOBUFS;
4542
Hai Shalom81f62d82019-07-22 12:10:00 -07004543 wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004544 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
4545 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
4546
Hai Shalomc3565922019-10-28 11:58:20 -07004547 hw_mode = ieee80211_freq_to_chan(freq->freq, &channel);
4548 is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G ||
4549 hw_mode == HOSTAPD_MODE_IEEE80211B;
4550
4551 if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004552 enum nl80211_chan_width cw;
4553
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004554 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004555 switch (freq->bandwidth) {
4556 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004557 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004558 break;
4559 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004560 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004561 break;
4562 case 80:
4563 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004564 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004565 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004566 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004567 break;
4568 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004569 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004570 break;
4571 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004572 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004573 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004574
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004575 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
4576 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
4577 freq->center_freq1);
4578 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
4579 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004580 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
4581 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
4582 freq->center_freq1) ||
4583 (freq->center_freq2 &&
4584 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
4585 freq->center_freq2)))
4586 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004587 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004588 enum nl80211_channel_type ct;
4589
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004590 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
4591 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004592 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004593 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004594 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004595 break;
4596 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004597 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004598 break;
4599 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004600 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004601 break;
4602 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004603
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004604 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
4606 return -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07004607 } else if (freq->edmg.channels && freq->edmg.bw_config) {
4608 wpa_printf(MSG_DEBUG,
4609 " * EDMG configuration: channels=0x%x bw_config=%d",
4610 freq->edmg.channels, freq->edmg.bw_config);
4611 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
4612 freq->edmg.channels) ||
4613 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
4614 freq->edmg.bw_config))
4615 return -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004616 } else {
4617 wpa_printf(MSG_DEBUG, " * channel_type=%d",
4618 NL80211_CHAN_NO_HT);
4619 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
4620 NL80211_CHAN_NO_HT))
4621 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004622 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004623 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004624}
4625
4626
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004627static int nl80211_set_channel(struct i802_bss *bss,
4628 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004629{
4630 struct wpa_driver_nl80211_data *drv = bss->drv;
4631 struct nl_msg *msg;
4632 int ret;
4633
4634 wpa_printf(MSG_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07004635 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4636 freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004637 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004638
4639 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
4640 NL80211_CMD_SET_WIPHY);
4641 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
4642 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004643 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004645
4646 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004647 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004648 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004649 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004650 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004651 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004652 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004653 return -1;
4654}
4655
4656
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004657static u32 sta_flags_nl80211(int flags)
4658{
4659 u32 f = 0;
4660
4661 if (flags & WPA_STA_AUTHORIZED)
4662 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
4663 if (flags & WPA_STA_WMM)
4664 f |= BIT(NL80211_STA_FLAG_WME);
4665 if (flags & WPA_STA_SHORT_PREAMBLE)
4666 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
4667 if (flags & WPA_STA_MFP)
4668 f |= BIT(NL80211_STA_FLAG_MFP);
4669 if (flags & WPA_STA_TDLS_PEER)
4670 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004671 if (flags & WPA_STA_AUTHENTICATED)
4672 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004673 if (flags & WPA_STA_ASSOCIATED)
4674 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004675
4676 return f;
4677}
4678
4679
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004680#ifdef CONFIG_MESH
4681static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
4682{
4683 switch (state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004684 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004685 return NL80211_PLINK_LISTEN;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004686 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004687 return NL80211_PLINK_OPN_SNT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004688 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004689 return NL80211_PLINK_OPN_RCVD;
4690 case PLINK_CNF_RCVD:
4691 return NL80211_PLINK_CNF_RCVD;
4692 case PLINK_ESTAB:
4693 return NL80211_PLINK_ESTAB;
4694 case PLINK_HOLDING:
4695 return NL80211_PLINK_HOLDING;
4696 case PLINK_BLOCKED:
4697 return NL80211_PLINK_BLOCKED;
4698 default:
4699 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
4700 state);
4701 }
4702 return -1;
4703}
4704#endif /* CONFIG_MESH */
4705
4706
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004707static int wpa_driver_nl80211_sta_add(void *priv,
4708 struct hostapd_sta_add_params *params)
4709{
4710 struct i802_bss *bss = priv;
4711 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004712 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004713 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 int ret = -ENOBUFS;
4715
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004716 if ((params->flags & WPA_STA_TDLS_PEER) &&
4717 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
4718 return -EOPNOTSUPP;
4719
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004720 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
4721 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004722 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
4723 NL80211_CMD_NEW_STATION);
4724 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
4725 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004727 /*
4728 * Set the below properties only in one of the following cases:
4729 * 1. New station is added, already associated.
4730 * 2. Set WPA_STA_TDLS_PEER station.
4731 * 3. Set an already added unassociated station, if driver supports
4732 * full AP client state. (Set these properties after station became
4733 * associated will be rejected by the driver).
4734 */
4735 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4736 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4737 (params->flags & WPA_STA_ASSOCIATED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004738 wpa_hexdump(MSG_DEBUG, " * supported rates",
4739 params->supp_rates, params->supp_rates_len);
4740 wpa_printf(MSG_DEBUG, " * capability=0x%x",
4741 params->capability);
4742 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
4743 params->supp_rates_len, params->supp_rates) ||
4744 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
4745 params->capability))
4746 goto fail;
4747
4748 if (params->ht_capabilities) {
4749 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
4750 (u8 *) params->ht_capabilities,
4751 sizeof(*params->ht_capabilities));
4752 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
4753 sizeof(*params->ht_capabilities),
4754 params->ht_capabilities))
4755 goto fail;
4756 }
4757
4758 if (params->vht_capabilities) {
4759 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
4760 (u8 *) params->vht_capabilities,
4761 sizeof(*params->vht_capabilities));
4762 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
4763 sizeof(*params->vht_capabilities),
4764 params->vht_capabilities))
4765 goto fail;
4766 }
4767
Hai Shalom81f62d82019-07-22 12:10:00 -07004768 if (params->he_capab) {
4769 wpa_hexdump(MSG_DEBUG, " * he_capab",
4770 params->he_capab, params->he_capab_len);
4771 if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY,
4772 params->he_capab_len, params->he_capab))
4773 goto fail;
4774 }
4775
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004776 if (params->ext_capab) {
4777 wpa_hexdump(MSG_DEBUG, " * ext_capab",
4778 params->ext_capab, params->ext_capab_len);
4779 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
4780 params->ext_capab_len, params->ext_capab))
4781 goto fail;
4782 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004783
4784 if (is_ap_interface(drv->nlmode) &&
4785 nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS,
4786 params->support_p2p_ps ?
4787 NL80211_P2P_PS_SUPPORTED :
4788 NL80211_P2P_PS_UNSUPPORTED))
4789 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004790 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004791 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004792 if (params->aid) {
4793 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004794 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
4795 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004796 } else {
4797 /*
4798 * cfg80211 validates that AID is non-zero, so we have
4799 * to make this a non-zero value for the TDLS case where
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004800 * a dummy STA entry is used for now and for a station
4801 * that is still not associated.
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004802 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004803 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
4804 (params->flags & WPA_STA_TDLS_PEER) ?
4805 "TDLS" : "UNASSOC_STA");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004806 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
4807 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004808 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004809 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4810 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004811 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4812 params->listen_interval))
4813 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004814 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
4815 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004816 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
4817 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004818 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4819 (params->flags & WPA_STA_ASSOCIATED)) {
4820 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
4821 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4822 params->listen_interval);
4823 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
4824 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4825 params->listen_interval))
4826 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004827 }
4828
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004829 if (params->vht_opmode_enabled) {
4830 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004831 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
4832 params->vht_opmode))
4833 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004834 }
4835
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004836 if (params->supp_channels) {
4837 wpa_hexdump(MSG_DEBUG, " * supported channels",
4838 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004839 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
4840 params->supp_channels_len, params->supp_channels))
4841 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004842 }
4843
4844 if (params->supp_oper_classes) {
4845 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
4846 params->supp_oper_classes,
4847 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004848 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
4849 params->supp_oper_classes_len,
4850 params->supp_oper_classes))
4851 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004852 }
4853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004854 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004855 upd.set = sta_flags_nl80211(params->flags);
4856 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004857
4858 /*
4859 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4860 * flags, as nl80211 driver moves a new station, by default, into
4861 * associated state.
4862 *
4863 * On the other hand, if the driver supports that feature and the
4864 * station is added in unauthenticated state, set the
4865 * authenticated/associated bits in the mask to prevent moving this
4866 * station to associated state before it is actually associated.
4867 *
4868 * This is irrelevant for mesh mode where the station is added to the
4869 * driver as authenticated already, and ASSOCIATED isn't part of the
4870 * nl80211 API.
4871 */
4872 if (!is_mesh_interface(drv->nlmode)) {
4873 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
4874 wpa_printf(MSG_DEBUG,
4875 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4876 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
4877 BIT(NL80211_STA_FLAG_AUTHENTICATED));
4878 } else if (!params->set &&
4879 !(params->flags & WPA_STA_TDLS_PEER)) {
4880 if (!(params->flags & WPA_STA_AUTHENTICATED))
4881 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
4882 if (!(params->flags & WPA_STA_ASSOCIATED))
4883 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
4884 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004885#ifdef CONFIG_MESH
4886 } else {
4887 if (params->plink_state == PLINK_ESTAB && params->peer_aid) {
4888 ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID,
4889 params->peer_aid);
4890 if (ret)
4891 goto fail;
4892 }
4893#endif /* CONFIG_MESH */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004894 }
4895
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004896 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
4897 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004898 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4899 goto fail;
4900
4901#ifdef CONFIG_MESH
4902 if (params->plink_state &&
4903 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
4904 sta_plink_state_nl80211(params->plink_state)))
4905 goto fail;
4906#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004907
Hai Shalomc3565922019-10-28 11:58:20 -07004908 if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4909 FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) &&
4910 (params->flags & WPA_STA_WMM)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004911 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
4912
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004913 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004914 if (!wme ||
4915 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
4916 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
4917 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
4918 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
4919 WMM_QOSINFO_STA_SP_MASK))
4920 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004921 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004922 }
4923
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004924 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004925 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004926 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004927 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
4928 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
4929 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004930 if (ret == -EEXIST)
4931 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004932fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004933 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004934 return ret;
4935}
4936
4937
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004938static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
4939{
4940#ifdef CONFIG_LIBNL3_ROUTE
4941 struct wpa_driver_nl80211_data *drv = bss->drv;
4942 struct rtnl_neigh *rn;
4943 struct nl_addr *nl_addr;
4944 int err;
4945
4946 rn = rtnl_neigh_alloc();
4947 if (!rn)
4948 return;
4949
4950 rtnl_neigh_set_family(rn, AF_BRIDGE);
4951 rtnl_neigh_set_ifindex(rn, bss->ifindex);
4952 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
4953 if (!nl_addr) {
4954 rtnl_neigh_put(rn);
4955 return;
4956 }
4957 rtnl_neigh_set_lladdr(rn, nl_addr);
4958
4959 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
4960 if (err < 0) {
4961 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
4962 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
4963 bss->ifindex, nl_geterror(err));
4964 } else {
4965 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
4966 MACSTR, MAC2STR(addr));
4967 }
4968
4969 nl_addr_put(nl_addr);
4970 rtnl_neigh_put(rn);
4971#endif /* CONFIG_LIBNL3_ROUTE */
4972}
4973
4974
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004975static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
4976 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004977{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004978 struct wpa_driver_nl80211_data *drv = bss->drv;
4979 struct nl_msg *msg;
4980 int ret;
4981
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004982 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
4983 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
4984 (deauth == 0 &&
4985 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4986 WLAN_FC_STYPE_DISASSOC)) ||
4987 (deauth == 1 &&
4988 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4989 WLAN_FC_STYPE_DEAUTH)) ||
4990 (reason_code &&
4991 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
4992 nlmsg_free(msg);
4993 return -ENOBUFS;
4994 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004995
4996 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004997 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4998 " --> %d (%s)",
4999 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005000
5001 if (drv->rtnl_sk)
5002 rtnl_neigh_delete_fdb_entry(bss, addr);
5003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005004 if (ret == -ENOENT)
5005 return 0;
5006 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005007}
5008
5009
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005010void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005011{
5012 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005013 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005014
5015 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
5016
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005017 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005018 dl_list_for_each(drv2, &drv->global->interfaces,
5019 struct wpa_driver_nl80211_data, list)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005020 {
5021 del_ifidx(drv2, ifidx, IFIDX_ANY);
5022 /* Remove all bridges learned for this iface */
5023 del_ifidx(drv2, IFIDX_ANY, ifidx);
5024 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005025
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005026 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005027 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5028 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005029 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
5030}
5031
5032
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005033const char * nl80211_iftype_str(enum nl80211_iftype mode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005034{
5035 switch (mode) {
5036 case NL80211_IFTYPE_ADHOC:
5037 return "ADHOC";
5038 case NL80211_IFTYPE_STATION:
5039 return "STATION";
5040 case NL80211_IFTYPE_AP:
5041 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07005042 case NL80211_IFTYPE_AP_VLAN:
5043 return "AP_VLAN";
5044 case NL80211_IFTYPE_WDS:
5045 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005046 case NL80211_IFTYPE_MONITOR:
5047 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07005048 case NL80211_IFTYPE_MESH_POINT:
5049 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005050 case NL80211_IFTYPE_P2P_CLIENT:
5051 return "P2P_CLIENT";
5052 case NL80211_IFTYPE_P2P_GO:
5053 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005054 case NL80211_IFTYPE_P2P_DEVICE:
5055 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005056 default:
5057 return "unknown";
5058 }
5059}
5060
5061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005062static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
5063 const char *ifname,
5064 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005065 const u8 *addr, int wds,
5066 int (*handler)(struct nl_msg *, void *),
5067 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005068{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005069 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005070 int ifidx;
5071 int ret = -ENOBUFS;
5072
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005073 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
5074 iftype, nl80211_iftype_str(iftype));
5075
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005076 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
5077 if (!msg ||
5078 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
5079 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
5080 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005081
5082 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005083 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005084
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005085 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005086 if (!flags ||
5087 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
5088 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005089
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005090 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005091 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005092 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
5093 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094 }
5095
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005096 /*
5097 * Tell cfg80211 that the interface belongs to the socket that created
5098 * it, and the interface should be deleted when the socket is closed.
5099 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005100 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
5101 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005102
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005103 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005104 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005105 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005106 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005107 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005108 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
5109 ifname, ret, strerror(-ret));
5110 return ret;
5111 }
5112
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005113 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
5114 return 0;
5115
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005116 ifidx = if_nametoindex(ifname);
5117 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
5118 ifname, ifidx);
5119
5120 if (ifidx <= 0)
5121 return -1;
5122
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005123 /*
5124 * Some virtual interfaces need to process EAPOL packets and events on
5125 * the parent interface. This is used mainly with hostapd.
5126 */
5127 if (drv->hostapd ||
5128 iftype == NL80211_IFTYPE_AP_VLAN ||
5129 iftype == NL80211_IFTYPE_WDS ||
5130 iftype == NL80211_IFTYPE_MONITOR) {
5131 /* start listening for EAPOL on this interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005132 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005134
5135 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005136 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005137 nl80211_remove_iface(drv, ifidx);
5138 return -1;
5139 }
5140
5141 return ifidx;
5142}
5143
5144
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005145int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
5146 const char *ifname, enum nl80211_iftype iftype,
5147 const u8 *addr, int wds,
5148 int (*handler)(struct nl_msg *, void *),
5149 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005150{
5151 int ret;
5152
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005153 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
5154 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005156 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005157 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005158 if (use_existing) {
5159 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
5160 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005161 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
5162 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
5163 addr) < 0 &&
5164 (linux_set_iface_flags(drv->global->ioctl_sock,
5165 ifname, 0) < 0 ||
5166 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
5167 addr) < 0 ||
5168 linux_set_iface_flags(drv->global->ioctl_sock,
5169 ifname, 1) < 0))
5170 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005171 return -ENFILE;
5172 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005173 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
5174
5175 /* Try to remove the interface that was already there. */
5176 nl80211_remove_iface(drv, if_nametoindex(ifname));
5177
5178 /* Try to create the interface again */
5179 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005180 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005181 }
5182
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005183 if (ret >= 0 && is_p2p_net_interface(iftype)) {
5184 wpa_printf(MSG_DEBUG,
5185 "nl80211: Interface %s created for P2P - disable 11b rates",
5186 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005187 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005189
5190 return ret;
5191}
5192
5193
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005194static int nl80211_setup_ap(struct i802_bss *bss)
5195{
5196 struct wpa_driver_nl80211_data *drv = bss->drv;
5197
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005198 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
5199 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005200
5201 /*
5202 * Disable Probe Request reporting unless we need it in this way for
5203 * devices that include the AP SME, in the other case (unless using
5204 * monitor iface) we'll get it through the nl_mgmt socket instead.
5205 */
5206 if (!drv->device_ap_sme)
5207 wpa_driver_nl80211_probe_req_report(bss, 0);
5208
5209 if (!drv->device_ap_sme && !drv->use_monitor)
5210 if (nl80211_mgmt_subscribe_ap(bss))
5211 return -1;
5212
5213 if (drv->device_ap_sme && !drv->use_monitor)
5214 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005215 wpa_printf(MSG_DEBUG,
5216 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005217
5218 if (!drv->device_ap_sme && drv->use_monitor &&
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005219 nl80211_create_monitor_interface(drv) &&
5220 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005221 return -1;
5222
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005223 if (drv->device_ap_sme &&
5224 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
5225 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
5226 "Probe Request frame reporting in AP mode");
5227 /* Try to survive without this */
5228 }
5229
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005230 return 0;
5231}
5232
5233
5234static void nl80211_teardown_ap(struct i802_bss *bss)
5235{
5236 struct wpa_driver_nl80211_data *drv = bss->drv;
5237
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005238 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
5239 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005240 if (drv->device_ap_sme) {
5241 wpa_driver_nl80211_probe_req_report(bss, 0);
5242 if (!drv->use_monitor)
5243 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
5244 } else if (drv->use_monitor)
5245 nl80211_remove_monitor_interface(drv);
5246 else
5247 nl80211_mgmt_unsubscribe(bss, "AP teardown");
5248
Paul Stewart092955c2017-02-06 09:13:09 -08005249 nl80211_put_wiphy_data_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005250 bss->beacon_set = 0;
5251}
5252
5253
Hai Shalomfdcde762020-04-02 11:19:20 -07005254static int nl80211_tx_control_port(void *priv, const u8 *dest,
5255 u16 proto, const u8 *buf, size_t len,
5256 int no_encrypt)
5257{
5258 struct i802_bss *bss = priv;
5259 struct nl_msg *msg;
5260 int ret;
5261
5262 wpa_printf(MSG_DEBUG,
5263 "nl80211: Send over control port dest=" MACSTR
5264 " proto=0x%04x len=%u no_encrypt=%d",
5265 MAC2STR(dest), proto, (unsigned int) len, no_encrypt);
5266
5267 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME);
5268 if (!msg ||
5269 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
5270 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) ||
5271 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
5272 (no_encrypt &&
5273 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) {
5274 nlmsg_free(msg);
5275 return -ENOBUFS;
5276 }
5277
5278 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5279 if (ret)
5280 wpa_printf(MSG_DEBUG,
5281 "nl80211: tx_control_port failed: ret=%d (%s)",
5282 ret, strerror(-ret));
5283
5284 return ret;
5285}
5286
5287
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005288static int nl80211_send_eapol_data(struct i802_bss *bss,
5289 const u8 *addr, const u8 *data,
5290 size_t data_len)
5291{
5292 struct sockaddr_ll ll;
5293 int ret;
5294
5295 if (bss->drv->eapol_tx_sock < 0) {
5296 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
5297 return -1;
5298 }
5299
5300 os_memset(&ll, 0, sizeof(ll));
5301 ll.sll_family = AF_PACKET;
5302 ll.sll_ifindex = bss->ifindex;
5303 ll.sll_protocol = htons(ETH_P_PAE);
5304 ll.sll_halen = ETH_ALEN;
5305 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
5306 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
5307 (struct sockaddr *) &ll, sizeof(ll));
5308 if (ret < 0)
5309 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
5310 strerror(errno));
5311
5312 return ret;
5313}
5314
5315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005316static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5317
5318static int wpa_driver_nl80211_hapd_send_eapol(
5319 void *priv, const u8 *addr, const u8 *data,
5320 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
5321{
5322 struct i802_bss *bss = priv;
5323 struct wpa_driver_nl80211_data *drv = bss->drv;
5324 struct ieee80211_hdr *hdr;
5325 size_t len;
5326 u8 *pos;
5327 int res;
5328 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08005329
Hai Shalomb755a2a2020-04-23 21:49:02 -07005330 /* For now, disable EAPOL TX over control port in AP mode by default
5331 * since it does not provide TX status notifications. */
5332 if (drv->control_port_ap &&
5333 (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT))
Hai Shalomfdcde762020-04-02 11:19:20 -07005334 return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL,
5335 data, data_len, !encrypt);
5336
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005337 if (drv->device_ap_sme || !drv->use_monitor)
5338 return nl80211_send_eapol_data(bss, addr, data, data_len);
5339
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005340 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
5341 data_len;
5342 hdr = os_zalloc(len);
5343 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005344 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
5345 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005346 return -1;
5347 }
5348
5349 hdr->frame_control =
5350 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
5351 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
5352 if (encrypt)
5353 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
5354 if (qos) {
5355 hdr->frame_control |=
5356 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
5357 }
5358
5359 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
5360 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
5361 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
5362 pos = (u8 *) (hdr + 1);
5363
5364 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005365 /* Set highest priority in QoS header */
5366 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005367 pos[1] = 0;
5368 pos += 2;
5369 }
5370
5371 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
5372 pos += sizeof(rfc1042_header);
5373 WPA_PUT_BE16(pos, ETH_P_PAE);
5374 pos += 2;
5375 memcpy(pos, data, data_len);
5376
Hai Shalomfdcde762020-04-02 11:19:20 -07005377 res = nl80211_send_monitor(drv, hdr, len, encrypt, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005378 if (res < 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005379 wpa_printf(MSG_ERROR,
5380 "hapd_send_eapol - packet len: %lu - failed",
5381 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005382 }
5383 os_free(hdr);
5384
5385 return res;
5386}
5387
5388
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005389static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005390 unsigned int total_flags,
5391 unsigned int flags_or,
5392 unsigned int flags_and)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005393{
5394 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005395 struct nl_msg *msg;
5396 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005397 struct nl80211_sta_flag_update upd;
5398
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005399 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
5400 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
5401 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
5402 !!(total_flags & WPA_STA_AUTHORIZED));
5403
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005404 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5405 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
5406 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005407
5408 /*
5409 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5410 * can be removed eventually.
5411 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005412 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005413 if (!flags ||
5414 ((total_flags & WPA_STA_AUTHORIZED) &&
5415 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
5416 ((total_flags & WPA_STA_WMM) &&
5417 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
5418 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
5419 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
5420 ((total_flags & WPA_STA_MFP) &&
5421 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
5422 ((total_flags & WPA_STA_TDLS_PEER) &&
5423 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
5424 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005425
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005426 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005427
5428 os_memset(&upd, 0, sizeof(upd));
5429 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
5430 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005431 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
5432 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005433
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005434 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5435fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005436 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005437 return -ENOBUFS;
5438}
5439
5440
Hai Shalom81f62d82019-07-22 12:10:00 -07005441static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr,
5442 unsigned int weight)
5443{
5444 struct i802_bss *bss = priv;
5445 struct nl_msg *msg;
5446
5447 wpa_printf(MSG_DEBUG,
5448 "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR
5449 " weight=%u", bss->ifname, MAC2STR(addr), weight);
5450
5451 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5452 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5453 nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight))
5454 goto fail;
5455
5456 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5457fail:
5458 nlmsg_free(msg);
5459 return -ENOBUFS;
5460}
5461
5462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005463static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
5464 struct wpa_driver_associate_params *params)
5465{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005466 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005467
5468 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005469 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
5470 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005471 nlmode = NL80211_IFTYPE_P2P_GO;
5472 } else
5473 nlmode = NL80211_IFTYPE_AP;
5474
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005475 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005476 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005477 nl80211_remove_monitor_interface(drv);
5478 return -1;
5479 }
5480
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005481 if (params->freq.freq &&
5482 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005483 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005484 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005485 nl80211_remove_monitor_interface(drv);
5486 return -1;
5487 }
5488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005489 return 0;
5490}
5491
5492
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005493static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
5494 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005495{
5496 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005497 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005498
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005499 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Hai Shalomb755a2a2020-04-23 21:49:02 -07005500 ret = send_and_recv_msgs_owner(drv, msg,
5501 get_connect_handle(drv->first_bss), 1,
5502 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005503 if (ret) {
5504 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
5505 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005506 } else {
5507 wpa_printf(MSG_DEBUG,
5508 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005509 }
5510
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005511 if (reset_mode &&
5512 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07005513 NL80211_IFTYPE_STATION)) {
5514 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5515 "station mode");
5516 }
5517
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005518 return ret;
5519}
5520
5521
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005522static int nl80211_ht_vht_overrides(struct nl_msg *msg,
5523 struct wpa_driver_associate_params *params)
5524{
5525 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
5526 return -1;
5527
5528 if (params->htcaps && params->htcaps_mask) {
5529 int sz = sizeof(struct ieee80211_ht_capabilities);
5530 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
5531 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
5532 params->htcaps_mask, sz);
5533 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
5534 params->htcaps) ||
5535 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
5536 params->htcaps_mask))
5537 return -1;
5538 }
5539
5540#ifdef CONFIG_VHT_OVERRIDES
5541 if (params->disable_vht) {
5542 wpa_printf(MSG_DEBUG, " * VHT disabled");
5543 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
5544 return -1;
5545 }
5546
5547 if (params->vhtcaps && params->vhtcaps_mask) {
5548 int sz = sizeof(struct ieee80211_vht_capabilities);
5549 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
5550 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
5551 params->vhtcaps_mask, sz);
5552 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
5553 params->vhtcaps) ||
5554 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
5555 params->vhtcaps_mask))
5556 return -1;
5557 }
5558#endif /* CONFIG_VHT_OVERRIDES */
5559
5560 return 0;
5561}
5562
5563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005564static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
5565 struct wpa_driver_associate_params *params)
5566{
5567 struct nl_msg *msg;
5568 int ret = -1;
5569 int count = 0;
5570
5571 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
5572
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005573 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005574 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5575 "IBSS mode");
5576 return -1;
5577 }
5578
5579retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005580 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
5581 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
5582 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005583
Hai Shalom74f70d42019-02-11 14:42:39 -08005584 wpa_printf(MSG_DEBUG, " * SSID=%s",
5585 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005586 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
5587 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005588 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5589 drv->ssid_len = params->ssid_len;
5590
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005591 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
5592 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005593 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005594
5595 ret = nl80211_set_conn_keys(params, msg);
5596 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005597 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005598
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005599 if (params->bssid && params->fixed_bssid) {
5600 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
5601 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005602 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5603 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005604 }
5605
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005606 if (params->fixed_freq) {
5607 wpa_printf(MSG_DEBUG, " * fixed_freq");
5608 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
5609 goto fail;
5610 }
5611
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005612 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5613 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5614 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
5615 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005616 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005617 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5618 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005619 }
5620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005621 if (params->wpa_ie) {
5622 wpa_hexdump(MSG_DEBUG,
5623 " * Extra IEs for Beacon/Probe Response frames",
5624 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005625 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
5626 params->wpa_ie))
5627 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005628 }
5629
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08005630 ret = nl80211_ht_vht_overrides(msg, params);
5631 if (ret < 0)
5632 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005633
Hai Shalomb755a2a2020-04-23 21:49:02 -07005634 ret = send_and_recv_msgs_owner(drv, msg,
5635 get_connect_handle(drv->first_bss), 1,
5636 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005637 msg = NULL;
5638 if (ret) {
5639 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
5640 ret, strerror(-ret));
5641 count++;
5642 if (ret == -EALREADY && count == 1) {
5643 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
5644 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005645 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005646 nlmsg_free(msg);
5647 goto retry;
5648 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005649 } else {
5650 wpa_printf(MSG_DEBUG,
5651 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005654fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005655 nlmsg_free(msg);
5656 return ret;
5657}
5658
5659
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005660static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv,
5661 struct wpa_driver_associate_params *params,
5662 struct nl_msg *msg)
5663{
5664 if (params->fils_erp_username_len) {
5665 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username",
5666 params->fils_erp_username,
5667 params->fils_erp_username_len);
5668 if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME,
5669 params->fils_erp_username_len,
5670 params->fils_erp_username))
5671 return -1;
5672 }
5673
5674 if (params->fils_erp_realm_len) {
5675 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm",
5676 params->fils_erp_realm,
5677 params->fils_erp_realm_len);
5678 if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM,
5679 params->fils_erp_realm_len, params->fils_erp_realm))
5680 return -1;
5681 }
5682
5683 wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u",
5684 params->fils_erp_next_seq_num);
5685 if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
5686 params->fils_erp_next_seq_num))
5687 return -1;
5688
5689 if (params->fils_erp_rrk_len) {
5690 wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)",
5691 (unsigned long) params->fils_erp_rrk_len);
5692 if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK,
5693 params->fils_erp_rrk_len, params->fils_erp_rrk))
5694 return -1;
5695 }
5696
5697 return 0;
5698}
5699
5700
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005701static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
5702 struct wpa_driver_associate_params *params,
5703 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005704{
Paul Stewart092955c2017-02-06 09:13:09 -08005705 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
5706 return -1;
5707
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005708 if (params->bssid) {
5709 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
5710 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005711 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5712 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005713 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005714
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005715 if (params->bssid_hint) {
5716 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
5717 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005718 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
5719 params->bssid_hint))
5720 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005721 }
5722
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005723 if (params->freq.freq) {
5724 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005725 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
5726 params->freq.freq))
5727 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005728 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005729 } else
5730 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005731
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005732 if (params->freq_hint) {
5733 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005734 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
5735 params->freq_hint))
5736 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005737 }
5738
Hai Shalomc3565922019-10-28 11:58:20 -07005739 if (params->freq.edmg.channels && params->freq.edmg.bw_config) {
5740 wpa_printf(MSG_DEBUG,
5741 " * EDMG configuration: channels=0x%x bw_config=%d",
5742 params->freq.edmg.channels,
5743 params->freq.edmg.bw_config);
5744 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
5745 params->freq.edmg.channels) ||
5746 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
5747 params->freq.edmg.bw_config))
5748 return -1;
5749 }
5750
Dmitry Shmidt04949592012-07-19 12:16:46 -07005751 if (params->bg_scan_period >= 0) {
5752 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
5753 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005754 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
5755 params->bg_scan_period))
5756 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005757 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005759 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005760 wpa_printf(MSG_DEBUG, " * SSID=%s",
5761 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005762 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
5763 params->ssid))
5764 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005765 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005766 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005767 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5768 drv->ssid_len = params->ssid_len;
5769 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005770
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005771 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005772 if (params->wpa_ie &&
5773 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
5774 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005775
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005776 if (params->wpa_proto) {
5777 enum nl80211_wpa_versions ver = 0;
5778
5779 if (params->wpa_proto & WPA_PROTO_WPA)
5780 ver |= NL80211_WPA_VERSION_1;
5781 if (params->wpa_proto & WPA_PROTO_RSN)
5782 ver |= NL80211_WPA_VERSION_2;
5783
5784 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005785 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
5786 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005787 }
5788
5789 if (params->pairwise_suite != WPA_CIPHER_NONE) {
5790 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
5791 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005792 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
5793 cipher))
5794 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005795 }
5796
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005797 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
5798 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
5799 /*
5800 * This is likely to work even though many drivers do not
5801 * advertise support for operations without GTK.
5802 */
5803 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5804 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005805 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
5806 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005807 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
5808 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005809 }
5810
5811 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5812 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5813 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
5814 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07005815 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005816 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
5817 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005818 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07005819 params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5820 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005821 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005822 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07005823 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005824 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 ||
5825 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 ||
5826 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07005827 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 ||
5828 params->key_mgmt_suite == WPA_KEY_MGMT_OWE ||
5829 params->key_mgmt_suite == WPA_KEY_MGMT_DPP) {
Paul Stewart092955c2017-02-06 09:13:09 -08005830 int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005831
5832 switch (params->key_mgmt_suite) {
5833 case WPA_KEY_MGMT_CCKM:
Paul Stewart092955c2017-02-06 09:13:09 -08005834 mgmt = RSN_AUTH_KEY_MGMT_CCKM;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005835 break;
5836 case WPA_KEY_MGMT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005837 mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005838 break;
5839 case WPA_KEY_MGMT_FT_IEEE8021X:
Paul Stewart092955c2017-02-06 09:13:09 -08005840 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005841 break;
5842 case WPA_KEY_MGMT_FT_PSK:
Paul Stewart092955c2017-02-06 09:13:09 -08005843 mgmt = RSN_AUTH_KEY_MGMT_FT_PSK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005844 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005845 case WPA_KEY_MGMT_IEEE8021X_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005846 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005847 break;
5848 case WPA_KEY_MGMT_PSK_SHA256:
Paul Stewart092955c2017-02-06 09:13:09 -08005849 mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07005850 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005851 case WPA_KEY_MGMT_OSEN:
Paul Stewart092955c2017-02-06 09:13:09 -08005852 mgmt = RSN_AUTH_KEY_MGMT_OSEN;
Dmitry Shmidt15907092014-03-25 10:42:57 -07005853 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07005854 case WPA_KEY_MGMT_SAE:
5855 mgmt = RSN_AUTH_KEY_MGMT_SAE;
5856 break;
5857 case WPA_KEY_MGMT_FT_SAE:
5858 mgmt = RSN_AUTH_KEY_MGMT_FT_SAE;
5859 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005860 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
Paul Stewart092955c2017-02-06 09:13:09 -08005861 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005862 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005863 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
Paul Stewart092955c2017-02-06 09:13:09 -08005864 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005865 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07005866 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
5867 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384;
5868 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005869 case WPA_KEY_MGMT_FILS_SHA256:
5870 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256;
5871 break;
5872 case WPA_KEY_MGMT_FILS_SHA384:
5873 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384;
5874 break;
5875 case WPA_KEY_MGMT_FT_FILS_SHA256:
5876 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
5877 break;
5878 case WPA_KEY_MGMT_FT_FILS_SHA384:
5879 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
5880 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005881 case WPA_KEY_MGMT_OWE:
5882 mgmt = RSN_AUTH_KEY_MGMT_OWE;
5883 break;
5884 case WPA_KEY_MGMT_DPP:
5885 mgmt = RSN_AUTH_KEY_MGMT_DPP;
5886 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005887 case WPA_KEY_MGMT_PSK:
5888 default:
Paul Stewart092955c2017-02-06 09:13:09 -08005889 mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005890 break;
5891 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07005892 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005893 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
5894 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005895 }
5896
Hai Shalomc3565922019-10-28 11:58:20 -07005897 if (params->req_handshake_offload &&
Hai Shalom74f70d42019-02-11 14:42:39 -08005898 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) {
5899 wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS");
5900 if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS))
5901 return -1;
5902 }
5903
Roshan Pius3a1667e2018-07-03 15:17:14 -07005904 /* Add PSK in case of 4-way handshake offload */
5905 if (params->psk &&
Hai Shalom74f70d42019-02-11 14:42:39 -08005906 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005907 wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32);
5908 if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk))
5909 return -1;
5910 }
5911
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005912 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5913 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005914
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005915 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
5916 (params->pairwise_suite == WPA_CIPHER_NONE ||
5917 params->pairwise_suite == WPA_CIPHER_WEP104 ||
5918 params->pairwise_suite == WPA_CIPHER_WEP40) &&
5919 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
5920 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
5921 return -1;
5922
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005923 if (params->rrm_used) {
5924 u32 drv_rrm_flags = drv->capa.rrm_flags;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005925 if ((!((drv_rrm_flags &
5926 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) &&
5927 (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) &&
5928 !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005929 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
5930 return -1;
5931 }
5932
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005933 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005934 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005935
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005936 if (params->p2p)
5937 wpa_printf(MSG_DEBUG, " * P2P group");
5938
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005939 if (params->pbss) {
5940 wpa_printf(MSG_DEBUG, " * PBSS");
5941 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
5942 return -1;
5943 }
5944
Dmitry Shmidte4663042016-04-04 10:07:49 -07005945 drv->connect_reassoc = 0;
5946 if (params->prev_bssid) {
5947 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
5948 MAC2STR(params->prev_bssid));
5949 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
5950 params->prev_bssid))
5951 return -1;
5952 drv->connect_reassoc = 1;
5953 }
5954
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005955 if ((params->auth_alg & WPA_AUTH_ALG_FILS) &&
5956 nl80211_put_fils_connect_params(drv, params, msg) != 0)
5957 return -1;
5958
Hai Shalomc3565922019-10-28 11:58:20 -07005959 if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5960 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07005961 (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) &&
5962 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
5963 return -1;
5964
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005965 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005966}
5967
5968
5969static int wpa_driver_nl80211_try_connect(
5970 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005971 struct wpa_driver_associate_params *params,
Hai Shalomfdcde762020-04-02 11:19:20 -07005972 struct nl_sock *nl_connect)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005973{
5974 struct nl_msg *msg;
5975 enum nl80211_auth_type type;
5976 int ret;
5977 int algs;
5978
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005979#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005980 if (params->req_key_mgmt_offload && params->psk &&
5981 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5982 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
5983 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
5984 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
5985 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
5986 if (ret)
5987 return ret;
5988 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005989#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005990
5991 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
5992 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005993 if (!msg)
5994 return -1;
5995
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005996 ret = nl80211_connect_common(drv, params, msg);
5997 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005998 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005999
Roshan Pius3a1667e2018-07-03 15:17:14 -07006000 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
6001 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
6002 goto fail;
6003
6004 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL &&
6005 (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) &&
6006 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL))
6007 goto fail;
6008
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006009 algs = 0;
6010 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
6011 algs++;
6012 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
6013 algs++;
6014 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
6015 algs++;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006016 if (params->auth_alg & WPA_AUTH_ALG_FILS)
6017 algs++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006018 if (params->auth_alg & WPA_AUTH_ALG_FT)
6019 algs++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006020 if (algs > 1) {
6021 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
6022 "selection");
6023 goto skip_auth_type;
6024 }
6025
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006026 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006027 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006028 if (type == NL80211_AUTHTYPE_MAX ||
6029 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006030 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006031
6032skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006033 ret = nl80211_set_conn_keys(params, msg);
6034 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006035 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006036
Hai Shalomb755a2a2020-04-23 21:49:02 -07006037 ret = send_and_recv_msgs_owner(drv, msg, nl_connect, 1, NULL,
6038 (void *) -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006039 msg = NULL;
6040 if (ret) {
6041 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
6042 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006043 } else {
6044 wpa_printf(MSG_DEBUG,
6045 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006047
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006048fail:
Hai Shalom74f70d42019-02-11 14:42:39 -08006049 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006050 nlmsg_free(msg);
6051 return ret;
6052
6053}
6054
6055
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006056static int wpa_driver_nl80211_connect(
6057 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07006058 struct wpa_driver_associate_params *params,
Hai Shalomfdcde762020-04-02 11:19:20 -07006059 struct nl_sock *nl_connect)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006060{
Jithu Jancea7c60b42014-12-03 18:54:40 +05306061 int ret;
6062
6063 /* Store the connection attempted bssid for future use */
6064 if (params->bssid)
6065 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
6066 else
6067 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
6068
Roshan Pius3a1667e2018-07-03 15:17:14 -07006069 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006070 if (ret == -EALREADY) {
6071 /*
6072 * cfg80211 does not currently accept new connections if
6073 * we are already connected. As a workaround, force
6074 * disconnection and try again.
6075 */
6076 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
6077 "disconnecting before reassociation "
6078 "attempt");
6079 if (wpa_driver_nl80211_disconnect(
Hai Shalom74f70d42019-02-11 14:42:39 -08006080 drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006081 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006082 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006083 }
6084 return ret;
6085}
6086
6087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006088static int wpa_driver_nl80211_associate(
6089 void *priv, struct wpa_driver_associate_params *params)
6090{
6091 struct i802_bss *bss = priv;
6092 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006093 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006094 struct nl_msg *msg;
6095
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006096 nl80211_unmask_11b_rates(bss);
6097
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006098 if (params->mode == IEEE80211_MODE_AP)
6099 return wpa_driver_nl80211_ap(drv, params);
6100
6101 if (params->mode == IEEE80211_MODE_IBSS)
6102 return wpa_driver_nl80211_ibss(drv, params);
6103
6104 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006105 enum nl80211_iftype nlmode = params->p2p ?
6106 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
6107
6108 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006109 return -1;
Hai Shalomc3565922019-10-28 11:58:20 -07006110 if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
Hai Shalomb755a2a2020-04-23 21:49:02 -07006111 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)
Hai Shalom74f70d42019-02-11 14:42:39 -08006112 bss->use_nl_connect = 1;
Hai Shalomb755a2a2020-04-23 21:49:02 -07006113 else
Hai Shalom74f70d42019-02-11 14:42:39 -08006114 bss->use_nl_connect = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006115
Hai Shalomb755a2a2020-04-23 21:49:02 -07006116 return wpa_driver_nl80211_connect(drv, params,
6117 get_connect_handle(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006118 }
6119
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07006120 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006121
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006122 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
6123 drv->ifindex);
6124 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006125 if (!msg)
6126 return -1;
6127
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006128 ret = nl80211_connect_common(drv, params, msg);
6129 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006130 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006131
Roshan Pius3a1667e2018-07-03 15:17:14 -07006132 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
6133 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
6134 goto fail;
6135
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006136 if (params->fils_kek) {
6137 wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)",
6138 (unsigned int) params->fils_kek_len);
6139 if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len,
6140 params->fils_kek))
6141 goto fail;
6142 }
6143 if (params->fils_nonces) {
6144 wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)",
6145 params->fils_nonces,
6146 params->fils_nonces_len);
6147 if (nla_put(msg, NL80211_ATTR_FILS_NONCES,
6148 params->fils_nonces_len, params->fils_nonces))
6149 goto fail;
6150 }
6151
Hai Shalomb755a2a2020-04-23 21:49:02 -07006152 ret = send_and_recv_msgs_owner(drv, msg,
6153 get_connect_handle(drv->first_bss), 1,
6154 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006155 msg = NULL;
6156 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006157 wpa_dbg(drv->ctx, MSG_DEBUG,
6158 "nl80211: MLME command failed (assoc): ret=%d (%s)",
6159 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006160 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006161 } else {
6162 wpa_printf(MSG_DEBUG,
6163 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006164 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006165
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006166fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006167 nlmsg_free(msg);
6168 return ret;
6169}
6170
6171
6172static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006173 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006174{
6175 struct nl_msg *msg;
6176 int ret = -ENOBUFS;
6177
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006178 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
6179 ifindex, mode, nl80211_iftype_str(mode));
6180
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006181 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
6182 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
6183 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006184
6185 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006186 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006187 if (!ret)
6188 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006189fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006190 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006191 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
6192 " %d (%s)", ifindex, mode, ret, strerror(-ret));
6193 return ret;
6194}
6195
6196
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006197static int wpa_driver_nl80211_set_mode_impl(
6198 struct i802_bss *bss,
6199 enum nl80211_iftype nlmode,
6200 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006201{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006202 struct wpa_driver_nl80211_data *drv = bss->drv;
6203 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006204 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006205 int was_ap = is_ap_interface(drv->nlmode);
6206 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006207 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006208
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07006209 if (TEST_FAIL())
6210 return -1;
6211
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006212 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
6213 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
6214 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006215
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006216 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006217 drv->nlmode = nlmode;
6218 ret = 0;
6219 goto done;
6220 }
6221
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006222 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006223 return -1;
6224
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006225 if (nlmode == drv->nlmode) {
6226 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
6227 "requested mode - ignore error");
6228 ret = 0;
6229 goto done; /* Already in the requested mode */
6230 }
6231
6232 /* mac80211 doesn't allow mode changes while the device is up, so
6233 * take the device down, try to set the mode again, and bring the
6234 * device back up.
6235 */
6236 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
6237 "interface down");
6238 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006239 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006240 if (res == -EACCES || res == -ENODEV)
6241 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006242 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006243 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
6244 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006245 os_sleep(0, 100000);
6246 continue;
6247 }
6248
6249 /*
6250 * Setting the mode will fail for some drivers if the phy is
6251 * on a frequency that the mode is disallowed in.
6252 */
6253 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006254 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006255 if (res) {
6256 wpa_printf(MSG_DEBUG,
6257 "nl80211: Failed to set frequency on interface");
6258 }
6259 }
6260
6261 /* Try to set the mode again while the interface is down */
6262 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
6263 if (mode_switch_res == -EBUSY) {
6264 wpa_printf(MSG_DEBUG,
6265 "nl80211: Delaying mode set while interface going down");
6266 os_sleep(0, 100000);
6267 continue;
6268 }
6269 ret = mode_switch_res;
6270 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006271 }
6272
6273 if (!ret) {
6274 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
6275 "interface is down");
6276 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006277 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006278 }
6279
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006280 /* Bring the interface back up */
6281 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
6282 if (res != 0) {
6283 wpa_printf(MSG_DEBUG,
6284 "nl80211: Failed to set interface up after switching mode");
6285 ret = -1;
6286 }
6287
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006288done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006289 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006290 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
6291 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006292 return ret;
6293 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006295 if (is_p2p_net_interface(nlmode)) {
6296 wpa_printf(MSG_DEBUG,
6297 "nl80211: Interface %s mode change to P2P - disable 11b rates",
6298 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006299 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006300 } else if (drv->disabled_11b_rates) {
6301 wpa_printf(MSG_DEBUG,
6302 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
6303 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006304 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006305 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006306
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006307 if (is_ap_interface(nlmode)) {
6308 nl80211_mgmt_unsubscribe(bss, "start AP");
6309 /* Setup additional AP mode functionality if needed */
6310 if (nl80211_setup_ap(bss))
6311 return -1;
6312 } else if (was_ap) {
6313 /* Remove additional AP mode functionality */
6314 nl80211_teardown_ap(bss);
6315 } else {
6316 nl80211_mgmt_unsubscribe(bss, "mode change");
6317 }
6318
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006319 if (is_mesh_interface(nlmode) &&
6320 nl80211_mgmt_subscribe_mesh(bss))
6321 return -1;
6322
Dmitry Shmidt04949592012-07-19 12:16:46 -07006323 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006324 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006325 nl80211_mgmt_subscribe_non_ap(bss) < 0)
6326 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
6327 "frame processing - ignore for now");
6328
6329 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006330}
6331
6332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006333int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
6334 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006335{
6336 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
6337}
6338
6339
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006340static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
6341 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006342{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006343 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006344 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07006345}
6346
6347
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006348static int wpa_driver_nl80211_get_capa(void *priv,
6349 struct wpa_driver_capa *capa)
6350{
6351 struct i802_bss *bss = priv;
6352 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07006353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006354 if (!drv->has_capability)
6355 return -1;
6356 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006357 if (drv->extended_capa && drv->extended_capa_mask) {
6358 capa->extended_capa = drv->extended_capa;
6359 capa->extended_capa_mask = drv->extended_capa_mask;
6360 capa->extended_capa_len = drv->extended_capa_len;
6361 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006362
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006363 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006364}
6365
6366
6367static int wpa_driver_nl80211_set_operstate(void *priv, int state)
6368{
6369 struct i802_bss *bss = priv;
6370 struct wpa_driver_nl80211_data *drv = bss->drv;
6371
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006372 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
6373 bss->ifname, drv->operstate, state,
6374 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006375 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006376 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006377 state ? IF_OPER_UP : IF_OPER_DORMANT);
6378}
6379
6380
6381static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
6382{
6383 struct i802_bss *bss = priv;
6384 struct wpa_driver_nl80211_data *drv = bss->drv;
6385 struct nl_msg *msg;
6386 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006387 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006388
6389 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
6390 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
6391 return 0;
6392 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006393
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07006394 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
6395 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
6396
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006397 os_memset(&upd, 0, sizeof(upd));
6398 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
6399 if (authorized)
6400 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006401
6402 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6403 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
6404 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
6405 nlmsg_free(msg);
6406 return -ENOBUFS;
6407 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006408
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006409 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006410 if (!ret)
6411 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006412 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
6413 ret, strerror(-ret));
6414 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006415}
6416
6417
Jouni Malinen75ecf522011-06-27 15:19:46 -07006418/* Set kernel driver on given frequency (MHz) */
6419static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006420{
Jouni Malinen75ecf522011-06-27 15:19:46 -07006421 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006422 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006423}
6424
6425
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006426static inline int min_int(int a, int b)
6427{
6428 if (a < b)
6429 return a;
6430 return b;
6431}
6432
6433
6434static int get_key_handler(struct nl_msg *msg, void *arg)
6435{
6436 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6437 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6438
6439 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6440 genlmsg_attrlen(gnlh, 0), NULL);
6441
6442 /*
6443 * TODO: validate the key index and mac address!
6444 * Otherwise, there's a race condition as soon as
6445 * the kernel starts sending key notifications.
6446 */
6447
6448 if (tb[NL80211_ATTR_KEY_SEQ])
6449 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
6450 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
Hai Shalom021b0b52019-04-10 11:17:58 -07006451 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006452 return NL_SKIP;
6453}
6454
6455
6456static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
6457 int idx, u8 *seq)
6458{
6459 struct i802_bss *bss = priv;
6460 struct wpa_driver_nl80211_data *drv = bss->drv;
6461 struct nl_msg *msg;
6462
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006463 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
6464 NL80211_CMD_GET_KEY);
6465 if (!msg ||
6466 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
6467 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
6468 nlmsg_free(msg);
6469 return -ENOBUFS;
6470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006471
6472 memset(seq, 0, 6);
6473
6474 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006475}
6476
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006477
6478static int i802_set_rts(void *priv, int rts)
6479{
6480 struct i802_bss *bss = priv;
6481 struct wpa_driver_nl80211_data *drv = bss->drv;
6482 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006483 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006484 u32 val;
6485
Hai Shalom021b0b52019-04-10 11:17:58 -07006486 if (rts >= 2347 || rts == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006487 val = (u32) -1;
6488 else
6489 val = rts;
6490
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006491 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6492 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6493 nlmsg_free(msg);
6494 return -ENOBUFS;
6495 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006496
6497 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6498 if (!ret)
6499 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006500 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
6501 "%d (%s)", rts, ret, strerror(-ret));
6502 return ret;
6503}
6504
6505
6506static int i802_set_frag(void *priv, int frag)
6507{
6508 struct i802_bss *bss = priv;
6509 struct wpa_driver_nl80211_data *drv = bss->drv;
6510 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006511 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006512 u32 val;
6513
Hai Shalom021b0b52019-04-10 11:17:58 -07006514 if (frag >= 2346 || frag == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006515 val = (u32) -1;
6516 else
6517 val = frag;
6518
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006519 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6520 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
6521 nlmsg_free(msg);
6522 return -ENOBUFS;
6523 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006524
6525 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6526 if (!ret)
6527 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006528 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
6529 "%d: %d (%s)", frag, ret, strerror(-ret));
6530 return ret;
6531}
6532
6533
6534static int i802_flush(void *priv)
6535{
6536 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006537 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006538 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006539
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006540 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
6541 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006542
6543 /*
6544 * XXX: FIX! this needs to flush all VLANs too
6545 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006546 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
6547 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006548 if (res) {
6549 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
6550 "(%s)", res, strerror(-res));
6551 }
6552 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006553}
6554
6555
Hai Shalom81f62d82019-07-22 12:10:00 -07006556static void get_sta_tid_stats(struct hostap_sta_driver_data *data,
6557 struct nlattr *attr)
6558{
6559 struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr;
6560 struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1];
6561 static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = {
6562 [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 },
6563 [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 },
6564 };
6565 int rem;
6566
6567 nla_for_each_nested(tidattr, attr, rem) {
6568 if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX,
6569 tidattr, NULL) != 0 ||
6570 !tid_stats[NL80211_TID_STATS_TXQ_STATS] ||
6571 nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX,
6572 tid_stats[NL80211_TID_STATS_TXQ_STATS],
6573 txq_stats_policy) != 0)
6574 continue;
6575 /* sum the backlogs over all TIDs for station */
6576 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES])
6577 data->backlog_bytes += nla_get_u32(
6578 txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]);
6579 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS])
6580 data->backlog_bytes += nla_get_u32(
6581 txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]);
6582 }
6583}
6584
6585
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006586static int get_sta_handler(struct nl_msg *msg, void *arg)
6587{
6588 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6589 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6590 struct hostap_sta_driver_data *data = arg;
6591 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
6592 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
6593 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
6594 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
6595 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
6596 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
6597 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006598 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006599 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
6600 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006601 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Roshan Pius3a1667e2018-07-03 15:17:14 -07006602 [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 },
Hai Shalom81f62d82019-07-22 12:10:00 -07006603 [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 },
6604 [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006605 };
6606 struct nlattr *rate[NL80211_RATE_INFO_MAX + 1];
6607 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
6608 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
6609 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
6610 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
6611 [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 },
6612 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
6613 [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006614 };
6615
6616 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6617 genlmsg_attrlen(gnlh, 0), NULL);
6618
6619 /*
6620 * TODO: validate the interface and mac address!
6621 * Otherwise, there's a race condition as soon as
6622 * the kernel starts sending station notifications.
6623 */
6624
6625 if (!tb[NL80211_ATTR_STA_INFO]) {
6626 wpa_printf(MSG_DEBUG, "sta stats missing!");
6627 return NL_SKIP;
6628 }
6629 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
6630 tb[NL80211_ATTR_STA_INFO],
6631 stats_policy)) {
6632 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
6633 return NL_SKIP;
6634 }
6635
6636 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
6637 data->inactive_msec =
6638 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006639 /* For backwards compatibility, fetch the 32-bit counters first. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006640 if (stats[NL80211_STA_INFO_RX_BYTES])
6641 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
6642 if (stats[NL80211_STA_INFO_TX_BYTES])
6643 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006644 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
6645 stats[NL80211_STA_INFO_TX_BYTES64]) {
6646 /*
6647 * The driver supports 64-bit counters, so use them to override
6648 * the 32-bit values.
6649 */
6650 data->rx_bytes =
6651 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
6652 data->tx_bytes =
6653 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
6654 data->bytes_64bit = 1;
6655 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006656 if (stats[NL80211_STA_INFO_RX_PACKETS])
6657 data->rx_packets =
6658 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
6659 if (stats[NL80211_STA_INFO_TX_PACKETS])
6660 data->tx_packets =
6661 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Hai Shalom81f62d82019-07-22 12:10:00 -07006662 if (stats[NL80211_STA_INFO_RX_DURATION])
6663 data->rx_airtime =
6664 nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]);
6665 if (stats[NL80211_STA_INFO_TX_DURATION])
6666 data->tx_airtime =
6667 nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03006668 if (stats[NL80211_STA_INFO_TX_FAILED])
6669 data->tx_retry_failed =
6670 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006671 if (stats[NL80211_STA_INFO_SIGNAL])
6672 data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006673 if (stats[NL80211_STA_INFO_ACK_SIGNAL]) {
6674 data->last_ack_rssi =
6675 nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]);
6676 data->flags |= STA_DRV_DATA_LAST_ACK_RSSI;
6677 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006678
6679 if (stats[NL80211_STA_INFO_TX_BITRATE] &&
6680 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6681 stats[NL80211_STA_INFO_TX_BITRATE],
6682 rate_policy) == 0) {
6683 if (rate[NL80211_RATE_INFO_BITRATE32])
6684 data->current_tx_rate =
6685 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6686 else if (rate[NL80211_RATE_INFO_BITRATE])
6687 data->current_tx_rate =
6688 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6689
6690 if (rate[NL80211_RATE_INFO_MCS]) {
6691 data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6692 data->flags |= STA_DRV_DATA_TX_MCS;
6693 }
6694 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6695 data->tx_vhtmcs =
6696 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6697 data->flags |= STA_DRV_DATA_TX_VHT_MCS;
6698 }
6699 if (rate[NL80211_RATE_INFO_SHORT_GI])
6700 data->flags |= STA_DRV_DATA_TX_SHORT_GI;
6701 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6702 data->tx_vht_nss =
6703 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6704 data->flags |= STA_DRV_DATA_TX_VHT_NSS;
6705 }
6706 }
6707
6708 if (stats[NL80211_STA_INFO_RX_BITRATE] &&
6709 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6710 stats[NL80211_STA_INFO_RX_BITRATE],
6711 rate_policy) == 0) {
6712 if (rate[NL80211_RATE_INFO_BITRATE32])
6713 data->current_rx_rate =
6714 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6715 else if (rate[NL80211_RATE_INFO_BITRATE])
6716 data->current_rx_rate =
6717 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6718
6719 if (rate[NL80211_RATE_INFO_MCS]) {
6720 data->rx_mcs =
6721 nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6722 data->flags |= STA_DRV_DATA_RX_MCS;
6723 }
6724 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6725 data->rx_vhtmcs =
6726 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6727 data->flags |= STA_DRV_DATA_RX_VHT_MCS;
6728 }
6729 if (rate[NL80211_RATE_INFO_SHORT_GI])
6730 data->flags |= STA_DRV_DATA_RX_SHORT_GI;
6731 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6732 data->rx_vht_nss =
6733 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6734 data->flags |= STA_DRV_DATA_RX_VHT_NSS;
6735 }
6736 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006737
Hai Shalom81f62d82019-07-22 12:10:00 -07006738 if (stats[NL80211_STA_INFO_TID_STATS])
6739 get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]);
6740
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006741 return NL_SKIP;
6742}
6743
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006744static int i802_read_sta_data(struct i802_bss *bss,
6745 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006746 const u8 *addr)
6747{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006748 struct nl_msg *msg;
6749
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006750 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
6751 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6752 nlmsg_free(msg);
6753 return -ENOBUFS;
6754 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006755
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006756 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006757}
6758
6759
6760static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
6761 int cw_min, int cw_max, int burst_time)
6762{
6763 struct i802_bss *bss = priv;
6764 struct wpa_driver_nl80211_data *drv = bss->drv;
6765 struct nl_msg *msg;
6766 struct nlattr *txq, *params;
Hai Shalom74f70d42019-02-11 14:42:39 -08006767 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006768
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006769 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006770 if (!msg)
6771 return -1;
6772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006773 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
6774 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006775 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006776
6777 /* We are only sending parameters for a single TXQ at a time */
6778 params = nla_nest_start(msg, 1);
6779 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006780 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006781
6782 switch (queue) {
6783 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006784 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
6785 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006786 break;
6787 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006788 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
6789 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006790 break;
6791 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006792 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
6793 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006794 break;
6795 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006796 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
6797 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006798 break;
6799 }
6800 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6801 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006802 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
6803 (burst_time * 100 + 16) / 32) ||
6804 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
6805 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
6806 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
6807 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006808
6809 nla_nest_end(msg, params);
6810
6811 nla_nest_end(msg, txq);
6812
Hai Shalom74f70d42019-02-11 14:42:39 -08006813 res = send_and_recv_msgs(drv, msg, NULL, NULL);
6814 wpa_printf(MSG_DEBUG,
6815 "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d",
6816 queue, aifs, cw_min, cw_max, burst_time, res);
6817 if (res == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006818 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006819 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006820fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006821 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006822 return -1;
6823}
6824
6825
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006826static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006827 const char *ifname, int vlan_id)
6828{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006829 struct wpa_driver_nl80211_data *drv = bss->drv;
6830 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006831 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006832
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006833 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6834 ", ifname=%s[%d], vlan_id=%d)",
6835 bss->ifname, if_nametoindex(bss->ifname),
6836 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006837 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6838 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Hai Shalomfdcde762020-04-02 11:19:20 -07006839 ((drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) &&
6840 nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006841 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
6842 nlmsg_free(msg);
6843 return -ENOBUFS;
6844 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006845
6846 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6847 if (ret < 0) {
6848 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6849 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
6850 MAC2STR(addr), ifname, vlan_id, ret,
6851 strerror(-ret));
6852 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006853 return ret;
6854}
6855
6856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006857static int i802_get_inact_sec(void *priv, const u8 *addr)
6858{
6859 struct hostap_sta_driver_data data;
6860 int ret;
6861
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08006862 os_memset(&data, 0, sizeof(data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006863 data.inactive_msec = (unsigned long) -1;
6864 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006865 if (ret == -ENOENT)
6866 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006867 if (ret || data.inactive_msec == (unsigned long) -1)
6868 return -1;
6869 return data.inactive_msec / 1000;
6870}
6871
6872
6873static int i802_sta_clear_stats(void *priv, const u8 *addr)
6874{
6875#if 0
6876 /* TODO */
6877#endif
6878 return 0;
6879}
6880
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006881
6882static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07006883 u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006884{
6885 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006886 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006887 struct ieee80211_mgmt mgmt;
Dmitry Shmidt29333592017-01-09 12:27:11 -08006888 u8 channel;
6889
6890 if (ieee80211_freq_to_chan(bss->freq, &channel) ==
6891 HOSTAPD_MODE_IEEE80211AD) {
6892 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6893 * disassociate the STA instead. */
6894 return i802_sta_disassoc(priv, own_addr, addr, reason);
6895 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006896
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006897 if (is_mesh_interface(drv->nlmode))
6898 return -1;
6899
Dmitry Shmidt04949592012-07-19 12:16:46 -07006900 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006901 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006903 memset(&mgmt, 0, sizeof(mgmt));
6904 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6905 WLAN_FC_STYPE_DEAUTH);
6906 memcpy(mgmt.da, addr, ETH_ALEN);
6907 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6908 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6909 mgmt.u.deauth.reason_code = host_to_le16(reason);
6910 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6911 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006912 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07006913 0, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006914}
6915
6916
6917static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07006918 u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006919{
6920 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006921 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006922 struct ieee80211_mgmt mgmt;
6923
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006924 if (is_mesh_interface(drv->nlmode))
6925 return -1;
6926
Dmitry Shmidt04949592012-07-19 12:16:46 -07006927 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006928 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006930 memset(&mgmt, 0, sizeof(mgmt));
6931 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6932 WLAN_FC_STYPE_DISASSOC);
6933 memcpy(mgmt.da, addr, ETH_ALEN);
6934 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6935 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6936 mgmt.u.disassoc.reason_code = host_to_le16(reason);
6937 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6938 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006939 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07006940 0, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006941}
6942
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006943
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006944static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
6945{
6946 char buf[200], *pos, *end;
6947 int i, res;
6948
6949 pos = buf;
6950 end = pos + sizeof(buf);
6951
6952 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006953 if (!drv->if_indices[i].ifindex)
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006954 continue;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006955 res = os_snprintf(pos, end - pos, " %d(%d)",
Hai Shalom81f62d82019-07-22 12:10:00 -07006956 drv->if_indices[i].ifindex,
6957 drv->if_indices[i].reason);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006958 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006959 break;
6960 pos += res;
6961 }
6962 *pos = '\0';
6963
6964 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
6965 drv->num_if_indices, buf);
6966}
6967
6968
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006969static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6970 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07006971{
6972 int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07006973 struct drv_nl80211_if_info *old;
Jouni Malinen75ecf522011-06-27 15:19:46 -07006974
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006975 wpa_printf(MSG_DEBUG,
6976 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6977 ifidx, ifidx_reason);
6978 if (have_ifidx(drv, ifidx, ifidx_reason)) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006979 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
6980 ifidx);
6981 return;
6982 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006983 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07006984 if (drv->if_indices[i].ifindex == 0) {
6985 drv->if_indices[i].ifindex = ifidx;
6986 drv->if_indices[i].reason = ifidx_reason;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006987 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006988 return;
6989 }
6990 }
6991
6992 if (drv->if_indices != drv->default_if_indices)
6993 old = drv->if_indices;
6994 else
6995 old = NULL;
6996
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006997 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006998 sizeof(*old));
Jouni Malinen75ecf522011-06-27 15:19:46 -07006999 if (!drv->if_indices) {
7000 if (!old)
7001 drv->if_indices = drv->default_if_indices;
7002 else
7003 drv->if_indices = old;
7004 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
7005 "interfaces");
7006 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
7007 return;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007008 }
7009 if (!old)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007010 os_memcpy(drv->if_indices, drv->default_if_indices,
7011 sizeof(drv->default_if_indices));
Hai Shalom81f62d82019-07-22 12:10:00 -07007012 drv->if_indices[drv->num_if_indices].ifindex = ifidx;
7013 drv->if_indices[drv->num_if_indices].reason = ifidx_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007014 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007015 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07007016}
7017
7018
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007019static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
7020 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007021{
7022 int i;
7023
7024 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07007025 if ((drv->if_indices[i].ifindex == ifidx ||
7026 ifidx == IFIDX_ANY) &&
7027 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007028 ifidx_reason == IFIDX_ANY)) {
Hai Shalom81f62d82019-07-22 12:10:00 -07007029 drv->if_indices[i].ifindex = 0;
7030 drv->if_indices[i].reason = 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007031 break;
7032 }
7033 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007034 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07007035}
7036
7037
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007038static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
7039 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007040{
7041 int i;
7042
7043 for (i = 0; i < drv->num_if_indices; i++)
Hai Shalom81f62d82019-07-22 12:10:00 -07007044 if (drv->if_indices[i].ifindex == ifidx &&
7045 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007046 ifidx_reason == IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07007047 return 1;
7048
7049 return 0;
7050}
7051
7052
7053static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07007054 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007055{
7056 struct i802_bss *bss = priv;
7057 struct wpa_driver_nl80211_data *drv = bss->drv;
7058 char name[IFNAMSIZ + 1];
Roshan Pius3a1667e2018-07-03 15:17:14 -07007059 union wpa_event_data event;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007060 int ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007061
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007062 ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
7063 if (ret >= (int) sizeof(name))
7064 wpa_printf(MSG_WARNING,
7065 "nl80211: WDS interface name was truncated");
7066 else if (ret < 0)
7067 return ret;
7068
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007069 if (ifname_wds)
7070 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
7071
Jouni Malinen75ecf522011-06-27 15:19:46 -07007072 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
7073 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
7074 if (val) {
7075 if (!if_nametoindex(name)) {
7076 if (nl80211_create_iface(drv, name,
7077 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007078 bss->addr, 1, NULL, NULL, 0) <
7079 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007080 return -1;
7081 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007082 linux_br_add_if(drv->global->ioctl_sock,
7083 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07007084 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007085
7086 os_memset(&event, 0, sizeof(event));
7087 event.wds_sta_interface.sta_addr = addr;
7088 event.wds_sta_interface.ifname = name;
7089 event.wds_sta_interface.istatus = INTERFACE_ADDED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07007090 wpa_supplicant_event(bss->ctx,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007091 EVENT_WDS_STA_INTERFACE_STATUS,
7092 &event);
Jouni Malinen75ecf522011-06-27 15:19:46 -07007093 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007094 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
7095 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
7096 "interface %s up", name);
7097 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07007098 return i802_set_sta_vlan(priv, addr, name, 0);
7099 } else {
Hai Shalom74f70d42019-02-11 14:42:39 -08007100 if (bridge_ifname &&
7101 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
7102 name) < 0)
7103 wpa_printf(MSG_INFO,
7104 "nl80211: Failed to remove interface %s from bridge %s: %s",
7105 name, bridge_ifname, strerror(errno));
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007106
Jouni Malinen75ecf522011-06-27 15:19:46 -07007107 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007108 nl80211_remove_iface(drv, if_nametoindex(name));
Roshan Pius3a1667e2018-07-03 15:17:14 -07007109 os_memset(&event, 0, sizeof(event));
7110 event.wds_sta_interface.sta_addr = addr;
7111 event.wds_sta_interface.ifname = name;
7112 event.wds_sta_interface.istatus = INTERFACE_REMOVED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07007113 wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007114 &event);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007115 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07007116 }
7117}
7118
7119
7120static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
7121{
7122 struct wpa_driver_nl80211_data *drv = eloop_ctx;
7123 struct sockaddr_ll lladdr;
7124 unsigned char buf[3000];
7125 int len;
7126 socklen_t fromlen = sizeof(lladdr);
7127
7128 len = recvfrom(sock, buf, sizeof(buf), 0,
7129 (struct sockaddr *)&lladdr, &fromlen);
7130 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007131 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
7132 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07007133 return;
7134 }
7135
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007136 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07007137 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
7138}
7139
7140
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007141static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
7142 struct i802_bss *bss,
7143 const char *brname, const char *ifname)
7144{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007145 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007146 char in_br[IFNAMSIZ];
7147
7148 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007149 br_ifindex = if_nametoindex(brname);
7150 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007151 /*
7152 * Bridge was configured, but the bridge device does
7153 * not exist. Try to add it now.
7154 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007155 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007156 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
7157 "bridge interface %s: %s",
7158 brname, strerror(errno));
7159 return -1;
7160 }
7161 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007162 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007163 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007164 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007165 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007166
7167 if (linux_br_get(in_br, ifname) == 0) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07007168 if (os_strcmp(in_br, brname) == 0) {
7169 bss->already_in_bridge = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007170 return 0; /* already in the bridge */
Hai Shalomc9e41a12018-07-31 14:41:42 -07007171 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007172
7173 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
7174 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007175 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
7176 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007177 wpa_printf(MSG_ERROR, "nl80211: Failed to "
7178 "remove interface %s from bridge "
7179 "%s: %s",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007180 ifname, in_br, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007181 return -1;
7182 }
7183 }
7184
7185 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
7186 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007187 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007188 wpa_printf(MSG_WARNING,
7189 "nl80211: Failed to add interface %s into bridge %s: %s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007190 ifname, brname, strerror(errno));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007191 /* Try to continue without the interface being in a bridge. This
7192 * may be needed for some cases, e.g., with Open vSwitch, where
7193 * an external component will need to handle bridge
7194 * configuration. */
7195 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007196 }
7197 bss->added_if_into_bridge = 1;
7198
7199 return 0;
7200}
7201
7202
7203static void *i802_init(struct hostapd_data *hapd,
7204 struct wpa_init_params *params)
7205{
7206 struct wpa_driver_nl80211_data *drv;
7207 struct i802_bss *bss;
7208 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007209 char master_ifname[IFNAMSIZ];
7210 int ifindex, br_ifindex = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007211 int br_added = 0;
7212
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007213 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
7214 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007215 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007216 if (bss == NULL)
7217 return NULL;
7218
7219 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007220
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007221 if (linux_br_get(master_ifname, params->ifname) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007222 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007223 params->ifname, master_ifname);
7224 br_ifindex = if_nametoindex(master_ifname);
7225 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
7226 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
7227 linux_master_get(master_ifname, params->ifname) == 0) {
7228 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
7229 params->ifname, master_ifname);
7230 /* start listening for EAPOL on the master interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007231 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007232
7233 /* check if master itself is under bridge */
7234 if (linux_br_get(master_ifname, master_ifname) == 0) {
7235 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
7236 master_ifname);
7237 br_ifindex = if_nametoindex(master_ifname);
7238 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
7239 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007240 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007241 master_ifname[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007242 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007244 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007246 for (i = 0; i < params->num_bridge; i++) {
7247 if (params->bridge[i]) {
7248 ifindex = if_nametoindex(params->bridge[i]);
7249 if (ifindex)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007250 add_ifidx(drv, ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007251 if (ifindex == br_ifindex)
7252 br_added = 1;
7253 }
7254 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007255
7256 /* start listening for EAPOL on the default AP interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007257 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007258
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007259 if (params->num_bridge && params->bridge[0]) {
7260 if (i802_check_bridge(drv, bss, params->bridge[0],
7261 params->ifname) < 0)
7262 goto failed;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007263 if (os_strcmp(params->bridge[0], master_ifname) != 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007264 br_added = 1;
7265 }
7266
7267 if (!br_added && br_ifindex &&
7268 (params->num_bridge == 0 || !params->bridge[0]))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007269 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007270
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007271#ifdef CONFIG_LIBNL3_ROUTE
Hai Shalomc9e41a12018-07-31 14:41:42 -07007272 if (bss->added_if_into_bridge || bss->already_in_bridge) {
Hai Shalomfdcde762020-04-02 11:19:20 -07007273 int err;
7274
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007275 drv->rtnl_sk = nl_socket_alloc();
7276 if (drv->rtnl_sk == NULL) {
7277 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
7278 goto failed;
7279 }
7280
Hai Shalomfdcde762020-04-02 11:19:20 -07007281 err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
7282 if (err) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007283 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -07007284 nl_geterror(err));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007285 goto failed;
7286 }
7287 }
7288#endif /* CONFIG_LIBNL3_ROUTE */
7289
Hai Shalomb755a2a2020-04-23 21:49:02 -07007290 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
7291 wpa_printf(MSG_DEBUG,
7292 "nl80211: Do not open EAPOL RX socket - using control port for RX");
7293 goto skip_eapol_sock;
7294 }
7295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007296 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
7297 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007298 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
7299 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007300 goto failed;
7301 }
7302
7303 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
7304 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007305 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007306 goto failed;
7307 }
Hai Shalomb755a2a2020-04-23 21:49:02 -07007308skip_eapol_sock:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007309
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007310 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
7311 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007312 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007313 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007314
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007315 memcpy(bss->addr, params->own_addr, ETH_ALEN);
7316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007317 return bss;
7318
7319failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007320 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007321 return NULL;
7322}
7323
7324
7325static void i802_deinit(void *priv)
7326{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007327 struct i802_bss *bss = priv;
7328 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007329}
7330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007331
7332static enum nl80211_iftype wpa_driver_nl80211_if_type(
7333 enum wpa_driver_if_type type)
7334{
7335 switch (type) {
7336 case WPA_IF_STATION:
7337 return NL80211_IFTYPE_STATION;
7338 case WPA_IF_P2P_CLIENT:
7339 case WPA_IF_P2P_GROUP:
7340 return NL80211_IFTYPE_P2P_CLIENT;
7341 case WPA_IF_AP_VLAN:
7342 return NL80211_IFTYPE_AP_VLAN;
7343 case WPA_IF_AP_BSS:
7344 return NL80211_IFTYPE_AP;
7345 case WPA_IF_P2P_GO:
7346 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007347 case WPA_IF_P2P_DEVICE:
7348 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007349 case WPA_IF_MESH:
7350 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007351 default:
7352 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007353 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007354}
7355
7356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007357static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
7358{
7359 struct wpa_driver_nl80211_data *drv;
7360 dl_list_for_each(drv, &global->interfaces,
7361 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007362 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007363 return 1;
7364 }
7365 return 0;
7366}
7367
7368
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007369static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007370{
7371 unsigned int idx;
7372
7373 if (!drv->global)
7374 return -1;
7375
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007376 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007377 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007378 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007379 new_addr[0] ^= idx << 2;
7380 if (!nl80211_addr_in_use(drv->global, new_addr))
7381 break;
7382 }
7383 if (idx == 64)
7384 return -1;
7385
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007386 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007387 MACSTR, MAC2STR(new_addr));
7388
7389 return 0;
7390}
7391
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007392
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007393struct wdev_info {
7394 u64 wdev_id;
7395 int wdev_id_set;
7396 u8 macaddr[ETH_ALEN];
7397};
7398
7399static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
7400{
7401 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7402 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7403 struct wdev_info *wi = arg;
7404
7405 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7406 genlmsg_attrlen(gnlh, 0), NULL);
7407 if (tb[NL80211_ATTR_WDEV]) {
7408 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
7409 wi->wdev_id_set = 1;
7410 }
7411
7412 if (tb[NL80211_ATTR_MAC])
7413 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
7414 ETH_ALEN);
7415
7416 return NL_SKIP;
7417}
7418
7419
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007420static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
7421 const char *ifname, const u8 *addr,
7422 void *bss_ctx, void **drv_priv,
7423 char *force_ifname, u8 *if_addr,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007424 const char *bridge, int use_existing,
7425 int setup_ap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007426{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007427 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007428 struct i802_bss *bss = priv;
7429 struct wpa_driver_nl80211_data *drv = bss->drv;
7430 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007431 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007432
7433 if (addr)
7434 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007435 nlmode = wpa_driver_nl80211_if_type(type);
7436 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
7437 struct wdev_info p2pdev_info;
7438
7439 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
7440 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
7441 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007442 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007443 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
7444 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
7445 ifname);
7446 return -1;
7447 }
7448
7449 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
7450 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
7451 if (!is_zero_ether_addr(p2pdev_info.macaddr))
7452 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
7453 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
7454 ifname,
7455 (long long unsigned int) p2pdev_info.wdev_id);
7456 } else {
7457 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007458 0, NULL, NULL, use_existing);
7459 if (use_existing && ifidx == -ENFILE) {
7460 added = 0;
7461 ifidx = if_nametoindex(ifname);
7462 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007463 return -1;
7464 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007465 }
7466
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007467 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007468 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007469 os_memcpy(if_addr, bss->addr, ETH_ALEN);
7470 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007471 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007472 if (added)
7473 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007474 return -1;
7475 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007476 }
7477
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007478 if (!addr &&
7479 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007480 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
7481 type == WPA_IF_STATION)) {
7482 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007483 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007484
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007485 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007486 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007487 if (added)
7488 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007489 return -1;
7490 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007491 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007492 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07007493 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007494 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007495 if (added)
7496 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007497 return -1;
7498 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007499 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007500 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007501 if (added)
7502 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007503 return -1;
7504 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007505 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007506 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007507 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007508
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007509 if (type == WPA_IF_AP_BSS && setup_ap) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007510 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
7511 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007512 if (added)
7513 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007514 return -1;
7515 }
7516
7517 if (bridge &&
7518 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
7519 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
7520 "interface %s to a bridge %s",
7521 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007522 if (added)
7523 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007524 os_free(new_bss);
7525 return -1;
7526 }
7527
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007528 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
7529 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07007530 if (added)
7531 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007532 os_free(new_bss);
7533 return -1;
7534 }
7535 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007536 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007537 new_bss->ifindex = ifidx;
7538 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007539 new_bss->next = drv->first_bss->next;
7540 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007541 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007542 new_bss->added_if = added;
7543 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007544 if (drv_priv)
7545 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007546 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007547
7548 /* Subscribe management frames for this WPA_IF_AP_BSS */
7549 if (nl80211_setup_ap(new_bss))
7550 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007551 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007552
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007553 if (drv->global)
7554 drv->global->if_add_ifindex = ifidx;
7555
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007556 /*
7557 * Some virtual interfaces need to process EAPOL packets and events on
7558 * the parent interface. This is used mainly with hostapd.
7559 */
7560 if (ifidx > 0 &&
7561 (drv->hostapd ||
7562 nlmode == NL80211_IFTYPE_AP_VLAN ||
7563 nlmode == NL80211_IFTYPE_WDS ||
7564 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007565 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007567 return 0;
7568}
7569
7570
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007571static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007572 enum wpa_driver_if_type type,
7573 const char *ifname)
7574{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007575 struct wpa_driver_nl80211_data *drv = bss->drv;
7576 int ifindex = if_nametoindex(ifname);
7577
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007578 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
7579 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007580 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07007581 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007582 else if (ifindex > 0 && !bss->added_if) {
7583 struct wpa_driver_nl80211_data *drv2;
7584 dl_list_for_each(drv2, &drv->global->interfaces,
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007585 struct wpa_driver_nl80211_data, list) {
7586 del_ifidx(drv2, ifindex, IFIDX_ANY);
7587 del_ifidx(drv2, IFIDX_ANY, ifindex);
7588 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07007589 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007590
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007591 if (type != WPA_IF_AP_BSS)
7592 return 0;
7593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007594 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007595 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
7596 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007597 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7598 "interface %s from bridge %s: %s",
7599 bss->ifname, bss->brname, strerror(errno));
7600 }
7601 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007602 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007603 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7604 "bridge %s: %s",
7605 bss->brname, strerror(errno));
7606 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007607
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007608 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007609 struct i802_bss *tbss;
7610
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007611 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
7612 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007613 if (tbss->next == bss) {
7614 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007615 /* Unsubscribe management frames */
7616 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007617 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007618 if (!bss->added_if)
7619 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007620 os_free(bss);
7621 bss = NULL;
7622 break;
7623 }
7624 }
7625 if (bss)
7626 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
7627 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007628 } else {
7629 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
7630 nl80211_teardown_ap(bss);
7631 if (!bss->added_if && !drv->first_bss->next)
Paul Stewart092955c2017-02-06 09:13:09 -08007632 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08007633 nl80211_destroy_bss(bss);
7634 if (!bss->added_if)
7635 i802_set_iface_flags(bss, 0);
7636 if (drv->first_bss->next) {
7637 drv->first_bss = drv->first_bss->next;
7638 drv->ctx = drv->first_bss->ctx;
7639 os_free(bss);
7640 } else {
7641 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
7642 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007643 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007644
7645 return 0;
7646}
7647
7648
7649static int cookie_handler(struct nl_msg *msg, void *arg)
7650{
7651 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7652 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7653 u64 *cookie = arg;
7654 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7655 genlmsg_attrlen(gnlh, 0), NULL);
7656 if (tb[NL80211_ATTR_COOKIE])
7657 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
7658 return NL_SKIP;
7659}
7660
7661
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007662static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007663 unsigned int freq, unsigned int wait,
7664 const u8 *buf, size_t buf_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07007665 int save_cookie, int no_cck, int no_ack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007666 int offchanok, const u16 *csa_offs,
7667 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007668{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007669 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007670 struct nl_msg *msg;
7671 u64 cookie;
7672 int ret = -1;
7673
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07007674 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007675 "no_ack=%d offchanok=%d",
7676 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007677 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007678
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007679 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
7680 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
7681 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
7682 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7683 drv->test_use_roc_tx) &&
7684 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
7685 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
7686 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007687 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
7688 csa_offs_len * sizeof(u16), csa_offs)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007689 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
7690 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007691
7692 cookie = 0;
7693 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7694 msg = NULL;
7695 if (ret) {
7696 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007697 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
7698 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007699 } else {
7700 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
7701 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
7702 (long long unsigned int) cookie);
7703
Hai Shalomfdcde762020-04-02 11:19:20 -07007704 if (save_cookie)
7705 drv->send_frame_cookie = no_ack ? (u64) -1 : cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007706
Hai Shalomfdcde762020-04-02 11:19:20 -07007707 if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007708 wpa_printf(MSG_DEBUG,
Hai Shalomfdcde762020-04-02 11:19:20 -07007709 "nl80211: Drop oldest pending send frame cookie 0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007710 (long long unsigned int)
Hai Shalomfdcde762020-04-02 11:19:20 -07007711 drv->send_frame_cookies[0]);
7712 os_memmove(&drv->send_frame_cookies[0],
7713 &drv->send_frame_cookies[1],
7714 (MAX_SEND_FRAME_COOKIES - 1) *
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007715 sizeof(u64));
Hai Shalomfdcde762020-04-02 11:19:20 -07007716 drv->num_send_frame_cookies--;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007717 }
Hai Shalomfdcde762020-04-02 11:19:20 -07007718 drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie;
7719 drv->num_send_frame_cookies++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007720 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007721
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007722fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007723 nlmsg_free(msg);
7724 return ret;
7725}
7726
7727
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007728static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
7729 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007730 unsigned int wait_time,
7731 const u8 *dst, const u8 *src,
7732 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007733 const u8 *data, size_t data_len,
7734 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007735{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007736 struct wpa_driver_nl80211_data *drv = bss->drv;
7737 int ret = -1;
7738 u8 *buf;
7739 struct ieee80211_hdr *hdr;
Hai Shalomfdcde762020-04-02 11:19:20 -07007740 int offchanok = 1;
7741
7742 if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq)
7743 offchanok = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007744
7745 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Hai Shalomfdcde762020-04-02 11:19:20 -07007746 "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)",
7747 drv->ifindex, freq, wait_time, no_cck, offchanok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007748
7749 buf = os_zalloc(24 + data_len);
7750 if (buf == NULL)
7751 return ret;
7752 os_memcpy(buf + 24, data, data_len);
7753 hdr = (struct ieee80211_hdr *) buf;
7754 hdr->frame_control =
7755 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
7756 os_memcpy(hdr->addr1, dst, ETH_ALEN);
7757 os_memcpy(hdr->addr2, src, ETH_ALEN);
7758 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
7759
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007760 if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) {
7761 wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR,
7762 MAC2STR(src));
7763 os_memcpy(bss->rand_addr, src, ETH_ALEN);
7764 } else {
7765 os_memset(bss->rand_addr, 0, ETH_ALEN);
7766 }
7767
Dmitry Shmidt56052862013-10-04 10:23:25 -07007768 if (is_ap_interface(drv->nlmode) &&
7769 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7770 (int) freq == bss->freq || drv->device_ap_sme ||
7771 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007772 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07007773 0, freq, no_cck, offchanok,
7774 wait_time, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007775 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007776 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007777 24 + data_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07007778 1, no_cck, 0, offchanok, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007779
7780 os_free(buf);
7781 return ret;
7782}
7783
7784
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007785static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007786{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007787 struct wpa_driver_nl80211_data *drv = bss->drv;
7788 struct nl_msg *msg;
7789 int ret;
7790
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08007791 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007792 (long long unsigned int) cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007793 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007794 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007795 nlmsg_free(msg);
7796 return;
7797 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007798
7799 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007800 if (ret)
7801 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
7802 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007803}
7804
7805
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007806static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
7807{
7808 struct i802_bss *bss = priv;
7809 struct wpa_driver_nl80211_data *drv = bss->drv;
7810 unsigned int i;
7811 u64 cookie;
7812
7813 /* Cancel the last pending TX cookie */
Hai Shalomfdcde762020-04-02 11:19:20 -07007814 nl80211_frame_wait_cancel(bss, drv->send_frame_cookie);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007815
7816 /*
7817 * Cancel the other pending TX cookies, if any. This is needed since
7818 * the driver may keep a list of all pending offchannel TX operations
7819 * and free up the radio only once they have expired or cancelled.
7820 */
Hai Shalomfdcde762020-04-02 11:19:20 -07007821 for (i = drv->num_send_frame_cookies; i > 0; i--) {
7822 cookie = drv->send_frame_cookies[i - 1];
7823 if (cookie != drv->send_frame_cookie)
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007824 nl80211_frame_wait_cancel(bss, cookie);
7825 }
Hai Shalomfdcde762020-04-02 11:19:20 -07007826 drv->num_send_frame_cookies = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007827}
7828
7829
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007830static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
7831 unsigned int duration)
7832{
7833 struct i802_bss *bss = priv;
7834 struct wpa_driver_nl80211_data *drv = bss->drv;
7835 struct nl_msg *msg;
7836 int ret;
7837 u64 cookie;
7838
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007839 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
7840 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
7841 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
7842 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007843 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007844 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007845
7846 cookie = 0;
7847 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7848 if (ret == 0) {
7849 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
7850 "0x%llx for freq=%u MHz duration=%u",
7851 (long long unsigned int) cookie, freq, duration);
7852 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007853 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007854 return 0;
7855 }
7856 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
7857 "(freq=%d duration=%u): %d (%s)",
7858 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007859 return -1;
7860}
7861
7862
7863static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
7864{
7865 struct i802_bss *bss = priv;
7866 struct wpa_driver_nl80211_data *drv = bss->drv;
7867 struct nl_msg *msg;
7868 int ret;
7869
7870 if (!drv->pending_remain_on_chan) {
7871 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
7872 "to cancel");
7873 return -1;
7874 }
7875
7876 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
7877 "0x%llx",
7878 (long long unsigned int) drv->remain_on_chan_cookie);
7879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007880 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
7881 if (!msg ||
7882 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
7883 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007884 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007885 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007886
7887 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7888 if (ret == 0)
7889 return 0;
7890 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
7891 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007892 return -1;
7893}
7894
7895
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007896static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007897{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007898 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07007899
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007900 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007901 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07007902 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
7903 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007904 /*
7905 * Do not disable Probe Request reporting that was
7906 * enabled in nl80211_setup_ap().
7907 */
7908 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
7909 "Probe Request reporting nl_preq=%p while "
7910 "in AP mode", bss->nl_preq);
7911 } else if (bss->nl_preq) {
7912 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
7913 "reporting nl_preq=%p", bss->nl_preq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07007914 nl80211_destroy_eloop_handle(&bss->nl_preq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007915 }
7916 return 0;
7917 }
7918
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007919 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007920 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007921 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007922 return 0;
7923 }
7924
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007925 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
7926 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007927 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007928 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
7929 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007930
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007931 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007932 (WLAN_FC_TYPE_MGMT << 2) |
7933 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007934 NULL, 0) < 0)
7935 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07007936
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007937 nl80211_register_eloop_read(&bss->nl_preq,
7938 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007939 bss->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007940
7941 return 0;
7942
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007943 out_err:
7944 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007945 return -1;
7946}
7947
7948
7949static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
7950 int ifindex, int disabled)
7951{
7952 struct nl_msg *msg;
7953 struct nlattr *bands, *band;
7954 int ret;
7955
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007956 wpa_printf(MSG_DEBUG,
7957 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7958 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
7959 "no NL80211_TXRATE_LEGACY constraint");
7960
7961 msg = nl80211_ifindex_msg(drv, ifindex, 0,
7962 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007963 if (!msg)
7964 return -1;
7965
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007966 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
7967 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007968 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007969
7970 /*
7971 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7972 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7973 * rates. All 5 GHz rates are left enabled.
7974 */
7975 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007976 if (!band ||
7977 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
7978 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7979 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007980 nla_nest_end(msg, band);
7981
7982 nla_nest_end(msg, bands);
7983
7984 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007985 if (ret) {
7986 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
7987 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007988 } else
7989 drv->disabled_11b_rates = disabled;
7990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007991 return ret;
7992
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007993fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007994 nlmsg_free(msg);
7995 return -1;
7996}
7997
7998
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007999static int wpa_driver_nl80211_deinit_ap(void *priv)
8000{
8001 struct i802_bss *bss = priv;
8002 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008003 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008004 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008005 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008006 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008007
8008 /*
8009 * If the P2P GO interface was dynamically added, then it is
8010 * possible that the interface change to station is not possible.
8011 */
8012 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
8013 return 0;
8014
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008015 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008016}
8017
8018
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008019static int wpa_driver_nl80211_stop_ap(void *priv)
8020{
8021 struct i802_bss *bss = priv;
8022 struct wpa_driver_nl80211_data *drv = bss->drv;
8023 if (!is_ap_interface(drv->nlmode))
8024 return -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008025 wpa_driver_nl80211_del_beacon(bss);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008026 bss->beacon_set = 0;
8027 return 0;
8028}
8029
8030
Dmitry Shmidt04949592012-07-19 12:16:46 -07008031static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
8032{
8033 struct i802_bss *bss = priv;
8034 struct wpa_driver_nl80211_data *drv = bss->drv;
8035 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
8036 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008037
8038 /*
8039 * If the P2P Client interface was dynamically added, then it is
8040 * possible that the interface change to station is not possible.
8041 */
8042 if (bss->if_dynamic)
8043 return 0;
8044
Dmitry Shmidt04949592012-07-19 12:16:46 -07008045 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
8046}
8047
8048
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008049static void wpa_driver_nl80211_resume(void *priv)
8050{
8051 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008052 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008053
8054 if (i802_set_iface_flags(bss, 1))
8055 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008056
8057 if (is_p2p_net_interface(nlmode))
8058 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008059}
8060
8061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008062static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
8063{
8064 struct i802_bss *bss = priv;
8065 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07008066 struct nl_msg *msg;
8067 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008068
8069 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
8070 "hysteresis=%d", threshold, hysteresis);
8071
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008072 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
8073 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
8074 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
8075 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
8076 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008077 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008078 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07008079 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008080
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008081 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008082}
8083
8084
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008085static int get_channel_width(struct nl_msg *msg, void *arg)
8086{
8087 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8088 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8089 struct wpa_signal_info *sig_change = arg;
8090
8091 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8092 genlmsg_attrlen(gnlh, 0), NULL);
8093
8094 sig_change->center_frq1 = -1;
8095 sig_change->center_frq2 = -1;
8096 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
8097
8098 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
8099 sig_change->chanwidth = convert2width(
8100 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
8101 if (tb[NL80211_ATTR_CENTER_FREQ1])
8102 sig_change->center_frq1 =
8103 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
8104 if (tb[NL80211_ATTR_CENTER_FREQ2])
8105 sig_change->center_frq2 =
8106 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
8107 }
8108
8109 return NL_SKIP;
8110}
8111
8112
8113static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
8114 struct wpa_signal_info *sig)
8115{
8116 struct nl_msg *msg;
8117
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008118 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008119 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008120}
8121
8122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008123static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
8124{
8125 struct i802_bss *bss = priv;
8126 struct wpa_driver_nl80211_data *drv = bss->drv;
8127 int res;
8128
8129 os_memset(si, 0, sizeof(*si));
8130 res = nl80211_get_link_signal(drv, si);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008131 if (res) {
8132 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
8133 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
8134 return res;
8135 si->current_signal = 0;
8136 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008137
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008138 res = nl80211_get_channel_width(drv, si);
8139 if (res != 0)
8140 return res;
8141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008142 return nl80211_get_link_noise(drv, si);
8143}
8144
8145
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008146static int nl80211_set_param(void *priv, const char *param)
8147{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008148 struct i802_bss *bss = priv;
8149 struct wpa_driver_nl80211_data *drv = bss->drv;
8150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008151 if (param == NULL)
8152 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008153 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008154
8155#ifdef CONFIG_P2P
8156 if (os_strstr(param, "use_p2p_group_interface=1")) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008157 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
8158 "interface");
8159 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
8160 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
8161 }
8162#endif /* CONFIG_P2P */
8163
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008164 if (os_strstr(param, "use_monitor=1"))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008165 drv->use_monitor = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008166
8167 if (os_strstr(param, "force_connect_cmd=1")) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008168 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008169 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008170 }
8171
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008172 if (os_strstr(param, "force_bss_selection=1"))
8173 drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
8174
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08008175 if (os_strstr(param, "no_offchannel_tx=1")) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08008176 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
8177 drv->test_use_roc_tx = 1;
8178 }
8179
Hai Shalomb755a2a2020-04-23 21:49:02 -07008180 if (os_strstr(param, "control_port=0")) {
Hai Shalomfdcde762020-04-02 11:19:20 -07008181 drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008182 drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_RX;
8183 }
8184
8185 if (os_strstr(param, "control_port_ap=1"))
8186 drv->control_port_ap = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07008187
8188 if (os_strstr(param, "full_ap_client_state=0"))
8189 drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
8190
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008191 return 0;
8192}
8193
8194
Dmitry Shmidte4663042016-04-04 10:07:49 -07008195static void * nl80211_global_init(void *ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008196{
8197 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008198 struct netlink_config *cfg;
8199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008200 global = os_zalloc(sizeof(*global));
8201 if (global == NULL)
8202 return NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -07008203 global->ctx = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008204 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008205 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008206 global->if_add_ifindex = -1;
8207
8208 cfg = os_zalloc(sizeof(*cfg));
8209 if (cfg == NULL)
8210 goto err;
8211
8212 cfg->ctx = global;
8213 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
8214 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
8215 global->netlink = netlink_init(cfg);
8216 if (global->netlink == NULL) {
8217 os_free(cfg);
8218 goto err;
8219 }
8220
8221 if (wpa_driver_nl80211_init_nl_global(global) < 0)
8222 goto err;
8223
8224 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
8225 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008226 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
8227 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008228 goto err;
8229 }
8230
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008231 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008232
8233err:
8234 nl80211_global_deinit(global);
8235 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008236}
8237
8238
8239static void nl80211_global_deinit(void *priv)
8240{
8241 struct nl80211_global *global = priv;
8242 if (global == NULL)
8243 return;
8244 if (!dl_list_empty(&global->interfaces)) {
8245 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
8246 "nl80211_global_deinit",
8247 dl_list_len(&global->interfaces));
8248 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008249
8250 if (global->netlink)
8251 netlink_deinit(global->netlink);
8252
8253 nl_destroy_handles(&global->nl);
8254
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008255 if (global->nl_event)
Roshan Pius3a1667e2018-07-03 15:17:14 -07008256 nl80211_destroy_eloop_handle(&global->nl_event, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008257
8258 nl_cb_put(global->nl_cb);
8259
8260 if (global->ioctl_sock >= 0)
8261 close(global->ioctl_sock);
8262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008263 os_free(global);
8264}
8265
8266
8267static const char * nl80211_get_radio_name(void *priv)
8268{
8269 struct i802_bss *bss = priv;
8270 struct wpa_driver_nl80211_data *drv = bss->drv;
8271 return drv->phyname;
8272}
8273
8274
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008275static int nl80211_pmkid(struct i802_bss *bss, int cmd,
8276 struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008277{
8278 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008279 const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */
Jouni Malinen75ecf522011-06-27 15:19:46 -07008280
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008281 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008282 (params->pmkid &&
8283 nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) ||
8284 (params->bssid &&
8285 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) ||
8286 (params->ssid_len &&
8287 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
8288 (params->fils_cache_id &&
8289 nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2,
8290 params->fils_cache_id)) ||
Hai Shalomfdcde762020-04-02 11:19:20 -07008291 (params->pmk_lifetime &&
8292 nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME,
8293 params->pmk_lifetime)) ||
8294 (params->pmk_reauth_threshold &&
8295 nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD,
8296 params->pmk_reauth_threshold)) ||
Hai Shalom021b0b52019-04-10 11:17:58 -07008297 (cmd != NL80211_CMD_DEL_PMKSA &&
8298 params->pmk_len && params->pmk_len <= PMK_MAX_LEN &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008299 nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) {
Hai Shalom74f70d42019-02-11 14:42:39 -08008300 nl80211_nlmsg_clear(msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008301 nlmsg_free(msg);
8302 return -ENOBUFS;
8303 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07008304
Hai Shalom74f70d42019-02-11 14:42:39 -08008305 return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008306}
8307
8308
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008309static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008310{
8311 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008312 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008313
8314 if (params->bssid)
8315 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR,
8316 MAC2STR(params->bssid));
8317 else if (params->fils_cache_id && params->ssid_len) {
8318 wpa_printf(MSG_DEBUG,
8319 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
8320 params->fils_cache_id[0], params->fils_cache_id[1],
8321 wpa_ssid_txt(params->ssid, params->ssid_len));
8322 }
8323
Roshan Pius3a1667e2018-07-03 15:17:14 -07008324 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params);
8325 if (ret < 0) {
8326 wpa_printf(MSG_DEBUG,
8327 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
8328 ret, strerror(-ret));
8329 }
8330
8331 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008332}
8333
8334
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008335static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008336{
8337 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008338 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008339
8340 if (params->bssid)
8341 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
8342 MAC2STR(params->bssid));
8343 else if (params->fils_cache_id && params->ssid_len) {
8344 wpa_printf(MSG_DEBUG,
8345 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
8346 params->fils_cache_id[0], params->fils_cache_id[1],
8347 wpa_ssid_txt(params->ssid, params->ssid_len));
8348 }
8349
Roshan Pius3a1667e2018-07-03 15:17:14 -07008350 ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params);
8351 if (ret < 0) {
8352 wpa_printf(MSG_DEBUG,
8353 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
8354 ret, strerror(-ret));
8355 }
8356
8357 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008358}
8359
8360
8361static int nl80211_flush_pmkid(void *priv)
8362{
8363 struct i802_bss *bss = priv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008364 struct nl_msg *msg;
8365
Jouni Malinen75ecf522011-06-27 15:19:46 -07008366 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008367 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA);
8368 if (!msg)
8369 return -ENOBUFS;
8370 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008371}
8372
8373
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008374static void clean_survey_results(struct survey_results *survey_results)
8375{
8376 struct freq_survey *survey, *tmp;
8377
8378 if (dl_list_empty(&survey_results->survey_list))
8379 return;
8380
8381 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
8382 struct freq_survey, list) {
8383 dl_list_del(&survey->list);
8384 os_free(survey);
8385 }
8386}
8387
8388
8389static void add_survey(struct nlattr **sinfo, u32 ifidx,
8390 struct dl_list *survey_list)
8391{
8392 struct freq_survey *survey;
8393
8394 survey = os_zalloc(sizeof(struct freq_survey));
8395 if (!survey)
8396 return;
8397
8398 survey->ifidx = ifidx;
8399 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8400 survey->filled = 0;
8401
8402 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
8403 survey->nf = (int8_t)
8404 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
8405 survey->filled |= SURVEY_HAS_NF;
8406 }
8407
8408 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
8409 survey->channel_time =
8410 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
8411 survey->filled |= SURVEY_HAS_CHAN_TIME;
8412 }
8413
8414 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
8415 survey->channel_time_busy =
8416 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
8417 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
8418 }
8419
8420 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
8421 survey->channel_time_rx =
8422 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
8423 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
8424 }
8425
8426 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
8427 survey->channel_time_tx =
8428 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
8429 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
8430 }
8431
8432 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)",
8433 survey->freq,
8434 survey->nf,
8435 (unsigned long int) survey->channel_time,
8436 (unsigned long int) survey->channel_time_busy,
8437 (unsigned long int) survey->channel_time_tx,
8438 (unsigned long int) survey->channel_time_rx,
8439 survey->filled);
8440
8441 dl_list_add_tail(survey_list, &survey->list);
8442}
8443
8444
8445static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
8446 unsigned int freq_filter)
8447{
8448 if (!freq_filter)
8449 return 1;
8450
8451 return freq_filter == surveyed_freq;
8452}
8453
8454
8455static int survey_handler(struct nl_msg *msg, void *arg)
8456{
8457 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8458 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8459 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
8460 struct survey_results *survey_results;
8461 u32 surveyed_freq = 0;
8462 u32 ifidx;
8463
8464 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
8465 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
8466 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
8467 };
8468
8469 survey_results = (struct survey_results *) arg;
8470
8471 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8472 genlmsg_attrlen(gnlh, 0), NULL);
8473
Dmitry Shmidt97672262014-02-03 13:02:54 -08008474 if (!tb[NL80211_ATTR_IFINDEX])
8475 return NL_SKIP;
8476
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008477 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
8478
8479 if (!tb[NL80211_ATTR_SURVEY_INFO])
8480 return NL_SKIP;
8481
8482 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
8483 tb[NL80211_ATTR_SURVEY_INFO],
8484 survey_policy))
8485 return NL_SKIP;
8486
8487 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
8488 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
8489 return NL_SKIP;
8490 }
8491
8492 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8493
8494 if (!check_survey_ok(sinfo, surveyed_freq,
8495 survey_results->freq_filter))
8496 return NL_SKIP;
8497
8498 if (survey_results->freq_filter &&
8499 survey_results->freq_filter != surveyed_freq) {
8500 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
8501 surveyed_freq);
8502 return NL_SKIP;
8503 }
8504
8505 add_survey(sinfo, ifidx, &survey_results->survey_list);
8506
8507 return NL_SKIP;
8508}
8509
8510
8511static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
8512{
8513 struct i802_bss *bss = priv;
8514 struct wpa_driver_nl80211_data *drv = bss->drv;
8515 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008516 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008517 union wpa_event_data data;
8518 struct survey_results *survey_results;
8519
8520 os_memset(&data, 0, sizeof(data));
8521 survey_results = &data.survey_results;
8522
8523 dl_list_init(&survey_results->survey_list);
8524
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008525 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008526 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008527 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008528
8529 if (freq)
8530 data.survey_results.freq_filter = freq;
8531
8532 do {
8533 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
8534 err = send_and_recv_msgs(drv, msg, survey_handler,
8535 survey_results);
8536 } while (err > 0);
8537
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008538 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008539 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008540 else
8541 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008542
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008543 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008544 return err;
8545}
8546
8547
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008548static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
8549 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008550 const u8 *replay_ctr)
8551{
8552 struct i802_bss *bss = priv;
8553 struct wpa_driver_nl80211_data *drv = bss->drv;
8554 struct nlattr *replay_nested;
8555 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008556 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008557
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008558 if (!drv->set_rekey_offload)
8559 return;
8560
8561 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008562 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
8563 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08008564 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008565 (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008566 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
8567 replay_ctr)) {
8568 nl80211_nlmsg_clear(msg);
8569 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008570 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008571 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008572
8573 nla_nest_end(msg, replay_nested);
8574
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008575 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
8576 if (ret == -EOPNOTSUPP) {
8577 wpa_printf(MSG_DEBUG,
8578 "nl80211: Driver does not support rekey offload");
8579 drv->set_rekey_offload = 0;
8580 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008581}
8582
8583
8584static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
8585 const u8 *addr, int qos)
8586{
8587 /* send data frame to poll STA and check whether
8588 * this frame is ACKed */
8589 struct {
8590 struct ieee80211_hdr hdr;
8591 u16 qos_ctl;
8592 } STRUCT_PACKED nulldata;
8593 size_t size;
8594
8595 /* Send data frame to poll STA and check whether this frame is ACKed */
8596
8597 os_memset(&nulldata, 0, sizeof(nulldata));
8598
8599 if (qos) {
8600 nulldata.hdr.frame_control =
8601 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8602 WLAN_FC_STYPE_QOS_NULL);
8603 size = sizeof(nulldata);
8604 } else {
8605 nulldata.hdr.frame_control =
8606 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8607 WLAN_FC_STYPE_NULLFUNC);
8608 size = sizeof(struct ieee80211_hdr);
8609 }
8610
8611 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
8612 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
8613 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
8614 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
8615
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008616 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07008617 0, 0, NULL, 0, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008618 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
8619 "send poll frame");
8620}
8621
8622static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
8623 int qos)
8624{
8625 struct i802_bss *bss = priv;
8626 struct wpa_driver_nl80211_data *drv = bss->drv;
8627 struct nl_msg *msg;
Hai Shalom5f92bc92019-04-18 11:54:11 -07008628 u64 cookie;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008629 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008630
8631 if (!drv->poll_command_supported) {
8632 nl80211_send_null_frame(bss, own_addr, addr, qos);
8633 return;
8634 }
8635
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008636 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
8637 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8638 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008639 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008640 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008641
Hai Shalom5f92bc92019-04-18 11:54:11 -07008642 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008643 if (ret < 0) {
8644 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
8645 MACSTR " failed: ret=%d (%s)",
8646 MAC2STR(addr), ret, strerror(-ret));
Hai Shalom5f92bc92019-04-18 11:54:11 -07008647 } else {
8648 wpa_printf(MSG_DEBUG,
8649 "nl80211: Client probe request addr=" MACSTR
8650 " cookie=%llu", MAC2STR(addr),
8651 (long long unsigned int) cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008652 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008653}
8654
8655
8656static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
8657{
8658 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008659 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008660
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008661 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
8662 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
8663 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
8664 nlmsg_free(msg);
8665 return -ENOBUFS;
8666 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07008667
8668 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
8669 if (ret < 0) {
8670 wpa_printf(MSG_DEBUG,
8671 "nl80211: Setting PS state %s failed: %d (%s)",
8672 enabled ? "enabled" : "disabled",
8673 ret, strerror(-ret));
8674 }
8675 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008676}
8677
8678
8679static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
8680 int ctwindow)
8681{
8682 struct i802_bss *bss = priv;
8683
8684 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
8685 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
8686
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008687 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08008688#ifdef ANDROID_P2P
8689 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008690#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008691 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008692#endif /* ANDROID_P2P */
8693 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008694
8695 if (legacy_ps == -1)
8696 return 0;
8697 if (legacy_ps != 0 && legacy_ps != 1)
8698 return -1; /* Not yet supported */
8699
8700 return nl80211_set_power_save(bss, legacy_ps);
8701}
8702
8703
Dmitry Shmidt051af732013-10-22 13:52:46 -07008704static int nl80211_start_radar_detection(void *priv,
8705 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008706{
8707 struct i802_bss *bss = priv;
8708 struct wpa_driver_nl80211_data *drv = bss->drv;
8709 struct nl_msg *msg;
8710 int ret;
8711
Hai Shalom81f62d82019-07-22 12:10:00 -07008712 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)",
8713 freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07008714 freq->bandwidth, freq->center_freq1, freq->center_freq2);
8715
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008716 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
8717 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
8718 "detection");
8719 return -1;
8720 }
8721
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008722 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
8723 nl80211_put_freq_params(msg, freq) < 0) {
8724 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008725 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008726 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008727
8728 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8729 if (ret == 0)
8730 return 0;
8731 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
8732 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008733 return -1;
8734}
8735
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008736#ifdef CONFIG_TDLS
8737
8738static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
8739 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07008740 u32 peer_capab, int initiator, const u8 *buf,
8741 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008742{
8743 struct i802_bss *bss = priv;
8744 struct wpa_driver_nl80211_data *drv = bss->drv;
8745 struct nl_msg *msg;
8746
8747 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8748 return -EOPNOTSUPP;
8749
8750 if (!dst)
8751 return -EINVAL;
8752
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008753 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
8754 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
8755 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
8756 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
8757 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
8758 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008759 if (peer_capab) {
8760 /*
8761 * The internal enum tdls_peer_capability definition is
8762 * currently identical with the nl80211 enum
8763 * nl80211_tdls_peer_capability, so no conversion is needed
8764 * here.
8765 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008766 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
8767 peer_capab))
8768 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008769 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008770 if ((initiator &&
8771 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
8772 nla_put(msg, NL80211_ATTR_IE, len, buf))
8773 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008774
8775 return send_and_recv_msgs(drv, msg, NULL, NULL);
8776
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008777fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008778 nlmsg_free(msg);
8779 return -ENOBUFS;
8780}
8781
8782
8783static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
8784{
8785 struct i802_bss *bss = priv;
8786 struct wpa_driver_nl80211_data *drv = bss->drv;
8787 struct nl_msg *msg;
8788 enum nl80211_tdls_operation nl80211_oper;
Paul Stewart092955c2017-02-06 09:13:09 -08008789 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008790
8791 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8792 return -EOPNOTSUPP;
8793
8794 switch (oper) {
8795 case TDLS_DISCOVERY_REQ:
8796 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
8797 break;
8798 case TDLS_SETUP:
8799 nl80211_oper = NL80211_TDLS_SETUP;
8800 break;
8801 case TDLS_TEARDOWN:
8802 nl80211_oper = NL80211_TDLS_TEARDOWN;
8803 break;
8804 case TDLS_ENABLE_LINK:
8805 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
8806 break;
8807 case TDLS_DISABLE_LINK:
8808 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
8809 break;
8810 case TDLS_ENABLE:
8811 return 0;
8812 case TDLS_DISABLE:
8813 return 0;
8814 default:
8815 return -EINVAL;
8816 }
8817
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008818 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
8819 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
8820 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
8821 nlmsg_free(msg);
8822 return -ENOBUFS;
8823 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008824
Paul Stewart092955c2017-02-06 09:13:09 -08008825 res = send_and_recv_msgs(drv, msg, NULL, NULL);
8826 wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8827 " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res,
8828 strerror(-res));
8829 return res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008830}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008831
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008832
8833static int
8834nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
8835 const struct hostapd_freq_params *params)
8836{
8837 struct i802_bss *bss = priv;
8838 struct wpa_driver_nl80211_data *drv = bss->drv;
8839 struct nl_msg *msg;
8840 int ret = -ENOBUFS;
8841
8842 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8843 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8844 return -EOPNOTSUPP;
8845
8846 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
8847 " oper_class=%u freq=%u",
8848 MAC2STR(addr), oper_class, params->freq);
8849 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
8850 if (!msg ||
8851 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8852 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
8853 (ret = nl80211_put_freq_params(msg, params))) {
8854 nlmsg_free(msg);
8855 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
8856 return ret;
8857 }
8858
8859 return send_and_recv_msgs(drv, msg, NULL, NULL);
8860}
8861
8862
8863static int
8864nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
8865{
8866 struct i802_bss *bss = priv;
8867 struct wpa_driver_nl80211_data *drv = bss->drv;
8868 struct nl_msg *msg;
8869
8870 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8871 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8872 return -EOPNOTSUPP;
8873
8874 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
8875 MAC2STR(addr));
8876 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
8877 if (!msg ||
8878 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8879 nlmsg_free(msg);
8880 wpa_printf(MSG_DEBUG,
8881 "nl80211: Could not build TDLS cancel chan switch");
8882 return -ENOBUFS;
8883 }
8884
8885 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008886}
8887
8888#endif /* CONFIG TDLS */
8889
8890
Hai Shalomfdcde762020-04-02 11:19:20 -07008891static int driver_nl80211_set_key(void *priv,
8892 struct wpa_driver_set_key_params *params)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008893{
8894 struct i802_bss *bss = priv;
Hai Shalomfdcde762020-04-02 11:19:20 -07008895
8896 return wpa_driver_nl80211_set_key(bss, params);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008897}
8898
8899
8900static int driver_nl80211_scan2(void *priv,
8901 struct wpa_driver_scan_params *params)
8902{
8903 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008904#ifdef CONFIG_DRIVER_NL80211_QCA
8905 struct wpa_driver_nl80211_data *drv = bss->drv;
8906
8907 /*
8908 * Do a vendor specific scan if possible. If only_new_results is
8909 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8910 * cannot be achieved through a vendor scan. The below condition may
8911 * need to be modified if new scan flags are added in the future whose
8912 * functionality can only be achieved through a normal scan.
8913 */
8914 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
8915 return wpa_driver_nl80211_vendor_scan(bss, params);
8916#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008917 return wpa_driver_nl80211_scan(bss, params);
8918}
8919
8920
8921static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07008922 u16 reason_code)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008923{
8924 struct i802_bss *bss = priv;
8925 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
8926}
8927
8928
8929static int driver_nl80211_authenticate(void *priv,
8930 struct wpa_driver_auth_params *params)
8931{
8932 struct i802_bss *bss = priv;
8933 return wpa_driver_nl80211_authenticate(bss, params);
8934}
8935
8936
8937static void driver_nl80211_deinit(void *priv)
8938{
8939 struct i802_bss *bss = priv;
8940 wpa_driver_nl80211_deinit(bss);
8941}
8942
8943
8944static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
8945 const char *ifname)
8946{
8947 struct i802_bss *bss = priv;
8948 return wpa_driver_nl80211_if_remove(bss, type, ifname);
8949}
8950
8951
8952static int driver_nl80211_send_mlme(void *priv, const u8 *data,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07008953 size_t data_len, int noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008954 unsigned int freq,
Hai Shalomfdcde762020-04-02 11:19:20 -07008955 const u16 *csa_offs, size_t csa_offs_len,
8956 int no_encrypt, unsigned int wait)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008957{
8958 struct i802_bss *bss = priv;
8959 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07008960 freq, 0, 0, wait, csa_offs,
8961 csa_offs_len, no_encrypt);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008962}
8963
8964
8965static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
8966{
8967 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008968 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008969}
8970
8971
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008972static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
8973 const char *ifname, int vlan_id)
8974{
8975 struct i802_bss *bss = priv;
8976 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
8977}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008978
8979
8980static int driver_nl80211_read_sta_data(void *priv,
8981 struct hostap_sta_driver_data *data,
8982 const u8 *addr)
8983{
8984 struct i802_bss *bss = priv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08008985
8986 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008987 return i802_read_sta_data(bss, data, addr);
8988}
8989
8990
8991static int driver_nl80211_send_action(void *priv, unsigned int freq,
8992 unsigned int wait_time,
8993 const u8 *dst, const u8 *src,
8994 const u8 *bssid,
8995 const u8 *data, size_t data_len,
8996 int no_cck)
8997{
8998 struct i802_bss *bss = priv;
8999 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
9000 bssid, data, data_len, no_cck);
9001}
9002
9003
9004static int driver_nl80211_probe_req_report(void *priv, int report)
9005{
9006 struct i802_bss *bss = priv;
9007 return wpa_driver_nl80211_probe_req_report(bss, report);
9008}
9009
9010
Dmitry Shmidt700a1372013-03-15 14:14:44 -07009011static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
9012 const u8 *ies, size_t ies_len)
9013{
9014 int ret;
9015 struct nl_msg *msg;
9016 struct i802_bss *bss = priv;
9017 struct wpa_driver_nl80211_data *drv = bss->drv;
9018 u16 mdid = WPA_GET_LE16(md);
9019
Dmitry Shmidt700a1372013-03-15 14:14:44 -07009020 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009021 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
9022 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
9023 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
9024 nlmsg_free(msg);
9025 return -ENOBUFS;
9026 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07009027
9028 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9029 if (ret) {
9030 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
9031 "err=%d (%s)", ret, strerror(-ret));
9032 }
9033
9034 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07009035}
9036
9037
Hai Shalom81f62d82019-07-22 12:10:00 -07009038static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac,
9039 u16 reason_code, const u8 *ie, size_t ie_len)
9040{
9041 int ret;
9042 struct nl_msg *msg;
9043 struct i802_bss *bss = priv;
9044 struct wpa_driver_nl80211_data *drv = bss->drv;
9045
9046 wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR
9047 " reason %u", MAC2STR(peer_mac), reason_code);
9048 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) ||
9049 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) ||
9050 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) ||
9051 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) {
9052 nlmsg_free(msg);
9053 return -ENOBUFS;
9054 }
9055
9056 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9057 if (ret) {
9058 wpa_printf(MSG_DEBUG,
9059 "nl80211: update_dh_ie failed err=%d (%s)",
9060 ret, strerror(-ret));
9061 }
9062
9063 return ret;
9064}
9065
9066
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009067static const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009068{
9069 struct i802_bss *bss = priv;
9070 struct wpa_driver_nl80211_data *drv = bss->drv;
9071
9072 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
9073 return NULL;
9074
9075 return bss->addr;
9076}
9077
9078
Dmitry Shmidt56052862013-10-04 10:23:25 -07009079static const char * scan_state_str(enum scan_states scan_state)
9080{
9081 switch (scan_state) {
9082 case NO_SCAN:
9083 return "NO_SCAN";
9084 case SCAN_REQUESTED:
9085 return "SCAN_REQUESTED";
9086 case SCAN_STARTED:
9087 return "SCAN_STARTED";
9088 case SCAN_COMPLETED:
9089 return "SCAN_COMPLETED";
9090 case SCAN_ABORTED:
9091 return "SCAN_ABORTED";
9092 case SCHED_SCAN_STARTED:
9093 return "SCHED_SCAN_STARTED";
9094 case SCHED_SCAN_STOPPED:
9095 return "SCHED_SCAN_STOPPED";
9096 case SCHED_SCAN_RESULTS:
9097 return "SCHED_SCAN_RESULTS";
9098 }
9099
9100 return "??";
9101}
9102
9103
9104static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
9105{
9106 struct i802_bss *bss = priv;
9107 struct wpa_driver_nl80211_data *drv = bss->drv;
9108 int res;
9109 char *pos, *end;
Hai Shalom74f70d42019-02-11 14:42:39 -08009110 struct nl_msg *msg;
9111 char alpha2[3] = { 0, 0, 0 };
Dmitry Shmidt56052862013-10-04 10:23:25 -07009112
9113 pos = buf;
9114 end = buf + buflen;
9115
9116 res = os_snprintf(pos, end - pos,
9117 "ifindex=%d\n"
9118 "ifname=%s\n"
9119 "brname=%s\n"
9120 "addr=" MACSTR "\n"
9121 "freq=%d\n"
Hai Shalomc9e41a12018-07-31 14:41:42 -07009122 "%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07009123 bss->ifindex,
9124 bss->ifname,
9125 bss->brname,
9126 MAC2STR(bss->addr),
9127 bss->freq,
9128 bss->beacon_set ? "beacon_set=1\n" : "",
9129 bss->added_if_into_bridge ?
9130 "added_if_into_bridge=1\n" : "",
Hai Shalomc9e41a12018-07-31 14:41:42 -07009131 bss->already_in_bridge ? "already_in_bridge=1\n" : "",
Dmitry Shmidt56052862013-10-04 10:23:25 -07009132 bss->added_bridge ? "added_bridge=1\n" : "",
9133 bss->in_deinit ? "in_deinit=1\n" : "",
9134 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009135 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07009136 return pos - buf;
9137 pos += res;
9138
9139 if (bss->wdev_id_set) {
9140 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
9141 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009142 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07009143 return pos - buf;
9144 pos += res;
9145 }
9146
9147 res = os_snprintf(pos, end - pos,
9148 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009149 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07009150 "drv_ifindex=%d\n"
9151 "operstate=%d\n"
9152 "scan_state=%s\n"
9153 "auth_bssid=" MACSTR "\n"
9154 "auth_attempt_bssid=" MACSTR "\n"
9155 "bssid=" MACSTR "\n"
9156 "prev_bssid=" MACSTR "\n"
9157 "associated=%d\n"
9158 "assoc_freq=%u\n"
9159 "monitor_sock=%d\n"
9160 "monitor_ifidx=%d\n"
9161 "monitor_refcount=%d\n"
9162 "last_mgmt_freq=%u\n"
9163 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009164 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07009165 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009166 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07009167 drv->ifindex,
9168 drv->operstate,
9169 scan_state_str(drv->scan_state),
9170 MAC2STR(drv->auth_bssid),
9171 MAC2STR(drv->auth_attempt_bssid),
9172 MAC2STR(drv->bssid),
9173 MAC2STR(drv->prev_bssid),
9174 drv->associated,
9175 drv->assoc_freq,
9176 drv->monitor_sock,
9177 drv->monitor_ifidx,
9178 drv->monitor_refcount,
9179 drv->last_mgmt_freq,
9180 drv->eapol_tx_sock,
9181 drv->ignore_if_down_event ?
9182 "ignore_if_down_event=1\n" : "",
9183 drv->scan_complete_events ?
9184 "scan_complete_events=1\n" : "",
9185 drv->disabled_11b_rates ?
9186 "disabled_11b_rates=1\n" : "",
9187 drv->pending_remain_on_chan ?
9188 "pending_remain_on_chan=1\n" : "",
9189 drv->in_interface_list ? "in_interface_list=1\n" : "",
9190 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
9191 drv->poll_command_supported ?
9192 "poll_command_supported=1\n" : "",
9193 drv->data_tx_status ? "data_tx_status=1\n" : "",
9194 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
9195 drv->retry_auth ? "retry_auth=1\n" : "",
9196 drv->use_monitor ? "use_monitor=1\n" : "",
9197 drv->ignore_next_local_disconnect ?
9198 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07009199 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009200 "ignore_next_local_deauth=1\n" : "");
9201 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07009202 return pos - buf;
9203 pos += res;
9204
9205 if (drv->has_capability) {
9206 res = os_snprintf(pos, end - pos,
9207 "capa.key_mgmt=0x%x\n"
9208 "capa.enc=0x%x\n"
9209 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009210 "capa.flags=0x%llx\n"
9211 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07009212 "capa.max_scan_ssids=%d\n"
9213 "capa.max_sched_scan_ssids=%d\n"
9214 "capa.sched_scan_supported=%d\n"
9215 "capa.max_match_sets=%d\n"
9216 "capa.max_remain_on_chan=%u\n"
9217 "capa.max_stations=%u\n"
9218 "capa.probe_resp_offloads=0x%x\n"
9219 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009220 "capa.num_multichan_concurrent=%u\n"
9221 "capa.mac_addr_rand_sched_scan_supported=%d\n"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009222 "capa.mac_addr_rand_scan_supported=%d\n"
9223 "capa.conc_capab=%u\n"
9224 "capa.max_conc_chan_2_4=%u\n"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009225 "capa.max_conc_chan_5_0=%u\n"
9226 "capa.max_sched_scan_plans=%u\n"
9227 "capa.max_sched_scan_plan_interval=%u\n"
9228 "capa.max_sched_scan_plan_iterations=%u\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07009229 drv->capa.key_mgmt,
9230 drv->capa.enc,
9231 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009232 (unsigned long long) drv->capa.flags,
9233 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07009234 drv->capa.max_scan_ssids,
9235 drv->capa.max_sched_scan_ssids,
9236 drv->capa.sched_scan_supported,
9237 drv->capa.max_match_sets,
9238 drv->capa.max_remain_on_chan,
9239 drv->capa.max_stations,
9240 drv->capa.probe_resp_offloads,
9241 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009242 drv->capa.num_multichan_concurrent,
9243 drv->capa.mac_addr_rand_sched_scan_supported,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009244 drv->capa.mac_addr_rand_scan_supported,
9245 drv->capa.conc_capab,
9246 drv->capa.max_conc_chan_2_4,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009247 drv->capa.max_conc_chan_5_0,
9248 drv->capa.max_sched_scan_plans,
9249 drv->capa.max_sched_scan_plan_interval,
9250 drv->capa.max_sched_scan_plan_iterations);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009251 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07009252 return pos - buf;
9253 pos += res;
9254 }
9255
Hai Shalom74f70d42019-02-11 14:42:39 -08009256 msg = nlmsg_alloc();
9257 if (msg &&
9258 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) &&
9259 nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) {
9260 if (send_and_recv_msgs(drv, msg, nl80211_get_country,
9261 alpha2) == 0 &&
9262 alpha2[0]) {
9263 res = os_snprintf(pos, end - pos, "country=%s\n",
9264 alpha2);
9265 if (os_snprintf_error(end - pos, res))
9266 return pos - buf;
9267 pos += res;
9268 }
9269 } else {
9270 nlmsg_free(msg);
9271 }
9272
Dmitry Shmidt56052862013-10-04 10:23:25 -07009273 return pos - buf;
9274}
9275
9276
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009277static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
9278{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009279 if ((settings->head &&
9280 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
9281 settings->head_len, settings->head)) ||
9282 (settings->tail &&
9283 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
9284 settings->tail_len, settings->tail)) ||
9285 (settings->beacon_ies &&
9286 nla_put(msg, NL80211_ATTR_IE,
9287 settings->beacon_ies_len, settings->beacon_ies)) ||
9288 (settings->proberesp_ies &&
9289 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
9290 settings->proberesp_ies_len, settings->proberesp_ies)) ||
9291 (settings->assocresp_ies &&
9292 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
9293 settings->assocresp_ies_len, settings->assocresp_ies)) ||
9294 (settings->probe_resp &&
9295 nla_put(msg, NL80211_ATTR_PROBE_RESP,
9296 settings->probe_resp_len, settings->probe_resp)))
9297 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009298
9299 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009300}
9301
9302
9303static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
9304{
9305 struct nl_msg *msg;
9306 struct i802_bss *bss = priv;
9307 struct wpa_driver_nl80211_data *drv = bss->drv;
9308 struct nlattr *beacon_csa;
9309 int ret = -ENOBUFS;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009310 int csa_off_len = 0;
9311 int i;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009312
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08009313 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 -08009314 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08009315 settings->freq_params.freq, settings->freq_params.bandwidth,
9316 settings->freq_params.center_freq1,
9317 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009318
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009319 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009320 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
9321 return -EOPNOTSUPP;
9322 }
9323
Roshan Pius3a1667e2018-07-03 15:17:14 -07009324 if (drv->nlmode != NL80211_IFTYPE_AP &&
9325 drv->nlmode != NL80211_IFTYPE_P2P_GO &&
9326 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009327 return -EOPNOTSUPP;
9328
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009329 /*
9330 * Remove empty counters, assuming Probe Response and Beacon frame
9331 * counters match. This implementation assumes that there are only two
9332 * counters.
9333 */
9334 if (settings->counter_offset_beacon[0] &&
9335 !settings->counter_offset_beacon[1]) {
9336 csa_off_len = 1;
9337 } else if (settings->counter_offset_beacon[1] &&
9338 !settings->counter_offset_beacon[0]) {
9339 csa_off_len = 1;
9340 settings->counter_offset_beacon[0] =
9341 settings->counter_offset_beacon[1];
9342 settings->counter_offset_presp[0] =
9343 settings->counter_offset_presp[1];
9344 } else if (settings->counter_offset_beacon[1] &&
9345 settings->counter_offset_beacon[0]) {
9346 csa_off_len = 2;
9347 } else {
9348 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
9349 return -EINVAL;
9350 }
9351
9352 /* Check CSA counters validity */
9353 if (drv->capa.max_csa_counters &&
9354 csa_off_len > drv->capa.max_csa_counters) {
9355 wpa_printf(MSG_ERROR,
9356 "nl80211: Too many CSA counters provided");
9357 return -EINVAL;
9358 }
9359
9360 if (!settings->beacon_csa.tail)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009361 return -EINVAL;
9362
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009363 for (i = 0; i < csa_off_len; i++) {
9364 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
9365 u16 csa_c_off_presp = settings->counter_offset_presp[i];
9366
9367 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
9368 (settings->beacon_csa.tail[csa_c_off_bcn] !=
9369 settings->cs_count))
9370 return -EINVAL;
9371
9372 if (settings->beacon_csa.probe_resp &&
9373 ((settings->beacon_csa.probe_resp_len <=
9374 csa_c_off_presp) ||
9375 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
9376 settings->cs_count)))
9377 return -EINVAL;
9378 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009379
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009380 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
9381 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
9382 settings->cs_count) ||
9383 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
9384 (settings->block_tx &&
9385 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009386 goto error;
9387
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009388 /* beacon_after params */
9389 ret = set_beacon_data(msg, &settings->beacon_after);
9390 if (ret)
9391 goto error;
9392
9393 /* beacon_csa params */
9394 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
9395 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009396 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009397
9398 ret = set_beacon_data(msg, &settings->beacon_csa);
9399 if (ret)
9400 goto error;
9401
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009402 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
9403 csa_off_len * sizeof(u16),
9404 settings->counter_offset_beacon) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009405 (settings->beacon_csa.probe_resp &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009406 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
9407 csa_off_len * sizeof(u16),
9408 settings->counter_offset_presp)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009409 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009410
9411 nla_nest_end(msg, beacon_csa);
9412 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9413 if (ret) {
9414 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
9415 ret, strerror(-ret));
9416 }
9417 return ret;
9418
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009419fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009420 ret = -ENOBUFS;
9421error:
9422 nlmsg_free(msg);
9423 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
9424 return ret;
9425}
9426
9427
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009428static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
9429 u8 user_priority, u16 admitted_time)
9430{
9431 struct i802_bss *bss = priv;
9432 struct wpa_driver_nl80211_data *drv = bss->drv;
9433 struct nl_msg *msg;
9434 int ret;
9435
9436 wpa_printf(MSG_DEBUG,
9437 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
9438 tsid, admitted_time, user_priority);
9439
9440 if (!is_sta_interface(drv->nlmode))
9441 return -ENOTSUP;
9442
9443 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
9444 if (!msg ||
9445 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9446 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9447 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
9448 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
9449 nlmsg_free(msg);
9450 return -ENOBUFS;
9451 }
9452
9453 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9454 if (ret)
9455 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
9456 ret, strerror(-ret));
9457 return ret;
9458}
9459
9460
9461static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
9462{
9463 struct i802_bss *bss = priv;
9464 struct wpa_driver_nl80211_data *drv = bss->drv;
9465 struct nl_msg *msg;
9466 int ret;
9467
9468 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
9469
9470 if (!is_sta_interface(drv->nlmode))
9471 return -ENOTSUP;
9472
9473 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
9474 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9475 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
9476 nlmsg_free(msg);
9477 return -ENOBUFS;
9478 }
9479
9480 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9481 if (ret)
9482 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
9483 ret, strerror(-ret));
9484 return ret;
9485}
9486
9487
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009488#ifdef CONFIG_TESTING_OPTIONS
9489static int cmd_reply_handler(struct nl_msg *msg, void *arg)
9490{
9491 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9492 struct wpabuf *buf = arg;
9493
9494 if (!buf)
9495 return NL_SKIP;
9496
9497 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
9498 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
9499 return NL_SKIP;
9500 }
9501
9502 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
9503 genlmsg_attrlen(gnlh, 0));
9504
9505 return NL_SKIP;
9506}
9507#endif /* CONFIG_TESTING_OPTIONS */
9508
9509
9510static int vendor_reply_handler(struct nl_msg *msg, void *arg)
9511{
9512 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9513 struct nlattr *nl_vendor_reply, *nl;
9514 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9515 struct wpabuf *buf = arg;
9516 int rem;
9517
9518 if (!buf)
9519 return NL_SKIP;
9520
9521 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9522 genlmsg_attrlen(gnlh, 0), NULL);
9523 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
9524
9525 if (!nl_vendor_reply)
9526 return NL_SKIP;
9527
9528 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
9529 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
9530 return NL_SKIP;
9531 }
9532
9533 nla_for_each_nested(nl, nl_vendor_reply, rem) {
9534 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
9535 }
9536
9537 return NL_SKIP;
9538}
9539
9540
9541static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
9542 unsigned int subcmd, const u8 *data,
9543 size_t data_len, struct wpabuf *buf)
9544{
9545 struct i802_bss *bss = priv;
9546 struct wpa_driver_nl80211_data *drv = bss->drv;
9547 struct nl_msg *msg;
9548 int ret;
9549
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009550#ifdef CONFIG_TESTING_OPTIONS
9551 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009552 msg = nlmsg_alloc();
9553 if (!msg)
9554 return -ENOMEM;
9555
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009556 nl80211_cmd(drv, msg, 0, subcmd);
9557 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
9558 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009559 goto fail;
Hai Shalomb755a2a2020-04-23 21:49:02 -07009560 /* This test vendor_cmd can be used with nl80211 commands that
9561 * need the connect nl_sock, so use the owner-setting variant
9562 * of send_and_recv_msgs(). */
9563 ret = send_and_recv_msgs_owner(drv, msg,
9564 get_connect_handle(bss), 0,
9565 cmd_reply_handler, buf);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009566 if (ret)
9567 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
9568 ret);
9569 return ret;
9570 }
9571#endif /* CONFIG_TESTING_OPTIONS */
9572
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009573 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
9574 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
9575 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
9576 (data &&
9577 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
9578 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009579
9580 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
9581 if (ret)
9582 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
9583 ret);
9584 return ret;
9585
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009586fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009587 nlmsg_free(msg);
9588 return -ENOBUFS;
9589}
9590
9591
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009592static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
9593 u8 qos_map_set_len)
9594{
9595 struct i802_bss *bss = priv;
9596 struct wpa_driver_nl80211_data *drv = bss->drv;
9597 struct nl_msg *msg;
9598 int ret;
9599
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009600 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
9601 qos_map_set, qos_map_set_len);
9602
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009603 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
9604 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
9605 nlmsg_free(msg);
9606 return -ENOBUFS;
9607 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009608
9609 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9610 if (ret)
9611 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
9612
9613 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009614}
9615
9616
Hai Shalomfdcde762020-04-02 11:19:20 -07009617static int get_wowlan_handler(struct nl_msg *msg, void *arg)
9618{
9619 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9620 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9621 int *wowlan_enabled = arg;
9622
9623 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9624 genlmsg_attrlen(gnlh, 0), NULL);
9625
9626 *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS];
9627
9628 return NL_SKIP;
9629}
9630
9631
9632static int nl80211_get_wowlan(void *priv)
9633{
9634 struct i802_bss *bss = priv;
9635 struct wpa_driver_nl80211_data *drv = bss->drv;
9636 struct nl_msg *msg;
9637 int wowlan_enabled;
9638 int ret;
9639
9640 wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status");
9641
9642 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN);
9643
9644 ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled);
9645 if (ret) {
9646 wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed");
9647 return 0;
9648 }
9649
9650 wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s",
9651 wowlan_enabled ? "enabled" : "disabled");
9652
9653 return wowlan_enabled;
9654}
9655
9656
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009657static int nl80211_set_wowlan(void *priv,
9658 const struct wowlan_triggers *triggers)
9659{
9660 struct i802_bss *bss = priv;
9661 struct wpa_driver_nl80211_data *drv = bss->drv;
9662 struct nl_msg *msg;
9663 struct nlattr *wowlan_triggers;
9664 int ret;
9665
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009666 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
9667
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07009668 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009669 !(wowlan_triggers = nla_nest_start(msg,
9670 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
9671 (triggers->any &&
9672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
9673 (triggers->disconnect &&
9674 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
9675 (triggers->magic_pkt &&
9676 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
9677 (triggers->gtk_rekey_failure &&
9678 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
9679 (triggers->eap_identity_req &&
9680 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
9681 (triggers->four_way_handshake &&
9682 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
9683 (triggers->rfkill_release &&
9684 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
9685 nlmsg_free(msg);
9686 return -ENOBUFS;
9687 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009688
9689 nla_nest_end(msg, wowlan_triggers);
9690
9691 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9692 if (ret)
9693 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
9694
9695 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009696}
9697
9698
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009699#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009700static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
9701{
9702 struct i802_bss *bss = priv;
9703 struct wpa_driver_nl80211_data *drv = bss->drv;
9704 struct nl_msg *msg;
9705 struct nlattr *params;
9706
9707 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
9708
9709 if (!drv->roaming_vendor_cmd_avail) {
9710 wpa_printf(MSG_DEBUG,
9711 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
9712 return -1;
9713 }
9714
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009715 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9716 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9717 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9718 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
9719 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9720 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
9721 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
9722 QCA_ROAMING_NOT_ALLOWED) ||
9723 (bssid &&
9724 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
9725 nlmsg_free(msg);
9726 return -1;
9727 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009728 nla_nest_end(msg, params);
9729
9730 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009731}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009732
9733
Roshan Pius3a1667e2018-07-03 15:17:14 -07009734static int nl80211_disable_fils(void *priv, int disable)
9735{
9736 struct i802_bss *bss = priv;
9737 struct wpa_driver_nl80211_data *drv = bss->drv;
9738 struct nl_msg *msg;
9739 struct nlattr *params;
9740
9741 wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable);
9742
9743 if (!drv->set_wifi_conf_vendor_cmd_avail)
9744 return -1;
9745
9746 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9747 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9748 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9749 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
9750 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9751 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS,
9752 disable)) {
9753 nlmsg_free(msg);
9754 return -1;
9755 }
9756 nla_nest_end(msg, params);
9757
9758 return send_and_recv_msgs(drv, msg, NULL, NULL);
9759}
9760
9761
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009762/* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
9763#define WPA_SUPPLICANT_CLIENT_ID 1
9764
9765static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid,
9766 const u8 *bssid)
9767{
9768 struct i802_bss *bss = priv;
9769 struct wpa_driver_nl80211_data *drv = bss->drv;
9770 struct nl_msg *msg;
9771 struct nlattr *params, *nlbssids, *attr;
9772 unsigned int i;
9773
9774 wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)",
9775 num_bssid);
9776
9777 if (!drv->roam_vendor_cmd_avail)
9778 return -1;
9779
9780 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9781 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9782 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9783 QCA_NL80211_VENDOR_SUBCMD_ROAM) ||
9784 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9785 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
Hai Shalomc3565922019-10-28 11:58:20 -07009786 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009787 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID,
9788 WPA_SUPPLICANT_CLIENT_ID) ||
9789 nla_put_u32(msg,
9790 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
9791 num_bssid))
9792 goto fail;
9793
9794 nlbssids = nla_nest_start(
9795 msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
9796 if (!nlbssids)
9797 goto fail;
9798
9799 for (i = 0; i < num_bssid; i++) {
9800 attr = nla_nest_start(msg, i);
9801 if (!attr)
9802 goto fail;
9803 if (nla_put(msg,
9804 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
9805 ETH_ALEN, &bssid[i * ETH_ALEN]))
9806 goto fail;
9807 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i,
9808 MAC2STR(&bssid[i * ETH_ALEN]));
9809 nla_nest_end(msg, attr);
9810 }
9811 nla_nest_end(msg, nlbssids);
9812 nla_nest_end(msg, params);
9813
9814 return send_and_recv_msgs(drv, msg, NULL, NULL);
9815
9816fail:
9817 nlmsg_free(msg);
9818 return -1;
9819}
9820
Hai Shalomc3565922019-10-28 11:58:20 -07009821
9822static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
9823{
9824 struct i802_bss *bss = priv;
9825 struct wpa_driver_nl80211_data *drv = bss->drv;
9826 struct nl_msg *msg;
9827 struct nlattr *params;
9828
9829 if (!drv->add_sta_node_vendor_cmd_avail)
9830 return -EOPNOTSUPP;
9831
9832 wpa_printf(MSG_DEBUG, "nl80211: Add STA node");
9833
9834 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9835 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9836 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9837 QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) ||
9838 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9839 (addr &&
9840 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN,
9841 addr)) ||
9842 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO,
9843 auth_alg)) {
9844 nlmsg_free(msg);
9845 wpa_printf(MSG_ERROR,
9846 "%s: err in adding vendor_cmd and vendor_data",
9847 __func__);
9848 return -1;
9849 }
9850 nla_nest_end(msg, params);
9851
9852 return send_and_recv_msgs(drv, msg, NULL, NULL);
9853}
9854
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009855#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009856
9857
9858static int nl80211_set_mac_addr(void *priv, const u8 *addr)
9859{
9860 struct i802_bss *bss = priv;
9861 struct wpa_driver_nl80211_data *drv = bss->drv;
9862 int new_addr = addr != NULL;
9863
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009864 if (TEST_FAIL())
9865 return -1;
9866
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009867 if (!addr)
9868 addr = drv->perm_addr;
9869
9870 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
9871 return -1;
9872
9873 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
9874 {
9875 wpa_printf(MSG_DEBUG,
9876 "nl80211: failed to set_mac_addr for %s to " MACSTR,
9877 bss->ifname, MAC2STR(addr));
9878 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
9879 1) < 0) {
9880 wpa_printf(MSG_DEBUG,
9881 "nl80211: Could not restore interface UP after failed set_mac_addr");
9882 }
9883 return -1;
9884 }
9885
9886 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
9887 bss->ifname, MAC2STR(addr));
9888 drv->addr_changed = new_addr;
9889 os_memcpy(bss->addr, addr, ETH_ALEN);
9890
9891 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
9892 {
9893 wpa_printf(MSG_DEBUG,
9894 "nl80211: Could not restore interface UP after set_mac_addr");
9895 }
9896
9897 return 0;
9898}
9899
9900
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009901#ifdef CONFIG_MESH
9902
9903static int wpa_driver_nl80211_init_mesh(void *priv)
9904{
9905 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
9906 wpa_printf(MSG_INFO,
9907 "nl80211: Failed to set interface into mesh mode");
9908 return -1;
9909 }
9910 return 0;
9911}
9912
9913
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009914static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
9915 size_t mesh_id_len)
9916{
9917 if (mesh_id) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009918 wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s",
9919 wpa_ssid_txt(mesh_id, mesh_id_len));
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009920 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
9921 }
9922
9923 return 0;
9924}
9925
9926
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009927static int nl80211_put_mesh_config(struct nl_msg *msg,
9928 struct wpa_driver_mesh_bss_params *params)
9929{
9930 struct nlattr *container;
9931
9932 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
9933 if (!container)
9934 return -1;
9935
9936 if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07009937 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
9938 params->auto_plinks)) ||
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009939 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
9940 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009941 params->max_peer_links)) ||
9942 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) &&
9943 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
9944 params->rssi_threshold)))
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07009945 return -1;
9946
9947 /*
9948 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9949 * the timer could disconnect stations even in that case.
9950 */
9951 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) &&
9952 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
9953 params->peer_link_timeout)) {
9954 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
9955 return -1;
9956 }
9957
9958 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) &&
9959 nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) {
9960 wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE");
9961 return -1;
9962 }
9963
9964 nla_nest_end(msg, container);
9965
9966 return 0;
9967}
9968
9969
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009970static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009971 struct wpa_driver_mesh_join_params *params)
9972{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009973 struct wpa_driver_nl80211_data *drv = bss->drv;
9974 struct nl_msg *msg;
9975 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08009976 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009977
9978 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
9979 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009980 if (!msg ||
9981 nl80211_put_freq_params(msg, &params->freq) ||
9982 nl80211_put_basic_rates(msg, params->basic_rates) ||
9983 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009984 nl80211_put_beacon_int(msg, params->beacon_int) ||
9985 nl80211_put_dtim_period(msg, params->dtim_period))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009986 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009987
9988 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
9989
9990 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
9991 if (!container)
9992 goto fail;
9993
9994 if (params->ies) {
9995 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
9996 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
9997 params->ies))
9998 goto fail;
9999 }
10000 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
10001 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
10002 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
10003 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
10004 goto fail;
10005 }
10006 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
10007 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
10008 goto fail;
10009 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
10010 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
10011 goto fail;
10012 nla_nest_end(msg, container);
10013
Dmitry Shmidtd13095b2016-08-22 14:02:19 -070010014 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
10015 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT;
10016 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS;
10017 if (nl80211_put_mesh_config(msg, &params->conf) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010018 goto fail;
10019
Hai Shalomb755a2a2020-04-23 21:49:02 -070010020 ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1,
10021 NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010022 msg = NULL;
10023 if (ret) {
10024 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
10025 ret, strerror(-ret));
10026 goto fail;
10027 }
10028 ret = 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070010029 drv->assoc_freq = bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010030 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
10031
10032fail:
10033 nlmsg_free(msg);
10034 return ret;
10035}
10036
10037
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010038static int
10039wpa_driver_nl80211_join_mesh(void *priv,
10040 struct wpa_driver_mesh_join_params *params)
10041{
10042 struct i802_bss *bss = priv;
10043 int ret, timeout;
10044
10045 timeout = params->conf.peer_link_timeout;
10046
10047 /* Disable kernel inactivity timer */
10048 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
10049 params->conf.peer_link_timeout = 0;
10050
10051 ret = nl80211_join_mesh(bss, params);
10052 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
10053 wpa_printf(MSG_DEBUG,
10054 "nl80211: Mesh join retry for peer_link_timeout");
10055 /*
10056 * Old kernel does not support setting
10057 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
10058 * into future from peer_link_timeout.
10059 */
10060 params->conf.peer_link_timeout = timeout + 60;
10061 ret = nl80211_join_mesh(priv, params);
10062 }
10063
10064 params->conf.peer_link_timeout = timeout;
10065 return ret;
10066}
10067
10068
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010069static int wpa_driver_nl80211_leave_mesh(void *priv)
10070{
10071 struct i802_bss *bss = priv;
10072 struct wpa_driver_nl80211_data *drv = bss->drv;
10073 struct nl_msg *msg;
10074 int ret;
10075
10076 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
10077 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
Hai Shalomb755a2a2020-04-23 21:49:02 -070010078 ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 0,
10079 NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010080 if (ret) {
10081 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
10082 ret, strerror(-ret));
10083 } else {
10084 wpa_printf(MSG_DEBUG,
10085 "nl80211: mesh leave request send successfully");
10086 }
10087
10088 if (wpa_driver_nl80211_set_mode(drv->first_bss,
10089 NL80211_IFTYPE_STATION)) {
10090 wpa_printf(MSG_INFO,
10091 "nl80211: Failed to set interface into station mode");
10092 }
10093 return ret;
10094}
10095
Hai Shalom81f62d82019-07-22 12:10:00 -070010096
10097static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth,
10098 size_t len)
10099{
10100 struct i802_bss *bss = priv;
10101 struct wpa_driver_nl80211_data *drv = bss->drv;
10102 struct nl_msg *msg;
10103 int ret;
10104
10105 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK);
10106 if (!msg ||
10107 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10108 nla_put(msg, NL80211_ATTR_FRAME, len, eth)) {
10109 nlmsg_free(msg);
10110 return -ENOBUFS;
10111 }
10112
10113 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10114 if (ret) {
10115 wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR
10116 " failed: ret=%d (%s)",
10117 MAC2STR(addr), ret, strerror(-ret));
10118 } else {
10119 wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR
10120 " probed successfully", MAC2STR(addr));
10121 }
10122
10123 return ret;
10124}
10125
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010126#endif /* CONFIG_MESH */
10127
10128
10129static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
10130 const u8 *ipaddr, int prefixlen,
10131 const u8 *addr)
10132{
10133#ifdef CONFIG_LIBNL3_ROUTE
10134 struct i802_bss *bss = priv;
10135 struct wpa_driver_nl80211_data *drv = bss->drv;
10136 struct rtnl_neigh *rn;
10137 struct nl_addr *nl_ipaddr = NULL;
10138 struct nl_addr *nl_lladdr = NULL;
10139 int family, addrsize;
10140 int res;
10141
10142 if (!ipaddr || prefixlen == 0 || !addr)
10143 return -EINVAL;
10144
10145 if (bss->br_ifindex == 0) {
10146 wpa_printf(MSG_DEBUG,
10147 "nl80211: bridge must be set before adding an ip neigh to it");
10148 return -1;
10149 }
10150
10151 if (!drv->rtnl_sk) {
10152 wpa_printf(MSG_DEBUG,
10153 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
10154 return -1;
10155 }
10156
10157 if (version == 4) {
10158 family = AF_INET;
10159 addrsize = 4;
10160 } else if (version == 6) {
10161 family = AF_INET6;
10162 addrsize = 16;
10163 } else {
10164 return -EINVAL;
10165 }
10166
10167 rn = rtnl_neigh_alloc();
10168 if (rn == NULL)
10169 return -ENOMEM;
10170
10171 /* set the destination ip address for neigh */
10172 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
10173 if (nl_ipaddr == NULL) {
10174 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
10175 res = -ENOMEM;
10176 goto errout;
10177 }
10178 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
10179 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
10180 if (res) {
10181 wpa_printf(MSG_DEBUG,
10182 "nl80211: neigh set destination addr failed");
10183 goto errout;
10184 }
10185
10186 /* set the corresponding lladdr for neigh */
10187 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
10188 if (nl_lladdr == NULL) {
10189 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
10190 res = -ENOMEM;
10191 goto errout;
10192 }
10193 rtnl_neigh_set_lladdr(rn, nl_lladdr);
10194
10195 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
10196 rtnl_neigh_set_state(rn, NUD_PERMANENT);
10197
10198 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
10199 if (res) {
10200 wpa_printf(MSG_DEBUG,
10201 "nl80211: Adding bridge ip neigh failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070010202 nl_geterror(res));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010203 }
10204errout:
10205 if (nl_lladdr)
10206 nl_addr_put(nl_lladdr);
10207 if (nl_ipaddr)
10208 nl_addr_put(nl_ipaddr);
10209 if (rn)
10210 rtnl_neigh_put(rn);
10211 return res;
10212#else /* CONFIG_LIBNL3_ROUTE */
10213 return -1;
10214#endif /* CONFIG_LIBNL3_ROUTE */
10215}
10216
10217
10218static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
10219 const u8 *ipaddr)
10220{
10221#ifdef CONFIG_LIBNL3_ROUTE
10222 struct i802_bss *bss = priv;
10223 struct wpa_driver_nl80211_data *drv = bss->drv;
10224 struct rtnl_neigh *rn;
10225 struct nl_addr *nl_ipaddr;
10226 int family, addrsize;
10227 int res;
10228
10229 if (!ipaddr)
10230 return -EINVAL;
10231
10232 if (version == 4) {
10233 family = AF_INET;
10234 addrsize = 4;
10235 } else if (version == 6) {
10236 family = AF_INET6;
10237 addrsize = 16;
10238 } else {
10239 return -EINVAL;
10240 }
10241
10242 if (bss->br_ifindex == 0) {
10243 wpa_printf(MSG_DEBUG,
10244 "nl80211: bridge must be set to delete an ip neigh");
10245 return -1;
10246 }
10247
10248 if (!drv->rtnl_sk) {
10249 wpa_printf(MSG_DEBUG,
10250 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
10251 return -1;
10252 }
10253
10254 rn = rtnl_neigh_alloc();
10255 if (rn == NULL)
10256 return -ENOMEM;
10257
10258 /* set the destination ip address for neigh */
10259 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
10260 if (nl_ipaddr == NULL) {
10261 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
10262 res = -ENOMEM;
10263 goto errout;
10264 }
10265 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
10266 if (res) {
10267 wpa_printf(MSG_DEBUG,
10268 "nl80211: neigh set destination addr failed");
10269 goto errout;
10270 }
10271
10272 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
10273
10274 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
10275 if (res) {
10276 wpa_printf(MSG_DEBUG,
10277 "nl80211: Deleting bridge ip neigh failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070010278 nl_geterror(res));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010279 }
10280errout:
10281 if (nl_ipaddr)
10282 nl_addr_put(nl_ipaddr);
10283 if (rn)
10284 rtnl_neigh_put(rn);
10285 return res;
10286#else /* CONFIG_LIBNL3_ROUTE */
10287 return -1;
10288#endif /* CONFIG_LIBNL3_ROUTE */
10289}
10290
10291
10292static int linux_write_system_file(const char *path, unsigned int val)
10293{
10294 char buf[50];
10295 int fd, len;
10296
10297 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
10298 if (os_snprintf_error(sizeof(buf), len))
10299 return -1;
10300
10301 fd = open(path, O_WRONLY);
10302 if (fd < 0)
10303 return -1;
10304
10305 if (write(fd, buf, len) < 0) {
10306 wpa_printf(MSG_DEBUG,
10307 "nl80211: Failed to write Linux system file: %s with the value of %d",
10308 path, val);
10309 close(fd);
10310 return -1;
10311 }
10312 close(fd);
10313
10314 return 0;
10315}
10316
10317
10318static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
10319{
10320 switch (attr) {
10321 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -070010322 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010323 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
10324 return "hairpin_mode";
10325 }
10326
10327 return NULL;
10328}
10329
10330
10331static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
10332 unsigned int val)
10333{
10334 struct i802_bss *bss = priv;
10335 char path[128];
10336 const char *attr_txt;
10337
10338 attr_txt = drv_br_port_attr_str(attr);
10339 if (attr_txt == NULL)
10340 return -EINVAL;
10341
10342 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
10343 bss->ifname, attr_txt);
10344
10345 if (linux_write_system_file(path, val))
10346 return -1;
10347
10348 return 0;
10349}
10350
10351
10352static const char * drv_br_net_param_str(enum drv_br_net_param param)
10353{
10354 switch (param) {
10355 case DRV_BR_NET_PARAM_GARP_ACCEPT:
10356 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -070010357 default:
10358 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010359 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010360}
10361
10362
10363static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
10364 unsigned int val)
10365{
10366 struct i802_bss *bss = priv;
10367 char path[128];
10368 const char *param_txt;
10369 int ip_version = 4;
10370
Dmitry Shmidt83474442015-04-15 13:47:09 -070010371 if (param == DRV_BR_MULTICAST_SNOOPING) {
10372 os_snprintf(path, sizeof(path),
10373 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
10374 bss->brname);
10375 goto set_val;
10376 }
10377
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010378 param_txt = drv_br_net_param_str(param);
10379 if (param_txt == NULL)
10380 return -EINVAL;
10381
10382 switch (param) {
10383 case DRV_BR_NET_PARAM_GARP_ACCEPT:
10384 ip_version = 4;
10385 break;
10386 default:
10387 return -EINVAL;
10388 }
10389
10390 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
10391 ip_version, bss->brname, param_txt);
10392
Dmitry Shmidt83474442015-04-15 13:47:09 -070010393set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010394 if (linux_write_system_file(path, val))
10395 return -1;
10396
10397 return 0;
10398}
10399
10400
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010401#ifdef CONFIG_DRIVER_NL80211_QCA
10402
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010403static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
10404{
10405 switch (hw_mode) {
10406 case HOSTAPD_MODE_IEEE80211B:
10407 return QCA_ACS_MODE_IEEE80211B;
10408 case HOSTAPD_MODE_IEEE80211G:
10409 return QCA_ACS_MODE_IEEE80211G;
10410 case HOSTAPD_MODE_IEEE80211A:
10411 return QCA_ACS_MODE_IEEE80211A;
10412 case HOSTAPD_MODE_IEEE80211AD:
10413 return QCA_ACS_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -070010414 case HOSTAPD_MODE_IEEE80211ANY:
10415 return QCA_ACS_MODE_IEEE80211ANY;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010416 default:
10417 return -1;
10418 }
10419}
10420
10421
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010422static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list)
10423{
10424 int num_channels = 0, num_freqs;
10425 u8 *ch_list;
10426 enum hostapd_hw_mode hw_mode;
10427 int ret = 0;
10428 int i;
10429
10430 if (!freq_list)
10431 return 0;
10432
10433 num_freqs = int_array_len(freq_list);
10434 ch_list = os_malloc(sizeof(u8) * num_freqs);
10435 if (!ch_list)
10436 return -1;
10437
10438 for (i = 0; i < num_freqs; i++) {
10439 const int freq = freq_list[i];
10440
10441 if (freq == 0)
10442 break;
10443 /* Send 2.4 GHz and 5 GHz channels with
10444 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards
10445 * compatibility.
10446 */
10447 if (!(freq >= 2412 && freq <= 2484) &&
10448 !(freq >= 5180 && freq <= 5900))
10449 continue;
10450 hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]);
10451 if (hw_mode != NUM_HOSTAPD_MODES)
10452 num_channels++;
10453 }
10454
10455 if (num_channels)
10456 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST,
10457 num_channels, ch_list);
10458
10459 os_free(ch_list);
10460 return ret;
10461}
10462
10463
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010464static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
10465{
10466 int i, len, ret;
10467 u32 *freqs;
10468
10469 if (!freq_list)
10470 return 0;
10471 len = int_array_len(freq_list);
10472 freqs = os_malloc(sizeof(u32) * len);
10473 if (!freqs)
10474 return -1;
10475 for (i = 0; i < len; i++)
10476 freqs[i] = freq_list[i];
10477 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
10478 sizeof(u32) * len, freqs);
10479 os_free(freqs);
10480 return ret;
10481}
10482
10483
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010484static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
10485{
10486 struct i802_bss *bss = priv;
10487 struct wpa_driver_nl80211_data *drv = bss->drv;
10488 struct nl_msg *msg;
10489 struct nlattr *data;
10490 int ret;
10491 int mode;
10492
10493 mode = hw_mode_to_qca_acs(params->hw_mode);
10494 if (mode < 0)
10495 return -1;
10496
10497 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10498 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10499 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10500 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
10501 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10502 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
10503 (params->ht_enabled &&
10504 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
10505 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010506 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
10507 (params->vht_enabled &&
10508 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
10509 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
10510 params->ch_width) ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010511 add_acs_ch_list(msg, params->freq_list) ||
Hai Shalomfdcde762020-04-02 11:19:20 -070010512 add_acs_freq_list(msg, params->freq_list) ||
10513 (params->edmg_enabled &&
10514 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010515 nlmsg_free(msg);
10516 return -ENOBUFS;
10517 }
10518 nla_nest_end(msg, data);
10519
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010520 wpa_printf(MSG_DEBUG,
Hai Shalomfdcde762020-04-02 11:19:20 -070010521 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d EDMG: %d",
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010522 params->hw_mode, params->ht_enabled, params->ht40_enabled,
Hai Shalomfdcde762020-04-02 11:19:20 -070010523 params->vht_enabled, params->ch_width, params->edmg_enabled);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070010524
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010525 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10526 if (ret) {
10527 wpa_printf(MSG_DEBUG,
10528 "nl80211: Failed to invoke driver ACS function: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070010529 strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010530 }
10531 return ret;
10532}
10533
10534
Ravi Joshie6ccb162015-07-16 17:45:41 -070010535static int nl80211_set_band(void *priv, enum set_band band)
10536{
10537 struct i802_bss *bss = priv;
10538 struct wpa_driver_nl80211_data *drv = bss->drv;
10539 struct nl_msg *msg;
10540 struct nlattr *data;
10541 int ret;
10542 enum qca_set_band qca_band;
10543
10544 if (!drv->setband_vendor_cmd_avail)
10545 return -1;
10546
10547 switch (band) {
10548 case WPA_SETBAND_AUTO:
10549 qca_band = QCA_SETBAND_AUTO;
10550 break;
10551 case WPA_SETBAND_5G:
10552 qca_band = QCA_SETBAND_5G;
10553 break;
10554 case WPA_SETBAND_2G:
10555 qca_band = QCA_SETBAND_2G;
10556 break;
10557 default:
10558 return -1;
10559 }
10560
10561 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10562 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10563 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10564 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
10565 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10566 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
10567 nlmsg_free(msg);
10568 return -ENOBUFS;
10569 }
10570 nla_nest_end(msg, data);
10571
10572 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10573 if (ret) {
10574 wpa_printf(MSG_DEBUG,
10575 "nl80211: Driver setband function failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070010576 strerror(-ret));
Ravi Joshie6ccb162015-07-16 17:45:41 -070010577 }
10578 return ret;
10579}
10580
10581
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010582struct nl80211_pcl {
10583 unsigned int num;
10584 unsigned int *freq_list;
10585};
10586
10587static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
10588{
10589 struct nlattr *tb[NL80211_ATTR_MAX + 1];
10590 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10591 struct nl80211_pcl *param = arg;
10592 struct nlattr *nl_vend, *attr;
10593 enum qca_iface_type iface_type;
10594 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10595 unsigned int num, max_num;
10596 u32 *freqs;
10597
10598 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10599 genlmsg_attrlen(gnlh, 0), NULL);
10600
10601 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
10602 if (!nl_vend)
10603 return NL_SKIP;
10604
10605 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10606 nla_data(nl_vend), nla_len(nl_vend), NULL);
10607
10608 attr = tb_vendor[
10609 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
10610 if (!attr) {
10611 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
10612 param->num = 0;
10613 return NL_SKIP;
10614 }
10615
10616 iface_type = (enum qca_iface_type) nla_get_u32(attr);
10617 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
10618 iface_type);
10619
10620 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
10621 if (!attr) {
10622 wpa_printf(MSG_ERROR,
10623 "nl80211: preferred_freq_list couldn't be found");
10624 param->num = 0;
10625 return NL_SKIP;
10626 }
10627
10628 /*
10629 * param->num has the maximum number of entries for which there
10630 * is room in the freq_list provided by the caller.
10631 */
10632 freqs = nla_data(attr);
10633 max_num = nla_len(attr) / sizeof(u32);
10634 if (max_num > param->num)
10635 max_num = param->num;
10636 for (num = 0; num < max_num; num++)
10637 param->freq_list[num] = freqs[num];
10638 param->num = num;
10639
10640 return NL_SKIP;
10641}
10642
10643
10644static int nl80211_get_pref_freq_list(void *priv,
10645 enum wpa_driver_if_type if_type,
10646 unsigned int *num,
10647 unsigned int *freq_list)
10648{
10649 struct i802_bss *bss = priv;
10650 struct wpa_driver_nl80211_data *drv = bss->drv;
10651 struct nl_msg *msg;
10652 int ret;
10653 unsigned int i;
10654 struct nlattr *params;
10655 struct nl80211_pcl param;
10656 enum qca_iface_type iface_type;
10657
10658 if (!drv->get_pref_freq_list)
10659 return -1;
10660
10661 switch (if_type) {
10662 case WPA_IF_STATION:
10663 iface_type = QCA_IFACE_TYPE_STA;
10664 break;
10665 case WPA_IF_AP_BSS:
10666 iface_type = QCA_IFACE_TYPE_AP;
10667 break;
10668 case WPA_IF_P2P_GO:
10669 iface_type = QCA_IFACE_TYPE_P2P_GO;
10670 break;
10671 case WPA_IF_P2P_CLIENT:
10672 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
10673 break;
10674 case WPA_IF_IBSS:
10675 iface_type = QCA_IFACE_TYPE_IBSS;
10676 break;
10677 case WPA_IF_TDLS:
10678 iface_type = QCA_IFACE_TYPE_TDLS;
10679 break;
10680 default:
10681 return -1;
10682 }
10683
10684 param.num = *num;
10685 param.freq_list = freq_list;
10686
10687 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10688 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
10689 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10690 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10691 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
10692 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10693 nla_put_u32(msg,
10694 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
10695 iface_type)) {
10696 wpa_printf(MSG_ERROR,
10697 "%s: err in adding vendor_cmd and vendor_data",
10698 __func__);
10699 nlmsg_free(msg);
10700 return -1;
10701 }
10702 nla_nest_end(msg, params);
10703
10704 os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
10705 ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
10706 if (ret) {
10707 wpa_printf(MSG_ERROR,
10708 "%s: err in send_and_recv_msgs", __func__);
10709 return ret;
10710 }
10711
10712 *num = param.num;
10713
10714 for (i = 0; i < *num; i++) {
10715 wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
10716 i, freq_list[i]);
10717 }
10718
10719 return 0;
10720}
10721
10722
10723static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
10724{
10725 struct i802_bss *bss = priv;
10726 struct wpa_driver_nl80211_data *drv = bss->drv;
10727 struct nl_msg *msg;
10728 int ret;
10729 struct nlattr *params;
10730
10731 if (!drv->set_prob_oper_freq)
10732 return -1;
10733
10734 wpa_printf(MSG_DEBUG,
10735 "nl80211: Set P2P probable operating freq %u for ifindex %d",
10736 freq, bss->ifindex);
10737
10738 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10739 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10740 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10741 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
10742 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10743 nla_put_u32(msg,
10744 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
10745 QCA_IFACE_TYPE_P2P_CLIENT) ||
10746 nla_put_u32(msg,
10747 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
10748 freq)) {
10749 wpa_printf(MSG_ERROR,
10750 "%s: err in adding vendor_cmd and vendor_data",
10751 __func__);
10752 nlmsg_free(msg);
10753 return -1;
10754 }
10755 nla_nest_end(msg, params);
10756
10757 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10758 msg = NULL;
10759 if (ret) {
10760 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
10761 __func__);
10762 return ret;
10763 }
10764 nlmsg_free(msg);
10765 return 0;
10766}
10767
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010768
10769static int nl80211_p2p_lo_start(void *priv, unsigned int freq,
10770 unsigned int period, unsigned int interval,
10771 unsigned int count, const u8 *device_types,
10772 size_t dev_types_len,
10773 const u8 *ies, size_t ies_len)
10774{
10775 struct i802_bss *bss = priv;
10776 struct wpa_driver_nl80211_data *drv = bss->drv;
10777 struct nl_msg *msg;
10778 struct nlattr *container;
10779 int ret;
10780
10781 wpa_printf(MSG_DEBUG,
10782 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
10783 freq, period, interval, count);
10784
10785 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10786 return -1;
10787
10788 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10789 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10790 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10791 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START))
10792 goto fail;
10793
10794 container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10795 if (!container)
10796 goto fail;
10797
10798 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL,
10799 freq) ||
10800 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD,
10801 period) ||
10802 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL,
10803 interval) ||
10804 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT,
10805 count) ||
10806 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES,
10807 dev_types_len, device_types) ||
10808 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE,
10809 ies_len, ies))
10810 goto fail;
10811
10812 nla_nest_end(msg, container);
10813 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10814 msg = NULL;
10815 if (ret) {
10816 wpa_printf(MSG_DEBUG,
10817 "nl80211: Failed to send P2P Listen offload vendor command");
10818 goto fail;
10819 }
10820
10821 return 0;
10822
10823fail:
10824 nlmsg_free(msg);
10825 return -1;
10826}
10827
10828
10829static int nl80211_p2p_lo_stop(void *priv)
10830{
10831 struct i802_bss *bss = priv;
10832 struct wpa_driver_nl80211_data *drv = bss->drv;
10833 struct nl_msg *msg;
10834
10835 wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload");
10836
10837 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10838 return -1;
10839
10840 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10841 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10842 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10843 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) {
10844 nlmsg_free(msg);
10845 return -1;
10846 }
10847
10848 return send_and_recv_msgs(drv, msg, NULL, NULL);
10849}
10850
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080010851
10852static int nl80211_set_tdls_mode(void *priv, int tdls_external_control)
10853{
10854 struct i802_bss *bss = priv;
10855 struct wpa_driver_nl80211_data *drv = bss->drv;
10856 struct nl_msg *msg;
10857 struct nlattr *params;
10858 int ret;
10859 u32 tdls_mode;
10860
10861 wpa_printf(MSG_DEBUG,
10862 "nl80211: Set TDKS mode: tdls_external_control=%d",
10863 tdls_external_control);
10864
10865 if (tdls_external_control == 1)
10866 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT |
10867 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL;
10868 else
10869 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT;
10870
10871 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10872 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10873 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10874 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS))
10875 goto fail;
10876
10877 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10878 if (!params)
10879 goto fail;
10880
10881 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE,
10882 tdls_mode))
10883 goto fail;
10884
10885 nla_nest_end(msg, params);
10886
10887 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10888 msg = NULL;
10889 if (ret) {
10890 wpa_printf(MSG_ERROR,
10891 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10892 ret, strerror(-ret));
10893 goto fail;
10894 }
10895 return 0;
10896fail:
10897 nlmsg_free(msg);
10898 return -1;
10899}
10900
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010901
10902#ifdef CONFIG_MBO
10903
10904static enum mbo_transition_reject_reason
10905nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status)
10906{
10907 switch (status) {
10908 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED:
10909 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS;
10910 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED:
10911 return MBO_TRANSITION_REJECT_REASON_DELAY;
10912 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY:
10913 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY;
10914 case QCA_STATUS_REJECT_LOW_RSSI:
10915 return MBO_TRANSITION_REJECT_REASON_RSSI;
10916 case QCA_STATUS_REJECT_HIGH_INTERFERENCE:
10917 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE;
10918 case QCA_STATUS_REJECT_UNKNOWN:
10919 default:
10920 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
10921 }
10922}
10923
10924
10925static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate,
10926 struct nlattr *tb[], int num)
10927{
10928 enum qca_wlan_btm_candidate_status status;
10929 char buf[50];
10930
10931 os_memcpy(candidate->bssid,
10932 nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]),
10933 ETH_ALEN);
10934
10935 status = nla_get_u32(
10936 tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]);
10937 candidate->is_accept = status == QCA_STATUS_ACCEPT;
10938 candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status);
10939
10940 if (candidate->is_accept)
10941 os_snprintf(buf, sizeof(buf), "Accepted");
10942 else
10943 os_snprintf(buf, sizeof(buf),
10944 "Rejected, Reject_reason: %d",
10945 candidate->reject_reason);
10946 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s",
10947 num, MAC2STR(candidate->bssid), buf);
10948}
10949
10950
10951static int
10952nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg)
10953{
10954 struct wpa_bss_candidate_info *info = arg;
10955 struct candidate_list *candidate = info->candidates;
10956 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
10957 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10958 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1];
10959 static struct nla_policy policy[
10960 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = {
10961 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = {
10962 .minlen = ETH_ALEN
10963 },
10964 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = {
10965 .type = NLA_U32,
10966 },
10967 };
10968 struct nlattr *attr;
10969 int rem;
10970 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10971 u8 num;
10972
10973 num = info->num; /* number of candidates sent to driver */
10974 info->num = 0;
10975 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10976 genlmsg_attrlen(gnlh, 0), NULL);
10977
10978 if (!tb_msg[NL80211_ATTR_VENDOR_DATA] ||
10979 nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10980 tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) ||
10981 !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO])
10982 return NL_SKIP;
10983
10984 wpa_printf(MSG_DEBUG,
10985 "nl80211: WNM Candidate list received from driver");
10986 nla_for_each_nested(attr,
10987 tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO],
10988 rem) {
10989 if (info->num >= num ||
10990 nla_parse_nested(
10991 tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX,
10992 attr, policy) ||
10993 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] ||
10994 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS])
10995 break;
10996
10997 nl80211_parse_btm_candidate_info(candidate, tb, info->num);
10998
10999 candidate++;
11000 info->num++;
11001 }
11002
11003 return NL_SKIP;
11004}
11005
11006
11007static struct wpa_bss_candidate_info *
11008nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params)
11009{
11010 struct i802_bss *bss = priv;
11011 struct wpa_driver_nl80211_data *drv = bss->drv;
11012 struct nl_msg *msg;
11013 struct nlattr *attr, *attr1, *attr2;
11014 struct wpa_bss_candidate_info *info;
11015 u8 i;
11016 int ret;
11017 u8 *pos;
11018
11019 if (!drv->fetch_bss_trans_status)
11020 return NULL;
11021
11022 info = os_zalloc(sizeof(*info));
11023 if (!info)
11024 return NULL;
11025 /* Allocate memory for number of candidates sent to driver */
11026 info->candidates = os_calloc(params->n_candidates,
11027 sizeof(*info->candidates));
11028 if (!info->candidates) {
11029 os_free(info);
11030 return NULL;
11031 }
11032
11033 /* Copy the number of candidates being sent to driver. This is used in
11034 * nl80211_get_bss_transition_status_handler() to limit the number of
11035 * candidates that can be populated in info->candidates and will be
11036 * later overwritten with the actual number of candidates received from
11037 * the driver.
11038 */
11039 info->num = params->n_candidates;
11040
11041 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11042 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11043 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11044 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS))
11045 goto fail;
11046
11047 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
11048 if (!attr)
11049 goto fail;
11050
11051 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON,
11052 params->mbo_transition_reason))
11053 goto fail;
11054
11055 attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO);
11056 if (!attr1)
11057 goto fail;
11058
11059 wpa_printf(MSG_DEBUG,
11060 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
11061 params->mbo_transition_reason, params->n_candidates);
11062 pos = params->bssid;
11063 for (i = 0; i < params->n_candidates; i++) {
11064 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i,
11065 MAC2STR(pos));
11066 attr2 = nla_nest_start(msg, i);
11067 if (!attr2 ||
11068 nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID,
11069 ETH_ALEN, pos))
11070 goto fail;
11071 pos += ETH_ALEN;
11072 nla_nest_end(msg, attr2);
11073 }
11074
11075 nla_nest_end(msg, attr1);
11076 nla_nest_end(msg, attr);
11077
11078 ret = send_and_recv_msgs(drv, msg,
11079 nl80211_get_bss_transition_status_handler,
11080 info);
11081 msg = NULL;
11082 if (ret) {
11083 wpa_printf(MSG_ERROR,
11084 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
11085 ret, strerror(-ret));
11086 goto fail;
11087 }
11088 return info;
11089
11090fail:
11091 nlmsg_free(msg);
11092 os_free(info->candidates);
11093 os_free(info);
11094 return NULL;
11095}
11096
11097
11098/**
11099 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
11100 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
11101 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
11102 * Returns: 0 on success, -1 on failure
11103 */
11104static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow)
11105{
11106 struct i802_bss *bss = priv;
11107 struct wpa_driver_nl80211_data *drv = bss->drv;
11108 struct nl_msg *msg;
11109 struct nlattr *attr;
11110 int ret = -1;
11111
11112 if (!drv->set_wifi_conf_vendor_cmd_avail)
11113 return -1;
11114
11115 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11116 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11117 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11118 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION))
11119 goto fail;
11120
11121 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
11122 if (!attr)
11123 goto fail;
11124
11125 wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d",
11126 ignore_disallow);
11127 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED,
11128 ignore_disallow))
11129 goto fail;
11130
11131 nla_nest_end(msg, attr);
11132
11133 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11134 msg = NULL;
11135 if (ret) {
11136 wpa_printf(MSG_ERROR,
11137 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
11138 ret, strerror(-ret));
11139 goto fail;
11140 }
11141
11142fail:
11143 nlmsg_free(msg);
11144 return ret;
11145}
11146
11147#endif /* CONFIG_MBO */
11148
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011149#endif /* CONFIG_DRIVER_NL80211_QCA */
11150
11151
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011152static int nl80211_write_to_file(const char *name, unsigned int val)
11153{
11154 int fd, len;
11155 char tmp[128];
Hai Shalomc3565922019-10-28 11:58:20 -070011156 int ret = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011157
11158 fd = open(name, O_RDWR);
11159 if (fd < 0) {
Hai Shalomc3565922019-10-28 11:58:20 -070011160 int level;
11161 /*
11162 * Flags may not exist on older kernels, or while we're tearing
11163 * down a disappearing device.
11164 */
11165 if (errno == ENOENT) {
11166 ret = 0;
11167 level = MSG_DEBUG;
11168 } else {
11169 ret = -1;
11170 level = MSG_ERROR;
11171 }
11172 wpa_printf(level, "nl80211: Failed to open %s: %s",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011173 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070011174 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011175 }
11176
11177 len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
11178 len = write(fd, tmp, len);
Hai Shalomc3565922019-10-28 11:58:20 -070011179 if (len < 0) {
11180 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011181 wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
11182 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070011183 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011184 close(fd);
11185
Hai Shalomc3565922019-10-28 11:58:20 -070011186 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011187}
11188
11189
11190static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags)
11191{
11192 struct i802_bss *bss = priv;
11193 char path[128];
11194 int ret;
11195
11196 wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x",
11197 filter_flags);
11198
11199 /* Configure filtering of unicast frame encrypted using GTK */
11200 ret = os_snprintf(path, sizeof(path),
11201 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
11202 bss->ifname);
11203 if (os_snprintf_error(sizeof(path), ret))
11204 return -1;
11205
11206 ret = nl80211_write_to_file(path,
11207 !!(filter_flags &
11208 WPA_DATA_FRAME_FILTER_FLAG_GTK));
11209 if (ret) {
11210 wpa_printf(MSG_ERROR,
11211 "nl80211: Failed to set IPv4 unicast in multicast filter");
11212 return ret;
11213 }
11214
11215 os_snprintf(path, sizeof(path),
11216 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
11217 bss->ifname);
11218 ret = nl80211_write_to_file(path,
11219 !!(filter_flags &
11220 WPA_DATA_FRAME_FILTER_FLAG_GTK));
11221
11222 if (ret) {
11223 wpa_printf(MSG_ERROR,
11224 "nl80211: Failed to set IPv6 unicast in multicast filter");
11225 return ret;
11226 }
11227
11228 /* Configure filtering of unicast frame encrypted using GTK */
11229 os_snprintf(path, sizeof(path),
11230 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
11231 bss->ifname);
11232 ret = nl80211_write_to_file(path,
11233 !!(filter_flags &
11234 WPA_DATA_FRAME_FILTER_FLAG_ARP));
11235 if (ret) {
11236 wpa_printf(MSG_ERROR,
11237 "nl80211: Failed set gratuitous ARP filter");
11238 return ret;
11239 }
11240
11241 /* Configure filtering of IPv6 NA frames */
11242 os_snprintf(path, sizeof(path),
11243 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
11244 bss->ifname);
11245 ret = nl80211_write_to_file(path,
11246 !!(filter_flags &
11247 WPA_DATA_FRAME_FILTER_FLAG_NA));
11248 if (ret) {
11249 wpa_printf(MSG_ERROR,
11250 "nl80211: Failed to set unsolicited NA filter");
11251 return ret;
11252 }
11253
11254 return 0;
11255}
11256
11257
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070011258static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type,
11259 const u8 **ext_capa, const u8 **ext_capa_mask,
11260 unsigned int *ext_capa_len)
11261{
11262 struct i802_bss *bss = priv;
11263 struct wpa_driver_nl80211_data *drv = bss->drv;
11264 enum nl80211_iftype nlmode;
11265 unsigned int i;
11266
11267 if (!ext_capa || !ext_capa_mask || !ext_capa_len)
11268 return -1;
11269
11270 nlmode = wpa_driver_nl80211_if_type(type);
11271
11272 /* By default, use the per-radio values */
11273 *ext_capa = drv->extended_capa;
11274 *ext_capa_mask = drv->extended_capa_mask;
11275 *ext_capa_len = drv->extended_capa_len;
11276
11277 /* Replace the default value if a per-interface type value exists */
11278 for (i = 0; i < drv->num_iface_ext_capa; i++) {
11279 if (nlmode == drv->iface_ext_capa[i].iftype) {
11280 *ext_capa = drv->iface_ext_capa[i].ext_capa;
11281 *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask;
11282 *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len;
11283 break;
11284 }
11285 }
11286
11287 return 0;
11288}
11289
11290
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011291static int nl80211_update_connection_params(
11292 void *priv, struct wpa_driver_associate_params *params,
11293 enum wpa_drv_update_connect_params_mask mask)
11294{
11295 struct i802_bss *bss = priv;
11296 struct wpa_driver_nl80211_data *drv = bss->drv;
11297 struct nl_msg *msg;
11298 int ret = -1;
11299 enum nl80211_auth_type type;
11300
Hai Shalomc3565922019-10-28 11:58:20 -070011301 /* Update Connection Params is intended for drivers that implement
11302 * internal SME and expect these updated connection params from
11303 * wpa_supplicant. Do not send this request for the drivers using
11304 * SME from wpa_supplicant.
11305 */
11306 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
11307 return 0;
11308
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011309 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS);
11310 if (!msg)
11311 goto fail;
11312
11313 wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)",
11314 drv->ifindex);
11315
11316 if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) {
11317 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
11318 params->wpa_ie))
11319 goto fail;
11320 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie,
11321 params->wpa_ie_len);
11322 }
11323
11324 if (mask & WPA_DRV_UPDATE_AUTH_TYPE) {
11325 type = get_nl_auth_type(params->auth_alg);
11326 if (type == NL80211_AUTHTYPE_MAX ||
11327 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
11328 goto fail;
11329 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
11330 }
11331
11332 if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) &&
11333 nl80211_put_fils_connect_params(drv, params, msg))
11334 goto fail;
11335
11336 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11337 msg = NULL;
11338 if (ret)
11339 wpa_dbg(drv->ctx, MSG_DEBUG,
11340 "nl80211: Update connect params command failed: ret=%d (%s)",
11341 ret, strerror(-ret));
11342
11343fail:
11344 nlmsg_free(msg);
11345 return ret;
11346}
11347
11348
Roshan Pius3a1667e2018-07-03 15:17:14 -070011349static int nl80211_send_external_auth_status(void *priv,
11350 struct external_auth *params)
11351{
11352 struct i802_bss *bss = priv;
11353 struct wpa_driver_nl80211_data *drv = bss->drv;
11354 struct nl_msg *msg = NULL;
11355 int ret = -1;
11356
Hai Shalom5f92bc92019-04-18 11:54:11 -070011357 /* External auth command/status is intended for drivers that implement
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080011358 * internal SME but want to offload authentication processing (e.g.,
11359 * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers
Hai Shalom5f92bc92019-04-18 11:54:11 -070011360 * which do not support AP SME or use wpa_supplicant/hostapd SME.
11361 */
Hai Shalom81f62d82019-07-22 12:10:00 -070011362 if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070011363 (drv->capa.flags & WPA_DRIVER_FLAGS_SME))
11364 return -1;
11365
Roshan Pius3a1667e2018-07-03 15:17:14 -070011366 wpa_dbg(drv->ctx, MSG_DEBUG,
11367 "nl80211: External auth status: %u", params->status);
11368
11369 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH);
11370 if (!msg ||
11371 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070011372 (params->ssid && params->ssid_len &&
11373 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
11374 (params->pmkid &&
11375 nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) ||
11376 (params->bssid &&
11377 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)))
Roshan Pius3a1667e2018-07-03 15:17:14 -070011378 goto fail;
11379 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11380 msg = NULL;
11381 if (ret) {
11382 wpa_printf(MSG_DEBUG,
11383 "nl80211: External Auth status update failed: ret=%d (%s)",
11384 ret, strerror(-ret));
11385 goto fail;
11386 }
11387fail:
11388 nlmsg_free(msg);
11389 return ret;
11390}
11391
11392
Hai Shalom74f70d42019-02-11 14:42:39 -080011393static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname,
11394 int val)
11395{
11396 struct i802_bss *bss = priv;
11397 struct wpa_driver_nl80211_data *drv = bss->drv;
11398 struct nl_msg *msg;
11399 int ret = -ENOBUFS;
11400
11401 wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)",
11402 val ? "Enable" : "Disable", bridge_ifname);
11403
11404 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
11405 if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val))
11406 goto fail;
11407
11408 if (bridge_ifname[0] && bss->added_if_into_bridge && !val) {
11409 if (linux_br_del_if(drv->global->ioctl_sock,
11410 bridge_ifname, bss->ifname)) {
11411 wpa_printf(MSG_ERROR,
11412 "nl80211: Failed to remove interface %s from bridge %s",
11413 bss->ifname, bridge_ifname);
11414 return -1;
11415 }
11416 bss->added_if_into_bridge = 0;
11417 }
11418
11419 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
11420 msg = NULL;
11421 if (!ret) {
11422 if (bridge_ifname[0] && val &&
11423 i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0)
11424 return -1;
11425 return 0;
11426 }
11427
11428fail:
11429 nlmsg_free(msg);
11430 wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr");
11431
11432 return ret;
11433}
11434
11435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011436const struct wpa_driver_ops wpa_driver_nl80211_ops = {
11437 .name = "nl80211",
11438 .desc = "Linux nl80211/cfg80211",
11439 .get_bssid = wpa_driver_nl80211_get_bssid,
11440 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011441 .set_key = driver_nl80211_set_key,
11442 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011443 .sched_scan = wpa_driver_nl80211_sched_scan,
11444 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011445 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011446 .abort_scan = wpa_driver_nl80211_abort_scan,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011447 .deauthenticate = driver_nl80211_deauthenticate,
11448 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011449 .associate = wpa_driver_nl80211_associate,
11450 .global_init = nl80211_global_init,
11451 .global_deinit = nl80211_global_deinit,
11452 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011453 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011454 .get_capa = wpa_driver_nl80211_get_capa,
11455 .set_operstate = wpa_driver_nl80211_set_operstate,
11456 .set_supp_port = wpa_driver_nl80211_set_supp_port,
11457 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -080011458 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011459 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -070011460 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011461 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011462 .if_remove = driver_nl80211_if_remove,
11463 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011464 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011465 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011466 .sta_remove = driver_nl80211_sta_remove,
Hai Shalomfdcde762020-04-02 11:19:20 -070011467 .tx_control_port = nl80211_tx_control_port,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011468 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
11469 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Hai Shalom81f62d82019-07-22 12:10:00 -070011470 .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011471 .hapd_init = i802_init,
11472 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -070011473 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011474 .get_seqnum = i802_get_seqnum,
11475 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011476 .get_inact_sec = i802_get_inact_sec,
11477 .sta_clear_stats = i802_sta_clear_stats,
11478 .set_rts = i802_set_rts,
11479 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011480 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011481 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011482 .sta_deauth = i802_sta_deauth,
11483 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011484 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011485 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011486 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011487 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
11488 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
11489 .cancel_remain_on_channel =
11490 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080011491 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011492 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -070011493 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011494 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011495 .signal_monitor = nl80211_signal_monitor,
11496 .signal_poll = nl80211_signal_poll,
Hai Shalom74f70d42019-02-11 14:42:39 -080011497 .channel_info = nl80211_channel_info,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011498 .set_param = nl80211_set_param,
11499 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -070011500 .add_pmkid = nl80211_add_pmkid,
11501 .remove_pmkid = nl80211_remove_pmkid,
11502 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011503 .set_rekey_info = nl80211_set_rekey_info,
11504 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011505 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -070011506 .start_dfs_cac = nl80211_start_radar_detection,
11507 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011508#ifdef CONFIG_TDLS
11509 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
11510 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011511 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
11512 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011513#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -070011514 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Hai Shalom81f62d82019-07-22 12:10:00 -070011515 .update_dh_ie = nl80211_update_dh_ie,
Dmitry Shmidt34af3062013-07-11 10:46:32 -070011516 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011517 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -070011518 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011519 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011520#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070011521 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011522 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070011523 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011524#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070011525#ifdef ANDROID
Dmitry Shmidt41712582015-06-29 11:02:15 -070011526#ifndef ANDROID_LIB_STUB
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070011527 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt41712582015-06-29 11:02:15 -070011528#endif /* !ANDROID_LIB_STUB */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011529#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011530 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011531 .set_qos_map = nl80211_set_qos_map,
Hai Shalomfdcde762020-04-02 11:19:20 -070011532 .get_wowlan = nl80211_get_wowlan,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011533 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011534 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011535#ifdef CONFIG_MESH
11536 .init_mesh = wpa_driver_nl80211_init_mesh,
11537 .join_mesh = wpa_driver_nl80211_join_mesh,
11538 .leave_mesh = wpa_driver_nl80211_leave_mesh,
Hai Shalom81f62d82019-07-22 12:10:00 -070011539 .probe_mesh_link = nl80211_probe_mesh_link,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011540#endif /* CONFIG_MESH */
11541 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
11542 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
11543 .br_port_set_attr = wpa_driver_br_port_set_attr,
11544 .br_set_net_param = wpa_driver_br_set_net_param,
11545 .add_tx_ts = nl80211_add_ts,
11546 .del_tx_ts = nl80211_del_ts,
Dmitry Shmidte4663042016-04-04 10:07:49 -070011547 .get_ifindex = nl80211_get_ifindex,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011548#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011549 .roaming = nl80211_roaming,
Roshan Pius3a1667e2018-07-03 15:17:14 -070011550 .disable_fils = nl80211_disable_fils,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011551 .do_acs = wpa_driver_do_acs,
Ravi Joshie6ccb162015-07-16 17:45:41 -070011552 .set_band = nl80211_set_band,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011553 .get_pref_freq_list = nl80211_get_pref_freq_list,
11554 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011555 .p2p_lo_start = nl80211_p2p_lo_start,
11556 .p2p_lo_stop = nl80211_p2p_lo_stop,
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070011557 .set_default_scan_ies = nl80211_set_default_scan_ies,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080011558 .set_tdls_mode = nl80211_set_tdls_mode,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011559#ifdef CONFIG_MBO
11560 .get_bss_transition_status = nl80211_get_bss_transition_status,
11561 .ignore_assoc_disallow = nl80211_ignore_assoc_disallow,
11562#endif /* CONFIG_MBO */
11563 .set_bssid_blacklist = nl80211_set_bssid_blacklist,
Hai Shalomc3565922019-10-28 11:58:20 -070011564 .add_sta_node = nl80211_add_sta_node,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011565#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011566 .configure_data_frame_filters = nl80211_configure_data_frame_filters,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070011567 .get_ext_capab = nl80211_get_ext_capab,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011568 .update_connect_params = nl80211_update_connection_params,
Roshan Pius3a1667e2018-07-03 15:17:14 -070011569 .send_external_auth_status = nl80211_send_external_auth_status,
Hai Shalom74f70d42019-02-11 14:42:39 -080011570 .set_4addr_mode = nl80211_set_4addr_mode,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011571};