blob: 9b50b6fae2385ca586dfd4795a2307a8f78377b8 [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>
Sunil Ravib0ac25f2024-07-12 01:42:03 +000015#include <sys/utsname.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include <fcntl.h>
17#include <net/if.h>
18#include <netlink/genl/genl.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include <netlink/genl/ctrl.h>
Sunil Ravib0ac25f2024-07-12 01:42:03 +000020#include <netlink/genl/family.h>
Sunil Ravi88611412024-06-28 17:34:56 +000021#ifdef CONFIG_LIBNL3_ROUTE
22#include <netlink/route/neighbour.h>
23#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070024#include <linux/rtnetlink.h>
25#include <netpacket/packet.h>
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080026#include <linux/errqueue.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027
28#include "common.h"
29#include "eloop.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080030#include "common/qca-vendor.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070031#include "common/qca-vendor-attr.h"
Hai Shalomc1a21442022-02-04 13:43:00 -080032#include "common/brcm_vendor.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080034#include "common/ieee802_11_common.h"
Paul Stewart092955c2017-02-06 09:13:09 -080035#include "common/wpa_common.h"
Sunil Ravi89eba102022-09-13 21:04:37 -070036#include "crypto/sha256.h"
37#include "crypto/sha384.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "linux_ioctl.h"
41#include "radiotap.h"
42#include "radiotap_iter.h"
43#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080044#include "driver_nl80211.h"
Andy Kuoaba17c12022-04-14 16:05:31 +080045#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Ajay Davanagerib921bb82020-09-16 12:49:08 +053046#include "common/brcm_vendor.h"
Andy Kuoaba17c12022-04-14 16:05:31 +080047#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080048
Hai Shalom74f70d42019-02-11 14:42:39 -080049#ifndef NETLINK_CAP_ACK
50#define NETLINK_CAP_ACK 10
51#endif /* NETLINK_CAP_ACK */
Hai Shalom39ba6fc2019-01-22 12:40:38 -080052/* support for extack if compilation headers are too old */
53#ifndef NETLINK_EXT_ACK
54#define NETLINK_EXT_ACK 11
55enum nlmsgerr_attrs {
56 NLMSGERR_ATTR_UNUSED,
57 NLMSGERR_ATTR_MSG,
58 NLMSGERR_ATTR_OFFS,
59 NLMSGERR_ATTR_COOKIE,
60
61 __NLMSGERR_ATTR_MAX,
62 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
63};
64#endif
65#ifndef NLM_F_CAPPED
66#define NLM_F_CAPPED 0x100
67#endif
68#ifndef NLM_F_ACK_TLVS
69#define NLM_F_ACK_TLVS 0x200
70#endif
71#ifndef SOL_NETLINK
72#define SOL_NETLINK 270
73#endif
74
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
Dmitry Shmidt54605472013-11-08 11:10:19 -080076#ifdef ANDROID
77/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -080078#undef nl_socket_set_nonblocking
79#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080080
Dmitry Shmidt54605472013-11-08 11:10:19 -080081#endif /* ANDROID */
82
83
Hai Shalomfdcde762020-04-02 11:19:20 -070084static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080085{
Hai Shalomfdcde762020-04-02 11:19:20 -070086 struct nl_sock *handle;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080087
Hai Shalomfdcde762020-04-02 11:19:20 -070088 handle = nl_socket_alloc_cb(cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080089 if (handle == NULL) {
90 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
91 "callbacks (%s)", dbg);
92 return NULL;
93 }
94
95 if (genl_connect(handle)) {
96 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
97 "netlink (%s)", dbg);
Hai Shalomfdcde762020-04-02 11:19:20 -070098 nl_socket_free(handle);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080099 return NULL;
100 }
101
102 return handle;
103}
104
105
Hai Shalomfdcde762020-04-02 11:19:20 -0700106static void nl_destroy_handles(struct nl_sock **handle)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800107{
108 if (*handle == NULL)
109 return;
Hai Shalomfdcde762020-04-02 11:19:20 -0700110 nl_socket_free(*handle);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800111 *handle = NULL;
112}
113
114
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700115#if __WORDSIZE == 64
116#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
117#else
118#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
119#endif
120
Hai Shalomfdcde762020-04-02 11:19:20 -0700121static void nl80211_register_eloop_read(struct nl_sock **handle,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700122 eloop_sock_handler handler,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700123 void *eloop_data, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700124{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800125 /*
126 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
127 * by default. It is possible to hit that limit in some cases where
128 * operations are blocked, e.g., with a burst of Deauthentication frames
129 * to hostapd and STA entry deletion. Try to increase the buffer to make
130 * this less likely to occur.
131 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700132 int err;
133
134 err = nl_socket_set_buffer_size(*handle, 262144, 0);
135 if (err < 0) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800136 wpa_printf(MSG_DEBUG,
137 "nl80211: Could not set nl_socket RX buffer size: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -0700138 nl_geterror(err));
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800139 /* continue anyway with the default (smaller) buffer */
140 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800141
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700142 nl_socket_set_nonblocking(*handle);
143 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
144 eloop_data, *handle);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700145 if (!persist)
146 *handle = (void *) (((intptr_t) *handle) ^
147 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700148}
149
150
Hai Shalomfdcde762020-04-02 11:19:20 -0700151static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700152{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700153 if (!persist)
154 *handle = (void *) (((intptr_t) *handle) ^
155 ELOOP_SOCKET_INVALID);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700156 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
157 nl_destroy_handles(handle);
158}
159
160
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800161static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800162static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800163
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800164static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700165static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
166 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800169wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800170 const u8 *set_addr, int first,
171 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800172static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173 unsigned int freq, unsigned int wait,
Hai Shalomfdcde762020-04-02 11:19:20 -0700174 const u8 *buf, size_t buf_len,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000175 int save_cookie, int no_cck, int no_ack,
176 int offchanok, const u16 *csa_offs,
177 size_t csa_offs_len, int link_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800178static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
179 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800181#define IFIDX_ANY -1
182
183static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
184 int ifidx_reason);
185static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
186 int ifidx_reason);
187static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
188 int ifidx_reason);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700189
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700190static int nl80211_set_channel(struct i802_bss *bss,
191 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
193 int ifindex, int disabled);
194
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800195static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
196 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800197
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700198static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800199static int nl80211_set_param(void *priv, const char *param);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000200static void nl80211_remove_links(struct i802_bss *bss);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700201#ifdef CONFIG_MESH
202static int nl80211_put_mesh_config(struct nl_msg *msg,
203 struct wpa_driver_mesh_bss_params *params);
204#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -0800205static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -0700206 u16 reason);
Winnie Chen4138eec2022-11-10 16:32:53 +0800207#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawade62409f2022-01-20 12:32:07 +0530208static int nl80211_set_td_policy(void *priv, u32 td_policy);
Winnie Chen4138eec2022-11-10 16:32:53 +0800209#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700210
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800211/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800212enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800213{
214 switch (width) {
215 case NL80211_CHAN_WIDTH_20_NOHT:
216 return CHAN_WIDTH_20_NOHT;
217 case NL80211_CHAN_WIDTH_20:
218 return CHAN_WIDTH_20;
219 case NL80211_CHAN_WIDTH_40:
220 return CHAN_WIDTH_40;
221 case NL80211_CHAN_WIDTH_80:
222 return CHAN_WIDTH_80;
223 case NL80211_CHAN_WIDTH_80P80:
224 return CHAN_WIDTH_80P80;
225 case NL80211_CHAN_WIDTH_160:
226 return CHAN_WIDTH_160;
Sunil8cd6f4d2022-06-28 18:40:46 +0000227 case NL80211_CHAN_WIDTH_320:
228 return CHAN_WIDTH_320;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000229 default:
230 return CHAN_WIDTH_UNKNOWN;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800231 }
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800232}
233
234
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800235int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800236{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237 return nlmode == NL80211_IFTYPE_AP ||
238 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800239}
240
241
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800242int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800243{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700244 return nlmode == NL80211_IFTYPE_STATION ||
245 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800246}
247
248
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700249static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800250{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700251 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
252 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800253}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254
255
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
257 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700258{
259 struct i802_bss *bss;
260
261 for (bss = drv->first_bss; bss; bss = bss->next) {
262 if (bss->ifindex == ifindex)
263 return bss;
264 }
265
266 return NULL;
267}
268
269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800270static int is_mesh_interface(enum nl80211_iftype nlmode)
271{
272 return nlmode == NL80211_IFTYPE_MESH_POINT;
273}
274
275
276void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700277{
278 if (drv->associated)
279 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
280 drv->associated = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000281 os_memset(&drv->sta_mlo_info, 0, sizeof(drv->sta_mlo_info));
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700282 os_memset(drv->bssid, 0, ETH_ALEN);
Sunil Ravi036cec52023-03-29 11:35:17 -0700283 drv->first_bss->flink->freq = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700284#ifdef CONFIG_DRIVER_NL80211_QCA
285 os_free(drv->pending_roam_data);
286 drv->pending_roam_data = NULL;
Sunil Ravi640215c2023-06-28 23:08:09 +0000287 os_free(drv->pending_t2lm_data);
288 drv->pending_t2lm_data = NULL;
289 os_free(drv->pending_link_reconfig_data);
290 drv->pending_link_reconfig_data = NULL;
Sunil Ravi89eba102022-09-13 21:04:37 -0700291#endif /* CONFIG_DRIVER_NL80211_QCA */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000292
293 drv->auth_mld = false;
294 drv->auth_mld_link_id = -1;
295 os_memset(drv->auth_ap_mld_addr, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700296}
297
298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299/* nl80211 code */
300static int ack_handler(struct nl_msg *msg, void *arg)
301{
302 int *err = arg;
303 *err = 0;
304 return NL_STOP;
305}
306
Hai Shalom899fcc72020-10-19 14:38:18 -0700307
308struct nl80211_ack_ext_arg {
309 int *err;
310 void *ext_data;
311};
312
313
314static int ack_handler_cookie(struct nl_msg *msg, void *arg)
315{
316 struct nl80211_ack_ext_arg *ext_arg = arg;
317 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
318 u64 *cookie = ext_arg->ext_data;
319 struct nlattr *attrs;
320 size_t ack_len, attr_len;
321
322 *ext_arg->err = 0;
323 ack_len = sizeof(struct nlmsghdr) + sizeof(int) +
324 sizeof(struct nlmsghdr);
325 attrs = (struct nlattr *)
326 ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) +
327 sizeof(int));
328 if (nlmsg_hdr(msg)->nlmsg_len <= ack_len)
329 return NL_STOP;
330
331 attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len;
332
333 if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS))
334 return NL_STOP;
335
336 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL);
337 if (tb[NLMSGERR_ATTR_COOKIE])
338 *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]);
339
340 return NL_STOP;
341}
342
343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344static int finish_handler(struct nl_msg *msg, void *arg)
345{
346 int *ret = arg;
347 *ret = 0;
348 return NL_SKIP;
349}
350
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000351struct nl80211_ack_err_args {
352 int err;
353 struct nl_msg *orig_msg;
354 struct nl80211_err_info *err_info;
355};
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
358 void *arg)
359{
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000360 struct nl80211_ack_err_args *err_args = arg;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800361 struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000362 struct nlmsghdr *orig_nlh = nlmsg_hdr(err_args->orig_msg);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800363 int len = nlh->nlmsg_len;
364 struct nlattr *attrs;
365 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800366 int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000367 struct nlattr *mlo_links, *link_attr;
368 u32 offset;
369 int rem;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800370
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000371 err_args->err = err->error;
372 if (err_args->err_info)
373 err_args->err_info->link_id = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800374
375 if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
376 return NL_SKIP;
377
378 if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
379 ack_len += err->msg.nlmsg_len - sizeof(*nlh);
380
381 if (len <= ack_len)
382 return NL_STOP;
383
384 attrs = (void *) ((unsigned char *) nlh + ack_len);
385 len -= ack_len;
386
387 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
388 if (tb[NLMSGERR_ATTR_MSG]) {
389 len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]),
390 nla_len(tb[NLMSGERR_ATTR_MSG]));
391 wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s",
392 len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG]));
393 }
394
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000395 if (!err_args->err_info)
396 return NL_SKIP;
397
398 /* Check if it was a per-link error report */
399
400 if (!tb[NLMSGERR_ATTR_OFFS] ||
401 os_memcmp(orig_nlh, &err->msg, sizeof(err->msg)) != 0)
402 return NL_SKIP;
403
404 offset = nla_get_u32(tb[NLMSGERR_ATTR_OFFS]);
405
406 mlo_links = nlmsg_find_attr(orig_nlh, GENL_HDRLEN,
407 NL80211_ATTR_MLO_LINKS);
408 if (!mlo_links)
409 return NL_SKIP;
410
411 nla_for_each_nested(link_attr, mlo_links, rem) {
412 struct nlattr *link_id;
413 size_t link_offset = (u8 *) link_attr - (u8 *) orig_nlh;
414
415 if (offset < link_offset ||
416 offset >= link_offset + link_attr->nla_len)
417 continue;
418
419 link_id = nla_find(nla_data(link_attr), nla_len(link_attr),
420 NL80211_ATTR_MLO_LINK_ID);
421 if (link_id) {
422 err_args->err_info->link_id = nla_get_u8(link_id);
423 wpa_printf(MSG_DEBUG,
424 "nl80211: kernel reports error for link: %d",
425 err_args->err_info->link_id);
426 break;
427 }
428 }
429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430 return NL_SKIP;
431}
432
433
434static int no_seq_check(struct nl_msg *msg, void *arg)
435{
436 return NL_OK;
437}
438
439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440static void nl80211_nlmsg_clear(struct nl_msg *msg)
441{
442 /*
443 * Clear nlmsg data, e.g., to make sure key material is not left in
444 * heap memory for unnecessarily long time.
445 */
446 if (msg) {
447 struct nlmsghdr *hdr = nlmsg_hdr(msg);
448 void *data = nlmsg_data(hdr);
449 /*
450 * This would use nlmsg_datalen() or the older nlmsg_len() if
451 * only libnl were to maintain a stable API.. Neither will work
452 * with all released versions, so just calculate the length
453 * here.
454 */
455 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
456
457 os_memset(data, 0, len);
458 }
459}
460
461
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000462static int send_event_marker(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463{
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000464 struct nl_sock *handle;
465 struct nl_msg *msg;
466 struct nlmsghdr *hdr;
467 int res = 0;
468 int err = -NLE_NOMEM;
469
470 msg = nlmsg_alloc();
471 if (!msg)
472 goto out;
473
474 /* We only care about the returned sequence number for matching. */
475 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES))
476 goto out;
477
478 handle = (void *) (((intptr_t) drv->global->nl_event) ^
479 ELOOP_SOCKET_INVALID);
480
481 err = nl_send_auto_complete(handle, msg);
482 if (err < 0)
483 goto out;
484
485 hdr = nlmsg_hdr(msg);
486 res = hdr->nlmsg_seq;
487
488out:
489 nlmsg_free(msg);
490 if (err)
491 wpa_printf(MSG_INFO, "nl80211: %s failed: %s",
492 __func__, nl_geterror(err));
493 return res;
494}
495
496
497int send_and_recv(struct nl80211_global *global,
498 struct nl_sock *nl_handle, struct nl_msg *msg,
499 int (*valid_handler)(struct nl_msg *, void *),
500 void *valid_data,
501 int (*ack_handler_custom)(struct nl_msg *, void *),
502 void *ack_data,
503 struct nl80211_err_info *err_info)
504{
505 struct nl_cb *cb, *s_nl_cb;
506 struct nl80211_ack_err_args err;
507 int opt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800509 if (!msg)
510 return -ENOMEM;
511
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000512 err.err = -ENOMEM;
513
514 s_nl_cb = nl_socket_get_cb(nl_handle);
515 cb = nl_cb_clone(s_nl_cb);
516 nl_cb_put(s_nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517 if (!cb)
518 goto out;
519
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800520 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
521 opt = 1;
522 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
523 NETLINK_EXT_ACK, &opt, sizeof(opt));
524
Hai Shalom74f70d42019-02-11 14:42:39 -0800525 /* try to set NETLINK_CAP_ACK to 1, ignoring errors */
526 opt = 1;
527 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
528 NETLINK_CAP_ACK, &opt, sizeof(opt));
529
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000530 err.err = nl_send_auto_complete(nl_handle, msg);
531 if (err.err < 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700532 wpa_printf(MSG_INFO,
533 "nl80211: nl_send_auto_complete() failed: %s",
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000534 nl_geterror(err.err));
Hai Shalomfdcde762020-04-02 11:19:20 -0700535 /* Need to convert libnl error code to an errno value. For now,
536 * just hardcode this to EBADF; the real error reason is shown
537 * in that error print above. */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000538 err.err = -EBADF;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 goto out;
Hai Shalomfdcde762020-04-02 11:19:20 -0700540 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000542 err.err = 1;
543 err.orig_msg = msg;
544 err.err_info = err_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545
546 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000547 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
Hai Shalom899fcc72020-10-19 14:38:18 -0700548 if (ack_handler_custom) {
549 struct nl80211_ack_ext_arg *ext_arg = ack_data;
550
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000551 ext_arg->err = &err.err;
Hai Shalom899fcc72020-10-19 14:38:18 -0700552 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM,
553 ack_handler_custom, ack_data);
554 } else {
555 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
556 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557
558 if (valid_handler)
559 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
560 valid_handler, valid_data);
561
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000562 while (err.err > 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700563 int res = nl_recvmsgs(nl_handle, cb);
Hai Shalomfdcde762020-04-02 11:19:20 -0700564
565 if (res == -NLE_DUMP_INTR) {
566 /* Most likely one of the nl80211 dump routines hit a
567 * case where internal results changed while the dump
568 * was being sent. The most common known case for this
569 * is scan results fetching while associated were every
570 * received Beacon frame from the AP may end up
571 * incrementing bss_generation. This
572 * NL80211_CMD_GET_SCAN case tries again in the caller;
573 * other cases (of which there are no known common ones)
574 * will stop and return an error. */
575 wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN",
576 nl_geterror(res));
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000577 err.err = -EAGAIN;
Hai Shalomfdcde762020-04-02 11:19:20 -0700578 } else if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700579 wpa_printf(MSG_INFO,
Hai Shalomfdcde762020-04-02 11:19:20 -0700580 "nl80211: %s->nl_recvmsgs failed: %d (%s)",
581 __func__, res, nl_geterror(res));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700582 }
583 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 out:
585 nl_cb_put(cb);
Hai Shalom60840252021-02-19 19:02:11 -0800586 /* Always clear the message as it can potentially contain keys */
587 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 nlmsg_free(msg);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000589 return err.err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700590}
591
592
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000593static int nl80211_put_control_port(struct wpa_driver_nl80211_data *drv,
594 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595{
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000596 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT) ||
597 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
598 ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) &&
599 (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) ||
600 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))))
Hai Shalomb755a2a2020-04-23 21:49:02 -0700601 return -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000602 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700603}
604
605
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606struct family_data {
607 const char *group;
608 int id;
609};
610
611
612static int family_handler(struct nl_msg *msg, void *arg)
613{
614 struct family_data *res = arg;
615 struct nlattr *tb[CTRL_ATTR_MAX + 1];
616 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
617 struct nlattr *mcgrp;
618 int i;
619
620 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
621 genlmsg_attrlen(gnlh, 0), NULL);
622 if (!tb[CTRL_ATTR_MCAST_GROUPS])
623 return NL_SKIP;
624
625 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
626 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
627 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
628 nla_len(mcgrp), NULL);
629 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
630 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
631 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
632 res->group,
633 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
634 continue;
635 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
636 break;
637 };
638
639 return NL_SKIP;
640}
641
642
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800643static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 const char *family, const char *group)
645{
646 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800647 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700648 struct family_data res = { group, -ENOENT };
649
650 msg = nlmsg_alloc();
651 if (!msg)
652 return -ENOMEM;
Hai Shalomc1a21442022-02-04 13:43:00 -0800653 if (!genlmsg_put(msg, 0, 0, global->nlctrl_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800654 0, 0, CTRL_CMD_GETFAMILY, 0) ||
655 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
656 nlmsg_free(msg);
657 return -1;
658 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659
Hai Shalom899fcc72020-10-19 14:38:18 -0700660 ret = send_and_recv(global, global->nl, msg, family_handler, &res,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000661 NULL, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 if (ret == 0)
663 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 return ret;
665}
666
667
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800668void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
669 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800670{
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700671 if (TEST_FAIL())
672 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800673 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
674 0, flags, cmd, 0);
675}
676
677
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800678static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
679{
680 if (bss->wdev_id_set)
681 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
682 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
683}
684
685
686struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
687{
688 struct nl_msg *msg;
689
690 msg = nlmsg_alloc();
691 if (!msg)
692 return NULL;
693
694 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
695 nl80211_set_iface_id(msg, bss) < 0) {
696 nlmsg_free(msg);
697 return NULL;
698 }
699
700 return msg;
701}
702
703
704static struct nl_msg *
Hai Shalomc1a21442022-02-04 13:43:00 -0800705nl80211_ifindex_msg_build(struct wpa_driver_nl80211_data *drv,
706 struct nl_msg *msg, int ifindex, int flags,
707 uint8_t cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800708{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800709 if (!msg)
710 return NULL;
711
712 if (!nl80211_cmd(drv, msg, flags, cmd) ||
713 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
714 nlmsg_free(msg);
715 return NULL;
716 }
717
718 return msg;
719}
720
721
Hai Shalomc1a21442022-02-04 13:43:00 -0800722static struct nl_msg *
723nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
724 int flags, uint8_t cmd)
725{
726 return nl80211_ifindex_msg_build(drv, nlmsg_alloc(), ifindex, flags,
727 cmd);
728}
729
730
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800731struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
732 uint8_t cmd)
733{
734 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
735}
736
737
738struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
739{
740 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
741}
742
743
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800744struct wiphy_idx_data {
745 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700746 enum nl80211_iftype nlmode;
747 u8 *macaddr;
Hai Shalom60840252021-02-19 19:02:11 -0800748 u8 use_4addr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800749};
750
751
752static int netdev_info_handler(struct nl_msg *msg, void *arg)
753{
754 struct nlattr *tb[NL80211_ATTR_MAX + 1];
755 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
756 struct wiphy_idx_data *info = arg;
757
758 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
759 genlmsg_attrlen(gnlh, 0), NULL);
760
761 if (tb[NL80211_ATTR_WIPHY])
762 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
763
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700764 if (tb[NL80211_ATTR_IFTYPE])
765 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
766
767 if (tb[NL80211_ATTR_MAC] && info->macaddr)
768 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
769 ETH_ALEN);
770
Hai Shalom60840252021-02-19 19:02:11 -0800771 if (tb[NL80211_ATTR_4ADDR])
772 info->use_4addr = nla_get_u8(tb[NL80211_ATTR_4ADDR]);
773
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800774 return NL_SKIP;
775}
776
777
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800778int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800779{
780 struct nl_msg *msg;
781 struct wiphy_idx_data data = {
782 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700783 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800784 };
785
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800786 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
787 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800788
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000789 if (send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data) == 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800791 return -1;
792}
793
794
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700795static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
796{
797 struct nl_msg *msg;
798 struct wiphy_idx_data data = {
799 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
800 .macaddr = NULL,
801 };
802
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800803 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
804 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700805
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000806 if (send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data) == 0)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700807 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700808 return NL80211_IFTYPE_UNSPECIFIED;
809}
810
811
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700812static int nl80211_get_macaddr(struct i802_bss *bss)
813{
814 struct nl_msg *msg;
815 struct wiphy_idx_data data = {
816 .macaddr = bss->addr,
817 };
818
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800819 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
820 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700821
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000822 return send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700823}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700824
825
Hai Shalom60840252021-02-19 19:02:11 -0800826static int nl80211_get_4addr(struct i802_bss *bss)
827{
828 struct nl_msg *msg;
829 struct wiphy_idx_data data = {
830 .use_4addr = 0,
831 };
832
833 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000834 send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data))
Hai Shalom60840252021-02-19 19:02:11 -0800835 return -1;
836 return data.use_4addr;
837}
838
839
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800840static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
841 struct nl80211_wiphy_data *w)
842{
843 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800844 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800845
846 msg = nlmsg_alloc();
847 if (!msg)
848 return -1;
849
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
851 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
852 nlmsg_free(msg);
853 return -1;
854 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800855
Hai Shalom899fcc72020-10-19 14:38:18 -0700856 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000857 NULL, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800858 if (ret) {
859 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
860 "failed: ret=%d (%s)",
861 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800863 return ret;
864}
865
866
867static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
868{
869 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700870 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800871
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800872 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800873
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700874 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700875 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700876 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
877 __func__, res);
878 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800879}
880
881
882static int process_beacon_event(struct nl_msg *msg, void *arg)
883{
884 struct nl80211_wiphy_data *w = arg;
885 struct wpa_driver_nl80211_data *drv;
886 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
887 struct nlattr *tb[NL80211_ATTR_MAX + 1];
888 union wpa_event_data event;
889
890 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
891 genlmsg_attrlen(gnlh, 0), NULL);
892
893 if (gnlh->cmd != NL80211_CMD_FRAME) {
894 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
895 gnlh->cmd);
896 return NL_SKIP;
897 }
898
899 if (!tb[NL80211_ATTR_FRAME])
900 return NL_SKIP;
901
902 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
903 wiphy_list) {
904 os_memset(&event, 0, sizeof(event));
905 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
906 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
907 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
908 }
909
910 return NL_SKIP;
911}
912
913
914static struct nl80211_wiphy_data *
915nl80211_get_wiphy_data_ap(struct i802_bss *bss)
916{
917 static DEFINE_DL_LIST(nl80211_wiphys);
918 struct nl80211_wiphy_data *w;
919 int wiphy_idx, found = 0;
920 struct i802_bss *tmp_bss;
Paul Stewart092955c2017-02-06 09:13:09 -0800921 u8 channel;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800922
923 if (bss->wiphy_data != NULL)
924 return bss->wiphy_data;
925
926 wiphy_idx = nl80211_get_wiphy_index(bss);
927
928 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
929 if (w->wiphy_idx == wiphy_idx)
930 goto add;
931 }
932
933 /* alloc new one */
934 w = os_zalloc(sizeof(*w));
935 if (w == NULL)
936 return NULL;
937 w->wiphy_idx = wiphy_idx;
938 dl_list_init(&w->bsss);
939 dl_list_init(&w->drvs);
940
Paul Stewart092955c2017-02-06 09:13:09 -0800941 /* Beacon frames not supported in IEEE 802.11ad */
Sunil Ravi036cec52023-03-29 11:35:17 -0700942 if (ieee80211_freq_to_chan(bss->flink->freq, &channel) !=
Paul Stewart092955c2017-02-06 09:13:09 -0800943 HOSTAPD_MODE_IEEE80211AD) {
944 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
945 if (!w->nl_cb) {
946 os_free(w);
947 return NULL;
948 }
949 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
950 no_seq_check, NULL);
951 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
952 process_beacon_event, w);
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000953
Paul Stewart092955c2017-02-06 09:13:09 -0800954 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
955 "wiphy beacons");
956 if (w->nl_beacons == NULL) {
957 os_free(w);
958 return NULL;
959 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000960
Paul Stewart092955c2017-02-06 09:13:09 -0800961 if (nl80211_register_beacons(bss->drv, w)) {
962 nl_destroy_handles(&w->nl_beacons);
963 os_free(w);
964 return NULL;
965 }
Rebecca Silberstein055a67c2017-02-01 23:05:56 +0000966
Paul Stewart092955c2017-02-06 09:13:09 -0800967 nl80211_register_eloop_read(&w->nl_beacons,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700968 nl80211_recv_beacons, w, 0);
Paul Stewart092955c2017-02-06 09:13:09 -0800969 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800970
971 dl_list_add(&nl80211_wiphys, &w->list);
972
973add:
974 /* drv entry for this bss already there? */
975 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
976 if (tmp_bss->drv == bss->drv) {
977 found = 1;
978 break;
979 }
980 }
981 /* if not add it */
982 if (!found)
983 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
984
985 dl_list_add(&w->bsss, &bss->wiphy_list);
986 bss->wiphy_data = w;
987 return w;
988}
989
990
991static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
992{
993 struct nl80211_wiphy_data *w = bss->wiphy_data;
994 struct i802_bss *tmp_bss;
995 int found = 0;
996
997 if (w == NULL)
998 return;
999 bss->wiphy_data = NULL;
1000 dl_list_del(&bss->wiphy_list);
1001
1002 /* still any for this drv present? */
1003 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
1004 if (tmp_bss->drv == bss->drv) {
1005 found = 1;
1006 break;
1007 }
1008 }
1009 /* if not remove it */
1010 if (!found)
1011 dl_list_del(&bss->drv->wiphy_list);
1012
1013 if (!dl_list_empty(&w->bsss))
1014 return;
1015
Paul Stewart092955c2017-02-06 09:13:09 -08001016 if (w->nl_beacons)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001017 nl80211_destroy_eloop_handle(&w->nl_beacons, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001018
1019 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001020 dl_list_del(&w->list);
1021 os_free(w);
1022}
1023
1024
Dmitry Shmidte4663042016-04-04 10:07:49 -07001025static unsigned int nl80211_get_ifindex(void *priv)
1026{
1027 struct i802_bss *bss = priv;
1028 struct wpa_driver_nl80211_data *drv = bss->drv;
1029
1030 return drv->ifindex;
1031}
1032
1033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
1035{
1036 struct i802_bss *bss = priv;
1037 struct wpa_driver_nl80211_data *drv = bss->drv;
1038 if (!drv->associated)
1039 return -1;
1040 os_memcpy(bssid, drv->bssid, ETH_ALEN);
1041 return 0;
1042}
1043
1044
1045static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
1046{
1047 struct i802_bss *bss = priv;
1048 struct wpa_driver_nl80211_data *drv = bss->drv;
1049 if (!drv->associated)
1050 return -1;
1051 os_memcpy(ssid, drv->ssid, drv->ssid_len);
1052 return drv->ssid_len;
1053}
1054
1055
Sunil Ravi77d572f2023-01-17 23:58:31 +00001056static int get_mlo_info(struct nl_msg *msg, void *arg)
1057{
1058 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1059 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1060 struct nlattr *link_attr, *link_data[NL80211_ATTR_MAX + 1];
1061 static struct nla_policy link_policy[NL80211_ATTR_MAX + 1] = {
1062 [NL80211_ATTR_MLO_LINK_ID] = { .type = NLA_U8 },
1063 [NL80211_ATTR_MAC] = { .minlen = ETH_ALEN, .maxlen = ETH_ALEN },
1064 };
1065 struct driver_sta_mlo_info *info = arg;
1066 int rem;
1067
1068 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1069 genlmsg_attrlen(gnlh, 0), NULL);
1070
1071 if (!tb[NL80211_ATTR_MLO_LINKS])
1072 return NL_SKIP;
1073
1074 info->valid_links = 0;
1075 nla_for_each_nested(link_attr, tb[NL80211_ATTR_MLO_LINKS], rem) {
1076 u8 link_id;
1077
1078 if (nla_parse_nested(link_data, NL80211_ATTR_MAX,
1079 link_attr, link_policy) != 0)
1080 continue;
1081
1082 if (!link_data[NL80211_ATTR_MLO_LINK_ID] ||
1083 !link_data[NL80211_ATTR_MAC])
1084 continue;
1085
1086 link_id = nla_get_u8(link_data[NL80211_ATTR_MLO_LINK_ID]);
1087 if (link_id >= MAX_NUM_MLD_LINKS)
1088 continue;
1089 info->valid_links |= BIT(link_id);
1090 os_memcpy(info->links[link_id].addr,
1091 nla_data(link_data[NL80211_ATTR_MAC]), ETH_ALEN);
1092 if (link_data[NL80211_ATTR_WIPHY_FREQ])
1093 info->links[link_id].freq =
1094 nla_get_u32(link_data[NL80211_ATTR_WIPHY_FREQ]);
1095 }
1096
1097 return NL_SKIP;
1098}
1099
1100
Sunil Ravi89eba102022-09-13 21:04:37 -07001101static int nl80211_get_sta_mlo_info(void *priv,
1102 struct driver_sta_mlo_info *mlo_info)
1103{
1104 struct i802_bss *bss = priv;
1105 struct wpa_driver_nl80211_data *drv = bss->drv;
1106
1107 if (!drv->associated)
1108 return -1;
1109
Sunil Ravi77d572f2023-01-17 23:58:31 +00001110 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) {
1111 struct nl_msg *msg;
1112
1113 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001114 if (send_and_recv_resp(drv, msg, get_mlo_info,
1115 &drv->sta_mlo_info))
Sunil Ravi77d572f2023-01-17 23:58:31 +00001116 return -1;
1117 }
1118
Sunil Ravi89eba102022-09-13 21:04:37 -07001119 os_memcpy(mlo_info, &drv->sta_mlo_info, sizeof(*mlo_info));
1120 return 0;
1121}
1122
1123
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001124static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidte4663042016-04-04 10:07:49 -07001125 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
1126 int ifindex, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127{
1128 union wpa_event_data event;
1129
Dmitry Shmidte4663042016-04-04 10:07:49 -07001130 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001131 if (if_nametoindex(drv->first_bss->ifname) == 0) {
1132 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
1133 drv->first_bss->ifname);
1134 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001135 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001136 if (!drv->if_removed)
1137 return;
1138 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
1139 drv->first_bss->ifname);
1140 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141 }
1142
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001143 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -07001144 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001145 os_strlcpy(event.interface_status.ifname, ifname,
1146 sizeof(event.interface_status.ifname));
1147 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001148 if (drv)
1149 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
1150 else
1151 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
1152 &event);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001153}
1154
1155
1156static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidte4663042016-04-04 10:07:49 -07001157 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
1158 int ifindex, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001159{
1160 union wpa_event_data event;
1161
Dmitry Shmidte4663042016-04-04 10:07:49 -07001162 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001163 if (drv->if_removed) {
1164 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
1165 ifname);
1166 return;
1167 }
1168 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
1169 ifname);
1170 drv->if_removed = 1;
1171 } else {
1172 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
1173 ifname);
1174 }
1175
1176 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -07001177 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001178 os_strlcpy(event.interface_status.ifname, ifname,
1179 sizeof(event.interface_status.ifname));
1180 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001181 if (drv)
1182 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
1183 else
1184 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
1185 &event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186}
1187
1188
1189static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
1190 u8 *buf, size_t len)
1191{
1192 int attrlen, rta_len;
1193 struct rtattr *attr;
1194
1195 attrlen = len;
1196 attr = (struct rtattr *) buf;
1197
1198 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1199 while (RTA_OK(attr, attrlen)) {
1200 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001201 if (os_strcmp(((char *) attr) + rta_len,
1202 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001203 return 1;
1204 else
1205 break;
1206 }
1207 attr = RTA_NEXT(attr, attrlen);
1208 }
1209
1210 return 0;
1211}
1212
1213
1214static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
1215 int ifindex, u8 *buf, size_t len)
1216{
1217 if (drv->ifindex == ifindex)
1218 return 1;
1219
1220 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001221 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
1223 "interface");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001224 if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0)
1225 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 return 1;
1227 }
1228
1229 return 0;
1230}
1231
1232
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001233static struct wpa_driver_nl80211_data *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001234nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len,
1235 int *init_failed)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001236{
1237 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001238 int res;
1239
1240 if (init_failed)
1241 *init_failed = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001242 dl_list_for_each(drv, &global->interfaces,
1243 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001244 res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len);
1245 if (res < 0) {
1246 wpa_printf(MSG_DEBUG,
1247 "nl80211: Found matching own interface, but failed to complete reinitialization");
1248 if (init_failed)
1249 *init_failed = 1;
1250 return drv;
1251 }
1252 if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001253 return drv;
1254 }
1255 return NULL;
1256}
1257
1258
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001259static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001260 int ifindex, int notify)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001261{
1262 struct i802_bss *bss;
1263 u8 addr[ETH_ALEN];
1264
1265 bss = get_bss_ifindex(drv, ifindex);
1266 if (bss &&
1267 linux_get_ifhwaddr(drv->global->ioctl_sock,
1268 bss->ifname, addr) < 0) {
1269 wpa_printf(MSG_DEBUG,
1270 "nl80211: %s: failed to re-read MAC address",
1271 bss->ifname);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001272 } else if (bss && !ether_addr_equal(addr, bss->addr)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001273 wpa_printf(MSG_DEBUG,
1274 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1275 MACSTR " to " MACSTR,
1276 ifindex, bss->ifname,
1277 MAC2STR(bss->addr), MAC2STR(addr));
Sunil Ravi77d572f2023-01-17 23:58:31 +00001278 os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001279 os_memcpy(bss->addr, addr, ETH_ALEN);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001280 if (notify)
1281 wpa_supplicant_event(drv->ctx,
1282 EVENT_INTERFACE_MAC_CHANGED, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001283 }
1284}
1285
1286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
1288 struct ifinfomsg *ifi,
1289 u8 *buf, size_t len)
1290{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001291 struct nl80211_global *global = ctx;
1292 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001293 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294 struct rtattr *attr;
1295 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001296 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001297 char ifname[IFNAMSIZ + 1];
1298 char extra[100], *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001299 int init_failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001301 extra[0] = '\0';
1302 pos = extra;
1303 end = pos + sizeof(extra);
1304 ifname[0] = '\0';
1305
1306 attrlen = len;
1307 attr = (struct rtattr *) buf;
1308 while (RTA_OK(attr, attrlen)) {
1309 switch (attr->rta_type) {
1310 case IFLA_IFNAME:
Hai Shalomfdcde762020-04-02 11:19:20 -07001311 if (RTA_PAYLOAD(attr) > IFNAMSIZ)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001312 break;
1313 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1314 ifname[RTA_PAYLOAD(attr)] = '\0';
1315 break;
1316 case IFLA_MASTER:
1317 brid = nla_get_u32((struct nlattr *) attr);
1318 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1319 break;
1320 case IFLA_WIRELESS:
1321 pos += os_snprintf(pos, end - pos, " wext");
1322 break;
1323 case IFLA_OPERSTATE:
1324 pos += os_snprintf(pos, end - pos, " operstate=%u",
1325 nla_get_u32((struct nlattr *) attr));
1326 break;
1327 case IFLA_LINKMODE:
1328 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1329 nla_get_u32((struct nlattr *) attr));
1330 break;
1331 }
1332 attr = RTA_NEXT(attr, attrlen);
1333 }
1334 extra[sizeof(extra) - 1] = '\0';
1335
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001336 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1337 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1338 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001339 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1340 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1341 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1342 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1343
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001344 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001345 if (!drv)
1346 goto event_newlink;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001347 if (init_failed)
1348 return; /* do not update interface state */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001349
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001351 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001352 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001353 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001354 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1355 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001356 drv->ignore_if_down_event = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001357 /* Re-read MAC address as it may have changed */
1358 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001359 return;
1360 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001361 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
1362 namebuf, ifname);
1363 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1364 wpa_printf(MSG_DEBUG,
1365 "nl80211: Not the main interface (%s) - do not indicate interface down",
1366 drv->first_bss->ifname);
1367 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001368 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1369 "event generated by mode change");
1370 drv->ignore_if_down_event = 0;
1371 } else {
1372 drv->if_disabled = 1;
1373 wpa_supplicant_event(drv->ctx,
1374 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001375
1376 /*
1377 * Try to get drv again, since it may be removed as
1378 * part of the EVENT_INTERFACE_DISABLED handling for
1379 * dynamic interfaces
1380 */
1381 drv = nl80211_find_drv(global, ifi->ifi_index,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001382 buf, len, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001383 if (!drv)
1384 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001385 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 }
1387
1388 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07001389 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001390 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001391 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001392 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1393 "event since interface %s is down",
1394 namebuf);
Hai Shalomc9e41a12018-07-31 14:41:42 -07001395 return;
1396 }
1397 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
1398 namebuf, ifname);
1399 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1400 wpa_printf(MSG_DEBUG,
1401 "nl80211: Not the main interface (%s) - do not indicate interface up",
1402 drv->first_bss->ifname);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001403 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001404 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1405 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001406 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001407 } else if (drv->if_removed) {
1408 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1409 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001410 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001412 /* Re-read MAC address as it may have changed */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001413 nl80211_refresh_mac(drv, ifi->ifi_index, 0);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001414
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001415 drv->if_disabled = 0;
1416 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1417 NULL);
1418 }
Sunil Ravi90775442020-09-24 11:53:19 -07001419 } else if (ifi->ifi_flags & IFF_UP) {
1420 /* Re-read MAC address as it may have changed */
1421 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422 }
1423
1424 /*
1425 * Some drivers send the association event before the operup event--in
1426 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1427 * fails. This will hit us when wpa_supplicant does not need to do
1428 * IEEE 802.1X authentication
1429 */
1430 if (drv->operstate == 1 &&
1431 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001432 !(ifi->ifi_flags & IFF_RUNNING)) {
1433 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001434 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001436 }
1437
Dmitry Shmidte4663042016-04-04 10:07:49 -07001438event_newlink:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001439 if (ifname[0])
Dmitry Shmidte4663042016-04-04 10:07:49 -07001440 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1441 ifname);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001442
Dmitry Shmidte4663042016-04-04 10:07:49 -07001443 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001444 struct i802_bss *bss;
1445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001447 if (!if_indextoname(brid, namebuf)) {
1448 wpa_printf(MSG_DEBUG,
1449 "nl80211: Could not find bridge ifname for ifindex %u",
1450 brid);
1451 return;
1452 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001453 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1454 brid, namebuf);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001455 add_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001456
1457 for (bss = drv->first_bss; bss; bss = bss->next) {
1458 if (os_strcmp(ifname, bss->ifname) == 0) {
1459 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1460 break;
1461 }
1462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001464}
1465
1466
1467static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1468 struct ifinfomsg *ifi,
1469 u8 *buf, size_t len)
1470{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001471 struct nl80211_global *global = ctx;
1472 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001473 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474 struct rtattr *attr;
1475 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001476 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001477 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001478
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001479 extra[0] = '\0';
1480 pos = extra;
1481 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001482 ifname[0] = '\0';
1483
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 attrlen = len;
1485 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001486 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001487 switch (attr->rta_type) {
1488 case IFLA_IFNAME:
Hai Shalomfdcde762020-04-02 11:19:20 -07001489 if (RTA_PAYLOAD(attr) > IFNAMSIZ)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001490 break;
1491 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1492 ifname[RTA_PAYLOAD(attr)] = '\0';
1493 break;
1494 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001495 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001496 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1497 break;
1498 case IFLA_OPERSTATE:
1499 pos += os_snprintf(pos, end - pos, " operstate=%u",
1500 nla_get_u32((struct nlattr *) attr));
1501 break;
1502 case IFLA_LINKMODE:
1503 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1504 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001505 break;
1506 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001507 attr = RTA_NEXT(attr, attrlen);
1508 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001509 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001511 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1512 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1513 ifi->ifi_flags,
1514 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1515 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1516 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1517 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1518
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001519 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001520
Dmitry Shmidte4663042016-04-04 10:07:49 -07001521 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001522 /* device has been removed from bridge */
1523 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001524
1525 if (!if_indextoname(brid, namebuf)) {
1526 wpa_printf(MSG_DEBUG,
1527 "nl80211: Could not find bridge ifname for ifindex %u",
1528 brid);
1529 } else {
1530 wpa_printf(MSG_DEBUG,
1531 "nl80211: Remove ifindex %u for bridge %s",
1532 brid, namebuf);
1533 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001534 del_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001536
1537 if (ifi->ifi_family != AF_BRIDGE || !brid)
1538 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1539 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540}
1541
1542
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001543struct nl80211_get_assoc_freq_arg {
1544 struct wpa_driver_nl80211_data *drv;
1545 unsigned int assoc_freq;
1546 unsigned int ibss_freq;
1547 u8 assoc_bssid[ETH_ALEN];
1548 u8 assoc_ssid[SSID_MAX_LEN];
1549 u8 assoc_ssid_len;
Sunil Ravi89eba102022-09-13 21:04:37 -07001550 u8 bssid[MAX_NUM_MLD_LINKS][ETH_ALEN];
1551 unsigned int freq[MAX_NUM_MLD_LINKS];
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001552};
1553
1554static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg)
1555{
1556 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1557 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1558 struct nlattr *bss[NL80211_BSS_MAX + 1];
1559 static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
1560 [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC },
1561 [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
1562 [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC },
1563 [NL80211_BSS_STATUS] = { .type = NLA_U32 },
Sunil Ravi89eba102022-09-13 21:04:37 -07001564 [NL80211_BSS_MLO_LINK_ID] = { .type = NLA_U8 },
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001565 };
1566 struct nl80211_get_assoc_freq_arg *ctx = arg;
1567 enum nl80211_bss_status status;
Sunil Ravi89eba102022-09-13 21:04:37 -07001568 struct wpa_driver_nl80211_data *drv = ctx->drv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001569
1570 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1571 genlmsg_attrlen(gnlh, 0), NULL);
1572 if (!tb[NL80211_ATTR_BSS] ||
1573 nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS],
1574 bss_policy) ||
1575 !bss[NL80211_BSS_STATUS])
1576 return NL_SKIP;
1577
1578 status = nla_get_u32(bss[NL80211_BSS_STATUS]);
1579 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1580 bss[NL80211_BSS_FREQUENCY]) {
Sunil Ravi89eba102022-09-13 21:04:37 -07001581 int link_id = -1;
1582 u32 freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1583
1584 if (bss[NL80211_BSS_MLO_LINK_ID])
1585 link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]);
1586
1587 if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) {
1588 ctx->freq[link_id] = freq;
1589 wpa_printf(MSG_DEBUG,
1590 "nl80211: MLO link %d associated on %u MHz",
1591 link_id, ctx->freq[link_id]);
1592 }
1593
1594 if (!drv->sta_mlo_info.valid_links ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001595 drv->sta_mlo_info.assoc_link_id == link_id) {
Sunil Ravi89eba102022-09-13 21:04:37 -07001596 ctx->assoc_freq = freq;
1597 wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz",
1598 ctx->assoc_freq);
1599 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001600 }
1601 if (status == NL80211_BSS_STATUS_IBSS_JOINED &&
1602 bss[NL80211_BSS_FREQUENCY]) {
1603 ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1604 wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz",
1605 ctx->ibss_freq);
1606 }
1607 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1608 bss[NL80211_BSS_BSSID]) {
Sunil Ravi89eba102022-09-13 21:04:37 -07001609 int link_id = -1;
1610 const u8 *bssid = nla_data(bss[NL80211_BSS_BSSID]);
1611
1612 if (bss[NL80211_BSS_MLO_LINK_ID])
1613 link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]);
1614
1615 if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) {
1616 os_memcpy(ctx->bssid[link_id], bssid, ETH_ALEN);
1617 wpa_printf(MSG_DEBUG,
1618 "nl80211: MLO link %d associated with "
1619 MACSTR, link_id, MAC2STR(bssid));
1620 }
1621
1622 if (!drv->sta_mlo_info.valid_links ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001623 drv->sta_mlo_info.assoc_link_id == link_id) {
Sunil Ravi89eba102022-09-13 21:04:37 -07001624 os_memcpy(ctx->assoc_bssid, bssid, ETH_ALEN);
1625 wpa_printf(MSG_DEBUG, "nl80211: Associated with "
1626 MACSTR, MAC2STR(bssid));
1627 }
1628
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001629 }
1630
1631 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1632 bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
1633 const u8 *ie, *ssid;
1634 size_t ie_len;
1635
1636 ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1637 ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1638 ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
1639 if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) {
1640 ctx->assoc_ssid_len = ssid[1];
1641 os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]);
1642 }
1643 }
1644
1645 return NL_SKIP;
1646}
1647
1648
1649int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001650{
1651 struct nl_msg *msg;
1652 int ret;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001653 struct nl80211_get_assoc_freq_arg arg;
Hai Shalomfdcde762020-04-02 11:19:20 -07001654 int count = 0;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001655
Hai Shalomfdcde762020-04-02 11:19:20 -07001656try_again:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001657 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001658 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001659 arg.drv = drv;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001660 ret = send_and_recv_resp(drv, msg, nl80211_get_assoc_freq_handler,
1661 &arg);
Hai Shalomfdcde762020-04-02 11:19:20 -07001662 if (ret == -EAGAIN) {
1663 count++;
1664 if (count >= 10) {
1665 wpa_printf(MSG_INFO,
1666 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid");
1667 } else {
1668 wpa_printf(MSG_DEBUG,
1669 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again");
1670 goto try_again;
1671 }
1672 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001673 if (ret == 0) {
1674 os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len);
1675 return arg.assoc_ssid_len;
1676 }
1677 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)",
1678 ret, strerror(-ret));
1679 return ret;
1680}
1681
1682
1683unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
1684{
1685 struct nl_msg *msg;
1686 int ret;
1687 struct nl80211_get_assoc_freq_arg arg;
Hai Shalomfdcde762020-04-02 11:19:20 -07001688 int count = 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001689
Hai Shalomfdcde762020-04-02 11:19:20 -07001690try_again:
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001691 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1692 os_memset(&arg, 0, sizeof(arg));
1693 arg.drv = drv;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001694 ret = send_and_recv_resp(drv, msg, nl80211_get_assoc_freq_handler,
1695 &arg);
Hai Shalomfdcde762020-04-02 11:19:20 -07001696 if (ret == -EAGAIN) {
1697 count++;
1698 if (count >= 10) {
1699 wpa_printf(MSG_INFO,
1700 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq");
1701 } else {
1702 wpa_printf(MSG_DEBUG,
1703 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again");
1704 goto try_again;
1705 }
1706 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001707 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001708 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1709 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001710 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001711 "associated BSS from scan results: %u MHz", freq);
1712 if (freq)
1713 drv->assoc_freq = freq;
Sunil Ravi89eba102022-09-13 21:04:37 -07001714
1715 if (drv->sta_mlo_info.valid_links) {
1716 int i;
1717
1718 for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
1719 drv->sta_mlo_info.links[i].freq = arg.freq[i];
1720 }
1721
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001722 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001723 }
1724 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1725 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001726 return drv->assoc_freq;
1727}
1728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001729static int get_link_noise(struct nl_msg *msg, void *arg)
1730{
1731 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1732 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1733 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1734 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1735 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1736 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1737 };
1738 struct wpa_signal_info *sig_change = arg;
1739
1740 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1741 genlmsg_attrlen(gnlh, 0), NULL);
1742
1743 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1744 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1745 return NL_SKIP;
1746 }
1747
1748 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1749 tb[NL80211_ATTR_SURVEY_INFO],
1750 survey_policy)) {
1751 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1752 "attributes!");
1753 return NL_SKIP;
1754 }
1755
1756 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1757 return NL_SKIP;
1758
1759 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1760 sig_change->frequency)
1761 return NL_SKIP;
1762
1763 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1764 return NL_SKIP;
1765
1766 sig_change->current_noise =
1767 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1768
1769 return NL_SKIP;
1770}
1771
1772
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001773int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1774 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775{
1776 struct nl_msg *msg;
1777
Hai Shalom74f70d42019-02-11 14:42:39 -08001778 sig_change->current_noise = WPA_INVALID_NOISE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779 sig_change->frequency = drv->assoc_freq;
1780
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001781 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001782 return send_and_recv_resp(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001783}
1784
1785
Hai Shalom74f70d42019-02-11 14:42:39 -08001786static int get_channel_info(struct nl_msg *msg, void *arg)
1787{
1788 struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 };
1789 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1790 struct wpa_channel_info *chan_info = arg;
1791
1792 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1793 genlmsg_attrlen(gnlh, 0), NULL);
1794
1795 os_memset(chan_info, 0, sizeof(struct wpa_channel_info));
1796 chan_info->chanwidth = CHAN_WIDTH_UNKNOWN;
1797
1798 if (tb[NL80211_ATTR_WIPHY_FREQ])
1799 chan_info->frequency =
1800 nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
1801 if (tb[NL80211_ATTR_CHANNEL_WIDTH])
1802 chan_info->chanwidth = convert2width(
1803 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
1804 if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1805 enum nl80211_channel_type ct =
1806 nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1807
1808 switch (ct) {
1809 case NL80211_CHAN_HT40MINUS:
1810 chan_info->sec_channel = -1;
1811 break;
1812 case NL80211_CHAN_HT40PLUS:
1813 chan_info->sec_channel = 1;
1814 break;
1815 default:
1816 chan_info->sec_channel = 0;
1817 break;
1818 }
1819 }
1820 if (tb[NL80211_ATTR_CENTER_FREQ1])
1821 chan_info->center_frq1 =
1822 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
1823 if (tb[NL80211_ATTR_CENTER_FREQ2])
1824 chan_info->center_frq2 =
1825 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
1826
1827 if (chan_info->center_frq2) {
1828 u8 seg1_idx = 0;
1829
1830 if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) !=
1831 NUM_HOSTAPD_MODES)
1832 chan_info->seg1_idx = seg1_idx;
1833 }
1834
1835 return NL_SKIP;
1836}
1837
1838
1839static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci)
1840{
1841 struct i802_bss *bss = priv;
1842 struct wpa_driver_nl80211_data *drv = bss->drv;
1843 struct nl_msg *msg;
1844
1845 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001846 return send_and_recv_resp(drv, msg, get_channel_info, ci);
Hai Shalom74f70d42019-02-11 14:42:39 -08001847}
1848
1849
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1851 void *handle)
1852{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001853 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001854 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001856 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001858 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001859 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001860 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1861 __func__, res);
1862 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863}
1864
1865
1866/**
1867 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1868 * @priv: driver_nl80211 private data
1869 * @alpha2_arg: country to which to switch to
1870 * Returns: 0 on success, -1 on failure
1871 *
1872 * This asks nl80211 to set the regulatory domain for given
1873 * country ISO / IEC alpha2.
1874 */
1875static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1876{
1877 struct i802_bss *bss = priv;
1878 struct wpa_driver_nl80211_data *drv = bss->drv;
1879 char alpha2[3];
1880 struct nl_msg *msg;
1881
1882 msg = nlmsg_alloc();
1883 if (!msg)
1884 return -ENOMEM;
1885
1886 alpha2[0] = alpha2_arg[0];
1887 alpha2[1] = alpha2_arg[1];
1888 alpha2[2] = '\0';
1889
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001890 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1891 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1892 nlmsg_free(msg);
1893 return -EINVAL;
1894 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001895 if (send_and_recv_cmd(drv, msg))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896 return -EINVAL;
1897 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001898}
1899
1900
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001901static int nl80211_get_country(struct nl_msg *msg, void *arg)
1902{
1903 char *alpha2 = arg;
1904 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1905 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1906
1907 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1908 genlmsg_attrlen(gnlh, 0), NULL);
1909 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1910 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1911 return NL_SKIP;
1912 }
1913 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1914 return NL_SKIP;
1915}
1916
1917
1918static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1919{
1920 struct i802_bss *bss = priv;
1921 struct wpa_driver_nl80211_data *drv = bss->drv;
1922 struct nl_msg *msg;
1923 int ret;
1924
1925 msg = nlmsg_alloc();
1926 if (!msg)
1927 return -ENOMEM;
1928
1929 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
Sunil Ravi036cec52023-03-29 11:35:17 -07001930
1931 if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) {
1932 /* put wiphy idx to get the interface specific country code
1933 * instead of the global one. */
1934 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) {
1935 nlmsg_free(msg);
1936 return -1;
1937 }
1938 }
1939
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001940 alpha2[0] = '\0';
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001941 ret = send_and_recv_resp(drv, msg, nl80211_get_country, alpha2);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001942 if (!alpha2[0])
1943 ret = -1;
1944
1945 return ret;
1946}
1947
1948
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001949static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001950{
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001951 struct nl_cache *cache = NULL;
1952 struct genl_family *family = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953 int ret;
1954
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001955 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1956 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1958 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001959 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960 }
1961
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001962 global->nl = nl_create_handle(global->nl_cb, "nl");
1963 if (global->nl == NULL)
1964 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001965
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001966 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1967 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1969 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001970 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 }
1972
Hai Shalomc1a21442022-02-04 13:43:00 -08001973 global->nlctrl_id = genl_ctrl_resolve(global->nl, "nlctrl");
1974 if (global->nlctrl_id < 0) {
1975 wpa_printf(MSG_ERROR,
1976 "nl80211: 'nlctrl' generic netlink not found");
1977 goto err;
1978 }
1979
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001980 global->nl_event = nl_create_handle(global->nl_cb, "event");
1981 if (global->nl_event == NULL)
1982 goto err;
1983
1984 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001985 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001986 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 if (ret < 0) {
1988 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1989 "membership for scan events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07001990 ret, nl_geterror(ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001991 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001992 }
1993
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001994 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001995 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001996 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997 if (ret < 0) {
1998 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1999 "membership for mlme events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07002000 ret, nl_geterror(ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002001 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002 }
2003
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002004 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002006 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007 if (ret < 0) {
2008 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
2009 "membership for regulatory events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07002010 ret, nl_geterror(ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002011 /* Continue without regulatory events */
2012 }
2013
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002014 ret = nl_get_multicast_id(global, "nl80211", "vendor");
2015 if (ret >= 0)
2016 ret = nl_socket_add_membership(global->nl_event, ret);
2017 if (ret < 0) {
2018 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
2019 "membership for vendor events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07002020 ret, nl_geterror(ret));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002021 /* Continue without vendor events */
2022 }
2023
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002024 /* Resolve maxattr for kernel support checks */
2025 ret = genl_ctrl_alloc_cache(global->nl, &cache);
2026 if (ret < 0) {
2027 wpa_printf(MSG_DEBUG,
2028 "nl80211: Could not allocate genl cache: %d (%s)",
2029 ret, nl_geterror(ret));
2030 goto err;
2031 }
2032
2033 family = genl_ctrl_search(cache, global->nl80211_id);
2034 if (!family) {
2035 wpa_printf(MSG_DEBUG,
2036 "nl80211: Could not get nl80211 family from cache: %d (%s)",
2037 ret, nl_geterror(ret));
2038 goto err;
2039 }
2040
2041 global->nl80211_maxattr = genl_family_get_maxattr(family);
2042 wpa_printf(MSG_DEBUG, "nl80211: Maximum supported attribute ID: %u",
2043 global->nl80211_maxattr);
2044 genl_family_put(family);
2045 nl_cache_free(cache);
2046
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002047 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
2048 no_seq_check, NULL);
2049 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
2050 process_global_event, global);
2051
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002052 nl80211_register_eloop_read(&global->nl_event,
2053 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002054 global->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002055
2056 return 0;
2057
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002058err:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002059 genl_family_put(family);
2060 nl_cache_free(cache);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002061 nl_destroy_handles(&global->nl_event);
2062 nl_destroy_handles(&global->nl);
2063 nl_cb_put(global->nl_cb);
2064 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002065 return -1;
2066}
2067
2068
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002069static void nl80211_check_global(struct nl80211_global *global)
2070{
Hai Shalomfdcde762020-04-02 11:19:20 -07002071 struct nl_sock *handle;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002072 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
2073 int ret;
2074 unsigned int i;
2075
2076 /*
2077 * Try to re-add memberships to handle case of cfg80211 getting reloaded
2078 * and all registration having been cleared.
2079 */
2080 handle = (void *) (((intptr_t) global->nl_event) ^
2081 ELOOP_SOCKET_INVALID);
2082
2083 for (i = 0; groups[i]; i++) {
2084 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
2085 if (ret >= 0)
2086 ret = nl_socket_add_membership(handle, ret);
2087 if (ret < 0) {
2088 wpa_printf(MSG_INFO,
2089 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
Hai Shalomfdcde762020-04-02 11:19:20 -07002090 groups[i], ret, nl_geterror(ret));
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002091 }
2092 }
2093}
2094
2095
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002096static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
2097{
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002098 struct wpa_driver_nl80211_data *drv = ctx;
2099
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002100 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 /*
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002103 * rtnetlink ifdown handler will report interfaces other than the P2P
2104 * Device interface as disabled.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002105 */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002106 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2107 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002108}
2109
2110
2111static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
2112{
2113 struct wpa_driver_nl80211_data *drv = ctx;
2114 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002115 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
2117 "after rfkill unblock");
2118 return;
2119 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002120
2121 if (is_p2p_net_interface(drv->nlmode))
2122 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
2123
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002124 /*
2125 * rtnetlink ifup handler will report interfaces other than the P2P
2126 * Device interface as enabled.
2127 */
2128 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2129 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002130}
2131
2132
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002133static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
2134 void *eloop_ctx,
2135 void *handle)
2136{
2137 struct wpa_driver_nl80211_data *drv = eloop_ctx;
2138 u8 data[2048];
2139 struct msghdr msg;
2140 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002141 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002142 struct cmsghdr *cmsg;
2143 int res, found_ee = 0, found_wifi = 0, acked = 0;
2144 union wpa_event_data event;
2145
2146 memset(&msg, 0, sizeof(msg));
2147 msg.msg_iov = &entry;
2148 msg.msg_iovlen = 1;
2149 entry.iov_base = data;
2150 entry.iov_len = sizeof(data);
2151 msg.msg_control = &control;
2152 msg.msg_controllen = sizeof(control);
2153
2154 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
2155 /* if error or not fitting 802.3 header, return */
2156 if (res < 14)
2157 return;
2158
2159 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
2160 {
2161 if (cmsg->cmsg_level == SOL_SOCKET &&
2162 cmsg->cmsg_type == SCM_WIFI_STATUS) {
2163 int *ack;
2164
2165 found_wifi = 1;
2166 ack = (void *)CMSG_DATA(cmsg);
2167 acked = *ack;
2168 }
2169
2170 if (cmsg->cmsg_level == SOL_PACKET &&
2171 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
2172 struct sock_extended_err *err =
2173 (struct sock_extended_err *)CMSG_DATA(cmsg);
2174
2175 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
2176 found_ee = 1;
2177 }
2178 }
2179
2180 if (!found_ee || !found_wifi)
2181 return;
2182
2183 memset(&event, 0, sizeof(event));
2184 event.eapol_tx_status.dst = data;
2185 event.eapol_tx_status.data = data + 14;
2186 event.eapol_tx_status.data_len = res - 14;
2187 event.eapol_tx_status.ack = acked;
2188 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
2189}
2190
2191
Hai Shalomb755a2a2020-04-23 21:49:02 -07002192static int nl80211_init_connect_handle(struct i802_bss *bss)
2193{
2194 if (bss->nl_connect) {
2195 wpa_printf(MSG_DEBUG,
2196 "nl80211: Connect handle already created (nl_connect=%p)",
2197 bss->nl_connect);
2198 return -1;
2199 }
2200
2201 bss->nl_connect = nl_create_handle(bss->nl_cb, "connect");
2202 if (!bss->nl_connect)
2203 return -1;
2204 nl80211_register_eloop_read(&bss->nl_connect,
2205 wpa_driver_nl80211_event_receive,
2206 bss->nl_cb, 1);
2207 return 0;
2208}
2209
2210
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002211static int nl80211_init_bss(struct i802_bss *bss)
2212{
2213 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
2214 if (!bss->nl_cb)
2215 return -1;
2216
2217 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
2218 no_seq_check, NULL);
2219 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
2220 process_bss_event, bss);
2221
Hai Shalomb755a2a2020-04-23 21:49:02 -07002222 nl80211_init_connect_handle(bss);
2223
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002224 return 0;
2225}
2226
2227
2228static void nl80211_destroy_bss(struct i802_bss *bss)
2229{
2230 nl_cb_put(bss->nl_cb);
2231 bss->nl_cb = NULL;
Hai Shalomb755a2a2020-04-23 21:49:02 -07002232
2233 if (bss->nl_connect)
2234 nl80211_destroy_eloop_handle(&bss->nl_connect, 1);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002235}
2236
2237
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002238static void
2239wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
2240{
2241 struct rfkill_config *rcfg;
2242
2243 if (drv->rfkill)
2244 return;
2245
2246 rcfg = os_zalloc(sizeof(*rcfg));
2247 if (!rcfg)
2248 return;
2249
2250 rcfg->ctx = drv;
2251
2252 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
2253 * not associated with a netdev, so use the name of some other interface
2254 * sharing the same wiphy as the P2P Device interface.
2255 *
2256 * Note: This is valid, as a P2P Device interface is always dynamically
2257 * created and is created only once another wpa_s interface was added.
2258 */
2259 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
2260 struct nl80211_global *global = drv->global;
2261 struct wpa_driver_nl80211_data *tmp1;
2262
2263 dl_list_for_each(tmp1, &global->interfaces,
2264 struct wpa_driver_nl80211_data, list) {
2265 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
2266 !tmp1->rfkill)
2267 continue;
2268
2269 wpa_printf(MSG_DEBUG,
2270 "nl80211: Use (%s) to initialize P2P Device rfkill",
2271 tmp1->first_bss->ifname);
2272 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
2273 sizeof(rcfg->ifname));
2274 break;
2275 }
2276 } else {
2277 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
2278 sizeof(rcfg->ifname));
2279 }
2280
2281 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
2282 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
2283 drv->rfkill = rfkill_init(rcfg);
2284 if (!drv->rfkill) {
2285 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
2286 os_free(rcfg);
2287 }
2288}
2289
2290
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002291static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
2292 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002293 const u8 *set_addr,
2294 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295{
2296 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002297 struct i802_bss *bss;
Sunil Ravi88611412024-06-28 17:34:56 +00002298 unsigned int i;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002299 char path[128], buf[200], *pos;
2300 ssize_t len;
2301 int ret;
2302
2303 ret = os_snprintf(path, sizeof(path), "/sys/class/net/%s/device/driver",
2304 ifname);
2305 if (!os_snprintf_error(sizeof(path), ret)) {
2306 len = readlink(path, buf, sizeof(buf));
2307 if (len > 0 && (size_t) len < sizeof(buf)) {
2308 buf[len] = '\0';
2309 pos = strrchr(buf, '/');
2310 if (pos)
2311 pos++;
2312 else
2313 pos = buf;
2314 wpa_printf(MSG_DEBUG,
2315 "nl80211: Initialize interface %s (driver: %s)",
2316 ifname, pos);
2317 }
2318 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002320 if (global_priv == NULL)
2321 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 drv = os_zalloc(sizeof(*drv));
2323 if (drv == NULL)
2324 return NULL;
2325 drv->global = global_priv;
2326 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002327 drv->hostapd = !!hostapd;
2328 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002329
2330 /*
2331 * There is no driver capability flag for this, so assume it is
2332 * supported and disable this on first attempt to use if the driver
2333 * rejects the command due to missing support.
2334 */
2335 drv->set_rekey_offload = 1;
2336
Hai Shalom81f62d82019-07-22 12:10:00 -07002337 drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002338 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002339
2340 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
2341 if (!drv->first_bss) {
2342 os_free(drv);
2343 return NULL;
2344 }
2345 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002346 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002347 bss->ctx = ctx;
2348
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002349 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
2350 drv->monitor_ifidx = -1;
2351 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002352 drv->eapol_tx_sock = -1;
2353 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002354
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002355 if (nl80211_init_bss(bss))
2356 goto failed;
2357
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002358 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002359 goto failed;
2360
Hai Shalom899fcc72020-10-19 14:38:18 -07002361 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) {
2362 drv->control_port_ap = 1;
2363 goto skip_wifi_status;
2364 }
2365
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002366 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
2367 if (drv->eapol_tx_sock < 0)
2368 goto failed;
2369
2370 if (drv->data_tx_status) {
2371 int enabled = 1;
2372
2373 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
2374 &enabled, sizeof(enabled)) < 0) {
2375 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07002376 "nl80211: wifi status sockopt failed: %s",
2377 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002378 drv->data_tx_status = 0;
2379 if (!drv->use_monitor)
2380 drv->capa.flags &=
2381 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
2382 } else {
Hai Shalom899fcc72020-10-19 14:38:18 -07002383 eloop_register_read_sock(
2384 drv->eapol_tx_sock,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002385 wpa_driver_nl80211_handle_eapol_tx_status,
2386 drv, NULL);
2387 }
2388 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002389skip_wifi_status:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002390
2391 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002392 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002393 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002394 drv->in_interface_list = 1;
2395 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396
Sunil Ravi036cec52023-03-29 11:35:17 -07002397 /*
Sunil Ravi88611412024-06-28 17:34:56 +00002398 * Set the default link to be the first one, and set its address to that
2399 * of the interface.
Sunil Ravi036cec52023-03-29 11:35:17 -07002400 */
2401 bss->flink = &bss->links[0];
Sunil Ravi88611412024-06-28 17:34:56 +00002402 bss->n_links = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07002403 os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN);
2404
Sunil Ravi88611412024-06-28 17:34:56 +00002405 for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
2406 bss->links[i].link_id = NL80211_DRV_LINK_ID_NA;
2407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408 return bss;
2409
2410failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002411 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 return NULL;
2413}
2414
2415
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002416/**
2417 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2418 * @ctx: context to be used when calling wpa_supplicant functions,
2419 * e.g., wpa_supplicant_event()
2420 * @ifname: interface name, e.g., wlan0
2421 * @global_priv: private driver global data from global_init()
2422 * Returns: Pointer to private data, %NULL on failure
2423 */
2424static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
2425 void *global_priv)
2426{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002427 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
2428 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002429}
2430
2431
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002432static int nl80211_register_frame(struct i802_bss *bss,
Hai Shalomfdcde762020-04-02 11:19:20 -07002433 struct nl_sock *nl_handle,
Hai Shalome21d4e82020-04-29 16:34:06 -07002434 u16 type, const u8 *match, size_t match_len,
2435 bool multicast)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002436{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002437 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002439 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002440 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002441
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002442 buf[0] = '\0';
2443 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Hai Shalome21d4e82020-04-29 16:34:06 -07002444 wpa_printf(MSG_DEBUG,
2445 "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d",
2446 type, fc2str(type), nl_handle, buf, multicast);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002447
Hai Shalomfdcde762020-04-02 11:19:20 -07002448 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) ||
Hai Shalome21d4e82020-04-29 16:34:06 -07002449 (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002450 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
2451 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
2452 nlmsg_free(msg);
2453 return -1;
2454 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002455
Hai Shalom899fcc72020-10-19 14:38:18 -07002456 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002457 NULL, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458 if (ret) {
2459 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
2460 "failed (type=%u): ret=%d (%s)",
2461 type, ret, strerror(-ret));
2462 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
2463 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002464 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002465 return ret;
2466}
2467
2468
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002469static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
2470{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002471 if (bss->nl_mgmt) {
2472 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
2473 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
2474 return -1;
2475 }
2476
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002477 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002478 if (bss->nl_mgmt == NULL)
2479 return -1;
2480
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002481 return 0;
2482}
2483
2484
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002485static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
2486{
2487 nl80211_register_eloop_read(&bss->nl_mgmt,
2488 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002489 bss->nl_cb, 0);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002490}
2491
2492
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002493static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 const u8 *match, size_t match_len)
2495{
2496 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002497 return nl80211_register_frame(bss, bss->nl_mgmt,
Hai Shalome21d4e82020-04-29 16:34:06 -07002498 type, match, match_len, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499}
2500
2501
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002502static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002503{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002504 struct wpa_driver_nl80211_data *drv = bss->drv;
Hai Shalomfdcde762020-04-02 11:19:20 -07002505 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002506 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002507
2508 if (nl80211_alloc_mgmt_handle(bss))
2509 return -1;
2510 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
2511 "handle %p", bss->nl_mgmt);
2512
Hai Shalomfdcde762020-04-02 11:19:20 -07002513 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002514 /* register for any AUTH message */
Hai Shalome21d4e82020-04-29 16:34:06 -07002515 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false);
Hai Shalomfdcde762020-04-02 11:19:20 -07002516 } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
2517 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
2518 /* register for SAE Authentication frames */
2519 nl80211_register_frame(bss, bss->nl_mgmt, type,
Hai Shalome21d4e82020-04-29 16:34:06 -07002520 (u8 *) "\x03\x00", 2, false);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002521 }
2522
Hai Shalom60840252021-02-19 19:02:11 -08002523#ifdef CONFIG_PASN
2524 /* register for PASN Authentication frames */
Sunil Ravi89eba102022-09-13 21:04:37 -07002525 if (nl80211_register_frame(bss, bss->nl_mgmt, type,
Hai Shalom60840252021-02-19 19:02:11 -08002526 (u8 *) "\x07\x00", 2, false))
2527 ret = -1;
2528#endif /* CONFIG_PASN */
2529
Dmitry Shmidt051af732013-10-22 13:52:46 -07002530#ifdef CONFIG_INTERWORKING
2531 /* QoS Map Configure */
2532 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002533 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002534#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002535#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002536 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002537 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002538 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002539 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002540 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002541 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002542 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002543 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002544 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002546 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002547 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08002548 /* Protected GAS Initial Request */
2549 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
2550 ret = -1;
2551 /* Protected GAS Initial Response */
2552 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
2553 ret = -1;
2554 /* Protected GAS Comeback Request */
2555 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
2556 ret = -1;
2557 /* Protected GAS Comeback Response */
2558 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
2559 ret = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002560#endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002561#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002563 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
2565 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002566 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002567 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002568 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569 (u8 *) "\x7f\x50\x6f\x9a\x09",
2570 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002571 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572#endif /* CONFIG_P2P */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002573#ifdef CONFIG_NAN_USD
2574 /* NAN SDF Public Action */
2575 if (nl80211_register_action_frame(bss,
2576 (u8 *) "\x04\x09\x50\x6f\x9a\x13",
2577 6) < 0)
2578 ret = -1;
2579#endif /* CONFIG_NAN_USD */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002580#ifdef CONFIG_DPP
2581 /* DPP Public Action */
2582 if (nl80211_register_action_frame(bss,
2583 (u8 *) "\x04\x09\x50\x6f\x9a\x1a",
2584 6) < 0)
2585 ret = -1;
2586#endif /* CONFIG_DPP */
Hai Shalom74f70d42019-02-11 14:42:39 -08002587#ifdef CONFIG_OCV
2588 /* SA Query Request */
2589 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0)
2590 ret = -1;
2591#endif /* CONFIG_OCV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002593 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002594 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002595#ifdef CONFIG_TDLS
2596 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
2597 /* TDLS Discovery Response */
2598 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
2599 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002600 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002601 }
2602#endif /* CONFIG_TDLS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002603#ifdef CONFIG_FST
2604 /* FST Action frames */
2605 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2606 ret = -1;
2607#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608
2609 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002610 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002611 ret = -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002612 else if (!drv->has_driver_key_mgmt) {
2613 int i;
2614
2615 /* Update supported AKMs only if the driver doesn't advertize
2616 * any AKM capabilities. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002617 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
2618 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2619
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002620 /* Update per interface supported AKMs */
2621 for (i = 0; i < WPA_IF_MAX; i++)
2622 drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt;
2623 }
2624
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002625 /* WNM - BSS Transition Management Request */
2626 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002627 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002628 /* WNM-Sleep Mode Response */
2629 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002630 ret = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002631#ifdef CONFIG_WNM
2632 /* WNM - Collocated Interference Request */
2633 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0)
2634 ret = -1;
2635#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002636
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002637#ifdef CONFIG_HS20
2638 /* WNM-Notification */
2639 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002640 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002641#endif /* CONFIG_HS20 */
2642
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002643 /* WMM-AC ADDTS Response */
2644 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
2645 ret = -1;
2646
2647 /* WMM-AC DELTS */
2648 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
2649 ret = -1;
2650
2651 /* Radio Measurement - Neighbor Report Response */
2652 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
2653 ret = -1;
2654
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002655 /* Radio Measurement - Radio Measurement Request */
Hai Shalom899fcc72020-10-19 14:38:18 -07002656 if (!drv->no_rrm &&
2657 nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0)
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002658 ret = -1;
2659
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002660 /* Radio Measurement - Link Measurement Request */
2661 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
2662 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
2663 ret = -1;
2664
Hai Shalomc1a21442022-02-04 13:43:00 -08002665 /* Robust AV SCS Response */
2666 if (nl80211_register_action_frame(bss, (u8 *) "\x13\x01", 2) < 0)
2667 ret = -1;
2668
Hai Shalom899fcc72020-10-19 14:38:18 -07002669 /* Robust AV MSCS Response */
2670 if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0)
2671 ret = -1;
2672
Hai Shalomc1a21442022-02-04 13:43:00 -08002673 /* Protected QoS Management Action frame */
2674 if (nl80211_register_action_frame(bss, (u8 *) "\x7e\x50\x6f\x9a\x1a",
2675 5) < 0)
2676 ret = -1;
2677
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002678 nl80211_mgmt_handle_register_eloop(bss);
2679
2680 return ret;
2681}
2682
2683
2684static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2685{
2686 int ret = 0;
2687
2688 if (nl80211_alloc_mgmt_handle(bss))
2689 return -1;
2690
2691 wpa_printf(MSG_DEBUG,
2692 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2693 bss->nl_mgmt);
2694
2695 /* Auth frames for mesh SAE */
2696 if (nl80211_register_frame(bss, bss->nl_mgmt,
2697 (WLAN_FC_TYPE_MGMT << 2) |
2698 (WLAN_FC_STYPE_AUTH << 4),
Hai Shalome21d4e82020-04-29 16:34:06 -07002699 NULL, 0, false) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002700 ret = -1;
2701
2702 /* Mesh peering open */
2703 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2704 ret = -1;
2705 /* Mesh peering confirm */
2706 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2707 ret = -1;
2708 /* Mesh peering close */
2709 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2710 ret = -1;
2711
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002712 nl80211_mgmt_handle_register_eloop(bss);
2713
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002714 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002715}
2716
2717
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002718static int nl80211_register_spurious_class3(struct i802_bss *bss)
2719{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002720 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002721 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002722
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002723 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
Hai Shalom899fcc72020-10-19 14:38:18 -07002724 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002725 NULL, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002726 if (ret) {
2727 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2728 "failed: ret=%d (%s)",
2729 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002730 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002731 return ret;
2732}
2733
2734
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002735static int nl80211_action_subscribe_ap(struct i802_bss *bss)
2736{
2737 int ret = 0;
2738
2739 /* Public Action frames */
2740 if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0)
2741 ret = -1;
2742 /* RRM Measurement Report */
2743 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0)
2744 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08002745 /* RRM Link Measurement Report */
2746 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0)
2747 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002748 /* RRM Neighbor Report Request */
2749 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0)
2750 ret = -1;
2751 /* FT Action frames */
2752 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2753 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002754 /* SA Query */
2755 if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0)
2756 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002757 /* Protected Dual of Public Action */
2758 if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0)
2759 ret = -1;
2760 /* WNM */
2761 if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0)
2762 ret = -1;
2763 /* WMM */
2764 if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0)
2765 ret = -1;
2766#ifdef CONFIG_FST
2767 /* FST Action frames */
2768 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2769 ret = -1;
2770#endif /* CONFIG_FST */
2771 /* Vendor-specific */
2772 if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0)
2773 ret = -1;
2774
2775 return ret;
2776}
2777
2778
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002779static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2780{
2781 static const int stypes[] = {
2782 WLAN_FC_STYPE_AUTH,
2783 WLAN_FC_STYPE_ASSOC_REQ,
2784 WLAN_FC_STYPE_REASSOC_REQ,
2785 WLAN_FC_STYPE_DISASSOC,
2786 WLAN_FC_STYPE_DEAUTH,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002787 WLAN_FC_STYPE_PROBE_REQ,
2788/* Beacon doesn't work as mac80211 doesn't currently allow
2789 * it, but it wouldn't really be the right thing anyway as
2790 * it isn't per interface ... maybe just dump the scan
2791 * results periodically for OLBC?
2792 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002793 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002794 };
2795 unsigned int i;
2796
2797 if (nl80211_alloc_mgmt_handle(bss))
2798 return -1;
2799 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2800 "handle %p", bss->nl_mgmt);
2801
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002802 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002803 if (nl80211_register_frame(bss, bss->nl_mgmt,
2804 (WLAN_FC_TYPE_MGMT << 2) |
2805 (stypes[i] << 4),
Hai Shalome21d4e82020-04-29 16:34:06 -07002806 NULL, 0, false) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002807 goto out_err;
2808 }
2809 }
2810
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002811 if (nl80211_action_subscribe_ap(bss))
2812 goto out_err;
2813
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002814 if (nl80211_register_spurious_class3(bss))
2815 goto out_err;
2816
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002817 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002818 return 0;
2819
2820out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002821 nl_destroy_handles(&bss->nl_mgmt);
2822 return -1;
2823}
2824
2825
2826static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2827{
2828 if (nl80211_alloc_mgmt_handle(bss))
2829 return -1;
2830 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2831 "handle %p (device SME)", bss->nl_mgmt);
2832
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002833 if (nl80211_action_subscribe_ap(bss))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002834 goto out_err;
2835
Hai Shalom5f92bc92019-04-18 11:54:11 -07002836 if (bss->drv->device_ap_sme) {
2837 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2838
2839 /* Register for all Authentication frames */
Hai Shalome21d4e82020-04-29 16:34:06 -07002840 if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0,
2841 false) < 0)
Hai Shalom5f92bc92019-04-18 11:54:11 -07002842 wpa_printf(MSG_DEBUG,
2843 "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work");
2844 }
2845
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002846 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002847 return 0;
2848
2849out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002850 nl_destroy_handles(&bss->nl_mgmt);
2851 return -1;
2852}
2853
2854
2855static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2856{
2857 if (bss->nl_mgmt == NULL)
2858 return;
2859 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2860 "(%s)", bss->nl_mgmt, reason);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002861 nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002862
2863 nl80211_put_wiphy_data_ap(bss);
2864}
2865
2866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2868{
2869 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2870}
2871
2872
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002873static void nl80211_del_p2pdev(struct i802_bss *bss)
2874{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002875 struct nl_msg *msg;
2876 int ret;
2877
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002878 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002879 ret = send_and_recv_cmd(bss->drv, msg);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002880
2881 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2882 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002883 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002884}
2885
2886
2887static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2888{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002889 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002890 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002891
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002892 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2893 NL80211_CMD_STOP_P2P_DEVICE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002894 ret = send_and_recv_cmd(bss->drv, msg);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002895
2896 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2897 start ? "Start" : "Stop",
2898 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002899 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002900 return ret;
2901}
2902
2903
2904static int i802_set_iface_flags(struct i802_bss *bss, int up)
2905{
2906 enum nl80211_iftype nlmode;
2907
2908 nlmode = nl80211_get_ifmode(bss);
2909 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2910 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2911 bss->ifname, up);
2912 }
2913
2914 /* P2P Device has start/stop which is equivalent */
2915 return nl80211_set_p2pdev(bss, up);
2916}
2917
2918
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002919#ifdef CONFIG_TESTING_OPTIONS
2920static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2921{
2922 /* struct wpa_driver_nl80211_data *drv = arg; */
2923 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2924 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2925
2926
2927 wpa_printf(MSG_DEBUG,
2928 "nl80211: QCA vendor test command response received");
2929
2930 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2931 genlmsg_attrlen(gnlh, 0), NULL);
2932 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2933 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2934 return NL_SKIP;
2935 }
2936
2937 wpa_hexdump(MSG_DEBUG,
2938 "nl80211: Received QCA vendor test command response",
2939 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2940 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2941
2942 return NL_SKIP;
2943}
2944#endif /* CONFIG_TESTING_OPTIONS */
2945
2946
2947static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2948{
2949#ifdef CONFIG_TESTING_OPTIONS
2950 struct nl_msg *msg;
2951 struct nlattr *params;
2952 int ret;
2953
2954 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2955 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2956 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2957 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2958 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2959 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2960 nlmsg_free(msg);
2961 return;
2962 }
2963 nla_nest_end(msg, params);
2964
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002965 ret = send_and_recv_resp(drv, msg, qca_vendor_test_cmd_handler, drv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002966 wpa_printf(MSG_DEBUG,
2967 "nl80211: QCA vendor test command returned %d (%s)",
2968 ret, strerror(-ret));
2969#endif /* CONFIG_TESTING_OPTIONS */
2970}
2971
2972
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002973static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002974wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002975 const u8 *set_addr, int first,
2976 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002977{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002978 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002979 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002980 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981
2982 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002983 bss->ifindex = drv->ifindex;
2984 bss->wdev_id = drv->global->if_add_wdevid;
2985 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2986
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002987 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2988 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002989 drv->global->if_add_wdevid_set = 0;
2990
Dmitry Shmidt03658832014-08-13 11:03:49 -07002991 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2992 bss->static_ap = 1;
2993
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002994 if (first &&
2995 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2996 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2997 drv->start_iface_up = 1;
2998
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002999 if (wpa_driver_nl80211_capa(drv))
3000 return -1;
3001
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003002 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
3003 return -1;
3004
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003005 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
3006 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003008 if (set_addr &&
3009 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
3010 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
3011 set_addr)))
3012 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003013
Hai Shalomc1a21442022-02-04 13:43:00 -08003014 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_STATION)
3015 drv->start_mode_sta = 1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003016
Dmitry Shmidt03658832014-08-13 11:03:49 -07003017 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003018 nlmode = NL80211_IFTYPE_AP;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003019 else if (bss->if_dynamic ||
3020 nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003021 nlmode = nl80211_get_ifmode(bss);
3022 else
3023 nlmode = NL80211_IFTYPE_STATION;
3024
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003025 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003026 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003027 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003029
Dmitry Shmidt98660862014-03-11 17:26:21 -07003030 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003031 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003032
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08003033 wpa_driver_nl80211_drv_init_rfkill(drv);
3034
Dmitry Shmidt98660862014-03-11 17:26:21 -07003035 if (!rfkill_is_blocked(drv->rfkill)) {
3036 int ret = i802_set_iface_flags(bss, 1);
3037 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038 wpa_printf(MSG_ERROR, "nl80211: Could not set "
3039 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07003040 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003041 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003042
3043 if (is_p2p_net_interface(nlmode))
3044 nl80211_disable_11b_rates(bss->drv,
3045 bss->drv->ifindex, 1);
3046
Dmitry Shmidt98660862014-03-11 17:26:21 -07003047 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
3048 return ret;
3049 } else {
3050 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
3051 "interface '%s' due to rfkill", bss->ifname);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08003052 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
3053 drv->if_disabled = 1;
3054
Dmitry Shmidt98660862014-03-11 17:26:21 -07003055 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003056 }
3057
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08003058 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003059 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
3060 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003061
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08003062 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
3063 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
3064 bss->addr))
3065 return -1;
3066 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
3067 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003069 if (send_rfkill_event) {
3070 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
3071 drv, drv->ctx);
3072 }
3073
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003074 if (drv->vendor_cmd_test_avail)
3075 qca_vendor_test(drv);
3076
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077 return 0;
3078}
3079
3080
Sunil Ravi036cec52023-03-29 11:35:17 -07003081static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss,
Sunil Ravi88611412024-06-28 17:34:56 +00003082 struct i802_link *link)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003083{
3084 struct nl_msg *msg;
Paul Stewart092955c2017-02-06 09:13:09 -08003085 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003086
Sunil Ravi036cec52023-03-29 11:35:17 -07003087 if (!link->beacon_set)
3088 return 0;
3089
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003090 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
Sunil Ravi88611412024-06-28 17:34:56 +00003091 drv->ifindex);
Sunil Ravi036cec52023-03-29 11:35:17 -07003092 link->beacon_set = 0;
3093 link->freq = 0;
3094
Paul Stewart092955c2017-02-06 09:13:09 -08003095 nl80211_put_wiphy_data_ap(bss);
Sunil Ravi88611412024-06-28 17:34:56 +00003096 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Sunil Ravi036cec52023-03-29 11:35:17 -07003097 if (!msg)
3098 return -ENOBUFS;
3099
Sunil Ravi88611412024-06-28 17:34:56 +00003100 if (link->link_id != NL80211_DRV_LINK_ID_NA) {
Sunil Ravi036cec52023-03-29 11:35:17 -07003101 wpa_printf(MSG_DEBUG,
3102 "nl80211: MLD: stop beaconing on link=%u",
Sunil Ravi88611412024-06-28 17:34:56 +00003103 link->link_id);
Sunil Ravi036cec52023-03-29 11:35:17 -07003104
Sunil Ravi88611412024-06-28 17:34:56 +00003105 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
3106 link->link_id)) {
Sunil Ravi036cec52023-03-29 11:35:17 -07003107 nlmsg_free(msg);
3108 return -ENOBUFS;
3109 }
3110 }
3111
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003112 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113}
3114
3115
Sunil Ravi036cec52023-03-29 11:35:17 -07003116static void wpa_driver_nl80211_del_beacon_all(struct i802_bss *bss)
3117{
Sunil Ravi88611412024-06-28 17:34:56 +00003118 unsigned int i;
Sunil Ravi036cec52023-03-29 11:35:17 -07003119
Sunil Ravi88611412024-06-28 17:34:56 +00003120 for (i = 0; i < bss->n_links; i++)
3121 wpa_driver_nl80211_del_beacon(bss, &bss->links[i]);
Sunil Ravi036cec52023-03-29 11:35:17 -07003122}
3123
3124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125/**
3126 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003127 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003128 *
3129 * Shut down driver interface and processing of driver events. Free
3130 * private data buffer if one was allocated in wpa_driver_nl80211_init().
3131 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003132static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003133{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003134 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003135 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003136
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003137 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
3138 bss->ifname, drv->disabled_11b_rates);
3139
Dmitry Shmidt04949592012-07-19 12:16:46 -07003140 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003141 if (drv->data_tx_status)
3142 eloop_unregister_read_sock(drv->eapol_tx_sock);
3143 if (drv->eapol_tx_sock >= 0)
3144 close(drv->eapol_tx_sock);
3145
3146 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003147 wpa_driver_nl80211_probe_req_report(bss, 0);
3148 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003149 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
3150 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003151 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
3152 "interface %s from bridge %s: %s",
3153 bss->ifname, bss->brname, strerror(errno));
3154 }
Hai Shalomc9e41a12018-07-31 14:41:42 -07003155
3156 if (drv->rtnl_sk)
Hai Shalomfdcde762020-04-02 11:19:20 -07003157 nl_socket_free(drv->rtnl_sk);
Hai Shalomc9e41a12018-07-31 14:41:42 -07003158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003159 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003160 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
3161 0) < 0)
3162 wpa_printf(MSG_INFO,
3163 "nl80211: Could not set bridge %s down",
3164 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003165 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003166 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
3167 "bridge %s: %s",
3168 bss->brname, strerror(errno));
3169 }
3170
3171 nl80211_remove_monitor_interface(drv);
3172
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003173 if (is_ap_interface(drv->nlmode)) {
Sunil Ravi036cec52023-03-29 11:35:17 -07003174 wpa_driver_nl80211_del_beacon_all(bss);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003175 nl80211_remove_links(bss);
3176 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 if (drv->eapol_sock >= 0) {
3179 eloop_unregister_read_sock(drv->eapol_sock);
3180 close(drv->eapol_sock);
3181 }
3182
3183 if (drv->if_indices != drv->default_if_indices)
3184 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003185
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003186 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
3188
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003189 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
3190 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003191 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003192 rfkill_deinit(drv->rfkill);
3193
3194 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
3195
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003196 if (!drv->start_iface_up)
3197 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003198
3199 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003200 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
3201 0) < 0) {
3202 wpa_printf(MSG_DEBUG,
3203 "nl80211: Could not set interface down to restore permanent MAC address");
3204 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003205 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
3206 drv->perm_addr) < 0) {
3207 wpa_printf(MSG_DEBUG,
3208 "nl80211: Could not restore permanent MAC address");
3209 }
3210 }
3211
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003212 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Hai Shalomc1a21442022-02-04 13:43:00 -08003213 if (drv->start_mode_sta)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003214 wpa_driver_nl80211_set_mode(bss,
3215 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003216 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003217 } else {
3218 nl80211_mgmt_unsubscribe(bss, "deinit");
3219 nl80211_del_p2pdev(bss);
3220 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003221
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003222 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 os_free(drv->filter_ssids);
3225
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003226 os_free(drv->auth_ie);
Hai Shalom60840252021-02-19 19:02:11 -08003227 os_free(drv->auth_data);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003228
3229 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003230 dl_list_del(&drv->list);
3231
Dmitry Shmidt444d5672013-04-01 13:08:44 -07003232 os_free(drv->extended_capa);
3233 os_free(drv->extended_capa_mask);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003234 for (i = 0; i < drv->num_iface_capa; i++) {
3235 os_free(drv->iface_capa[i].ext_capa);
3236 os_free(drv->iface_capa[i].ext_capa_mask);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003237 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003238 os_free(drv->first_bss);
Hai Shalom60840252021-02-19 19:02:11 -08003239#ifdef CONFIG_DRIVER_NL80211_QCA
3240 os_free(drv->pending_roam_data);
3241#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003242 os_free(drv);
3243}
3244
3245
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003246static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
3247{
3248 switch (alg) {
3249 case WPA_ALG_WEP:
3250 if (key_len == 5)
Paul Stewart092955c2017-02-06 09:13:09 -08003251 return RSN_CIPHER_SUITE_WEP40;
3252 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003253 case WPA_ALG_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08003254 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003255 case WPA_ALG_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08003256 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003257 case WPA_ALG_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08003258 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003259 case WPA_ALG_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003260 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003261 case WPA_ALG_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003262 return RSN_CIPHER_SUITE_GCMP_256;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003263 case WPA_ALG_BIP_CMAC_128:
Paul Stewart092955c2017-02-06 09:13:09 -08003264 return RSN_CIPHER_SUITE_AES_128_CMAC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003265 case WPA_ALG_BIP_GMAC_128:
Paul Stewart092955c2017-02-06 09:13:09 -08003266 return RSN_CIPHER_SUITE_BIP_GMAC_128;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003267 case WPA_ALG_BIP_GMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003268 return RSN_CIPHER_SUITE_BIP_GMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003269 case WPA_ALG_BIP_CMAC_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003270 return RSN_CIPHER_SUITE_BIP_CMAC_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003271 case WPA_ALG_SMS4:
Paul Stewart092955c2017-02-06 09:13:09 -08003272 return RSN_CIPHER_SUITE_SMS4;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003273 case WPA_ALG_KRK:
Paul Stewart092955c2017-02-06 09:13:09 -08003274 return RSN_CIPHER_SUITE_KRK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003275 case WPA_ALG_NONE:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003276 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
3277 alg);
3278 return 0;
3279 }
3280
3281 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
3282 alg);
3283 return 0;
3284}
3285
3286
3287static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
3288{
3289 switch (cipher) {
3290 case WPA_CIPHER_CCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003291 return RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003292 case WPA_CIPHER_GCMP_256:
Paul Stewart092955c2017-02-06 09:13:09 -08003293 return RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003294 case WPA_CIPHER_CCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08003295 return RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003296 case WPA_CIPHER_GCMP:
Paul Stewart092955c2017-02-06 09:13:09 -08003297 return RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003298 case WPA_CIPHER_TKIP:
Paul Stewart092955c2017-02-06 09:13:09 -08003299 return RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003300 case WPA_CIPHER_WEP104:
Paul Stewart092955c2017-02-06 09:13:09 -08003301 return RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003302 case WPA_CIPHER_WEP40:
Paul Stewart092955c2017-02-06 09:13:09 -08003303 return RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003304 case WPA_CIPHER_GTK_NOT_USED:
Paul Stewart092955c2017-02-06 09:13:09 -08003305 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003306 default:
3307 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003308 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003309}
3310
3311
3312static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
3313 int max_suites)
3314{
3315 int num_suites = 0;
3316
3317 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08003318 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003319 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
Paul Stewart092955c2017-02-06 09:13:09 -08003320 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003321 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08003322 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003323 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
Paul Stewart092955c2017-02-06 09:13:09 -08003324 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003325 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
Paul Stewart092955c2017-02-06 09:13:09 -08003326 suites[num_suites++] = RSN_CIPHER_SUITE_TKIP;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003327 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
Paul Stewart092955c2017-02-06 09:13:09 -08003328 suites[num_suites++] = RSN_CIPHER_SUITE_WEP104;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003329 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
Paul Stewart092955c2017-02-06 09:13:09 -08003330 suites[num_suites++] = RSN_CIPHER_SUITE_WEP40;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003331
3332 return num_suites;
3333}
3334
3335
Hai Shalomfdcde762020-04-02 11:19:20 -07003336static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[],
3337 int max_suites)
3338{
3339 int num_suites = 0;
3340
3341#define __AKM(a, b) \
3342 if (num_suites < max_suites && \
3343 (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \
3344 suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b)
3345 __AKM(IEEE8021X, UNSPEC_802_1X);
3346 __AKM(PSK, PSK_OVER_802_1X);
3347 __AKM(FT_IEEE8021X, FT_802_1X);
3348 __AKM(FT_PSK, FT_PSK);
3349 __AKM(IEEE8021X_SHA256, 802_1X_SHA256);
3350 __AKM(PSK_SHA256, PSK_SHA256);
3351 __AKM(SAE, SAE);
Sunil Ravi89eba102022-09-13 21:04:37 -07003352 __AKM(SAE_EXT_KEY, SAE_EXT_KEY);
Hai Shalomfdcde762020-04-02 11:19:20 -07003353 __AKM(FT_SAE, FT_SAE);
Sunil Ravi89eba102022-09-13 21:04:37 -07003354 __AKM(FT_SAE_EXT_KEY, FT_SAE_EXT_KEY);
Hai Shalomfdcde762020-04-02 11:19:20 -07003355 __AKM(CCKM, CCKM);
3356 __AKM(OSEN, OSEN);
3357 __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B);
3358 __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192);
3359 __AKM(FILS_SHA256, FILS_SHA256);
3360 __AKM(FILS_SHA384, FILS_SHA384);
3361 __AKM(FT_FILS_SHA256, FT_FILS_SHA256);
3362 __AKM(FT_FILS_SHA384, FT_FILS_SHA384);
3363 __AKM(OWE, OWE);
3364 __AKM(DPP, DPP);
3365 __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003366 __AKM(IEEE8021X_SHA384, 802_1X_SHA384);
Hai Shalomfdcde762020-04-02 11:19:20 -07003367#undef __AKM
3368
3369 return num_suites;
3370}
3371
3372
Isaac Chiou6ce580d2024-04-24 17:07:24 +08003373#if (defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(WIFI_BRCM_OPEN_SOURCE_MULTI_AKM)) || \
3374 defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303375static int wpa_cross_akm_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[],
3376 int max_suites)
3377{
3378 int num_suites = 0;
3379
3380#define __AKM_TO_SUITES_ARRAY(a, b) \
3381 if (num_suites < max_suites && \
3382 (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \
3383 suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b)
3384 __AKM_TO_SUITES_ARRAY(PSK, PSK_OVER_802_1X);
3385 __AKM_TO_SUITES_ARRAY(SAE, SAE);
3386#undef __AKM_TO_SUITES_ARRAY
3387
3388 return num_suites;
3389}
Isaac Chiou6ce580d2024-04-24 17:07:24 +08003390#endif /* (CONFIG_DRIVER_NL80211_BRCM && !WIFI_BRCM_OPEN_SOURCE_MULTI_AKM) ||
3391 * CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303392
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003393
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003394#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003395static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
3396 const u8 *key, size_t key_len)
3397{
3398 struct nl_msg *msg;
3399 int ret;
3400
3401 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
3402 return 0;
3403
3404 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
3405 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3406 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3407 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
3408 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
3409 nl80211_nlmsg_clear(msg);
3410 nlmsg_free(msg);
3411 return -1;
3412 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003413 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003414 if (ret) {
3415 wpa_printf(MSG_DEBUG,
3416 "nl80211: Key management set key failed: ret=%d (%s)",
3417 ret, strerror(-ret));
3418 }
3419
3420 return ret;
3421}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003422#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003423
3424
Andy Kuoaba17c12022-04-14 16:05:31 +08003425#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303426static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
3427 const u8 *key, size_t key_len)
3428{
3429 struct nl_msg *msg;
3430 int ret;
3431 struct nlattr *params;
3432
3433 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
3434 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) ||
3435 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Hai Shalomc1a21442022-02-04 13:43:00 -08003436 BRCM_VENDOR_SCMD_SET_PMK) ||
Mir Ali677e7482020-11-12 19:49:02 +05303437 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3438 nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) {
3439 nl80211_nlmsg_clear(msg);
3440 nlmsg_free(msg);
3441 return -ENOBUFS;
3442 }
3443 nla_nest_end(msg, params);
3444
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003445 ret = send_and_recv_cmd(drv, msg);
Mir Ali677e7482020-11-12 19:49:02 +05303446 if (ret) {
3447 wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)",
3448 ret, strerror(-ret));
3449 }
3450
3451 return ret;
3452}
Andy Kuoaba17c12022-04-14 16:05:31 +08003453#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3454
Mir Ali677e7482020-11-12 19:49:02 +05303455
Roshan Pius3a1667e2018-07-03 15:17:14 -07003456static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv,
3457 const u8 *key, size_t key_len,
3458 const u8 *addr)
3459{
3460 struct nl_msg *msg = NULL;
3461 int ret;
3462
3463 /*
3464 * If the authenticator address is not set, assume it is
3465 * the current BSSID.
3466 */
3467 if (!addr && drv->associated)
3468 addr = drv->bssid;
3469 else if (!addr)
3470 return -1;
3471
3472 wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR,
3473 MAC2STR(addr));
3474 wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len);
3475 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK);
3476 if (!msg ||
3477 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3478 nla_put(msg, NL80211_ATTR_PMK, key_len, key)) {
3479 nl80211_nlmsg_clear(msg);
3480 nlmsg_free(msg);
3481 return -ENOBUFS;
3482 }
3483
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003484 ret = send_and_recv_cmd(drv, msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003485 if (ret) {
3486 wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)",
3487 ret, strerror(-ret));
3488 }
3489
3490 return ret;
3491}
3492
3493
Hai Shalomfdcde762020-04-02 11:19:20 -07003494static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
3495 struct wpa_driver_set_key_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003496{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003498 int ifindex;
Hai Shalomc3565922019-10-28 11:58:20 -07003499 struct nl_msg *msg;
3500 struct nl_msg *key_msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07003502 int skip_set_key = 1;
3503 const char *ifname = params->ifname;
3504 enum wpa_alg alg = params->alg;
3505 const u8 *addr = params->addr;
3506 int key_idx = params->key_idx;
3507 int set_tx = params->set_tx;
3508 const u8 *seq = params->seq;
3509 size_t seq_len = params->seq_len;
3510 const u8 *key = params->key;
3511 size_t key_len = params->key_len;
3512 int vlan_id = params->vlan_id;
3513 enum key_flag key_flag = params->key_flag;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003514 int link_id = params->link_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003515
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003516 /* Ignore for P2P Device */
3517 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
3518 return 0;
3519
3520 ifindex = if_nametoindex(ifname);
3521 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Sunil Ravi77d572f2023-01-17 23:58:31 +00003522 "set_tx=%d seq_len=%lu key_len=%lu key_flag=0x%x link_id=%d",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003523 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Sunil Ravi77d572f2023-01-17 23:58:31 +00003524 (unsigned long) seq_len, (unsigned long) key_len, key_flag,
3525 link_id);
Hai Shalomfdcde762020-04-02 11:19:20 -07003526
3527 if (check_key_flag(key_flag)) {
3528 wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__);
3529 return -EINVAL;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07003530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003531
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003532#ifdef CONFIG_DRIVER_NL80211_QCA
Hai Shalomfdcde762020-04-02 11:19:20 -07003533 if ((key_flag & KEY_FLAG_PMK) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003534 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
3535 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
3536 __func__);
3537 ret = issue_key_mgmt_set_key(drv, key, key_len);
3538 return ret;
3539 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003540#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541
Hai Shalomfdcde762020-04-02 11:19:20 -07003542 if (key_flag & KEY_FLAG_PMK) {
3543 if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)
3544 return nl80211_set_pmk(drv, key, key_len, addr);
Andy Kuoaba17c12022-04-14 16:05:31 +08003545#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303546 if (drv->vendor_set_pmk) {
Jay Patel731adae2021-02-17 14:55:58 -08003547 wpa_printf(MSG_INFO, "nl80211: key_mgmt_set_key with key_len %lu", (unsigned long) key_len);
Mir Ali677e7482020-11-12 19:49:02 +05303548 return key_mgmt_set_key(drv, key, key_len);
3549 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003550#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3551
Hai Shalomfdcde762020-04-02 11:19:20 -07003552 /* The driver does not have any offload mechanism for PMK, so
3553 * there is no need to configure this key. */
3554 return 0;
3555 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003556
Hai Shalomfdcde762020-04-02 11:19:20 -07003557 ret = -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07003558 key_msg = nlmsg_alloc();
3559 if (!key_msg)
Hai Shalomfdcde762020-04-02 11:19:20 -07003560 return ret;
Hai Shalomc3565922019-10-28 11:58:20 -07003561
Hai Shalomfdcde762020-04-02 11:19:20 -07003562 if ((key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3563 KEY_FLAG_PAIRWISE_RX_TX_MODIFY) {
3564 wpa_printf(MSG_DEBUG,
3565 "nl80211: SET_KEY (pairwise RX/TX modify)");
3566 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
3567 if (!msg)
3568 goto fail2;
3569 } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) {
3570 wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key",
3571 __func__);
3572 ret = -EINVAL;
3573 goto fail2;
3574 } else if (alg == WPA_ALG_NONE) {
3575 wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003576 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
3577 if (!msg)
Hai Shalomc3565922019-10-28 11:58:20 -07003578 goto fail2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003579 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003580 u32 suite;
3581
3582 suite = wpa_alg_to_cipher_suite(alg, key_len);
Hai Shalomfdcde762020-04-02 11:19:20 -07003583 if (!suite) {
3584 ret = -EINVAL;
Hai Shalomc3565922019-10-28 11:58:20 -07003585 goto fail2;
Hai Shalomfdcde762020-04-02 11:19:20 -07003586 }
3587 wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003588 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003589 if (!msg)
3590 goto fail2;
3591 if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) ||
3592 nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003593 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07003594 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003595
Hai Shalomfdcde762020-04-02 11:19:20 -07003596 if (seq && seq_len) {
3597 if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq))
3598 goto fail;
3599 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ",
3600 seq, seq_len);
3601 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07003602 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003603
3604 if (addr && !is_broadcast_ether_addr(addr)) {
3605 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003606 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
3607 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003608
Hai Shalomfdcde762020-04-02 11:19:20 -07003609 if ((key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3610 KEY_FLAG_PAIRWISE_RX ||
3611 (key_flag & KEY_FLAG_PAIRWISE_MASK) ==
3612 KEY_FLAG_PAIRWISE_RX_TX_MODIFY) {
3613 if (nla_put_u8(key_msg, NL80211_KEY_MODE,
3614 key_flag == KEY_FLAG_PAIRWISE_RX ?
3615 NL80211_KEY_NO_TX : NL80211_KEY_SET_TX))
3616 goto fail;
3617 } else if ((key_flag & KEY_FLAG_GROUP_MASK) ==
3618 KEY_FLAG_GROUP_RX) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Hai Shalomc3565922019-10-28 11:58:20 -07003620 if (nla_put_u32(key_msg, NL80211_KEY_TYPE,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003621 NL80211_KEYTYPE_GROUP))
3622 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07003623 } else if (!(key_flag & KEY_FLAG_PAIRWISE)) {
3624 wpa_printf(MSG_DEBUG,
3625 " key_flag missing PAIRWISE when setting a pairwise key");
3626 ret = -EINVAL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003627 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07003628 } else if (alg == WPA_ALG_WEP &&
3629 (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) {
3630 wpa_printf(MSG_DEBUG, " unicast WEP key");
3631 skip_set_key = 0;
3632 } else {
3633 wpa_printf(MSG_DEBUG, " pairwise key");
3634 }
3635 } else if ((key_flag & KEY_FLAG_PAIRWISE) ||
3636 !(key_flag & KEY_FLAG_GROUP)) {
3637 wpa_printf(MSG_DEBUG,
3638 " invalid key_flag for a broadcast key");
3639 ret = -EINVAL;
3640 goto fail;
3641 } else {
3642 wpa_printf(MSG_DEBUG, " broadcast key");
3643 if (key_flag & KEY_FLAG_DEFAULT)
3644 skip_set_key = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003645 }
Hai Shalomc3565922019-10-28 11:58:20 -07003646 if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
3647 nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003648 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003649 nl80211_nlmsg_clear(key_msg);
3650 nlmsg_free(key_msg);
3651 key_msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652
Hai Shalomfdcde762020-04-02 11:19:20 -07003653 if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
3654 wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id);
3655 if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id))
3656 goto fail;
3657 }
3658
Sunil Ravi77d572f2023-01-17 23:58:31 +00003659 if (link_id != -1) {
3660 wpa_printf(MSG_DEBUG, "nl80211: Link ID %d", link_id);
3661 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
3662 goto fail;
3663 }
3664
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003665 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003666 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
3667 ret = 0;
3668 if (ret)
Hai Shalomfdcde762020-04-02 11:19:20 -07003669 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003670 ret, strerror(-ret));
3671
3672 /*
Hai Shalomfdcde762020-04-02 11:19:20 -07003673 * If we failed or don't need to set the key as default (below),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003674 * we're done here.
3675 */
Hai Shalomfdcde762020-04-02 11:19:20 -07003676 if (ret || skip_set_key)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677 return ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07003678 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003679
Hai Shalomfdcde762020-04-02 11:19:20 -07003680 ret = -ENOBUFS;
Hai Shalomc3565922019-10-28 11:58:20 -07003681 key_msg = nlmsg_alloc();
3682 if (!key_msg)
Hai Shalomfdcde762020-04-02 11:19:20 -07003683 return ret;
Hai Shalomc3565922019-10-28 11:58:20 -07003684
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003685 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
Hai Shalomc3565922019-10-28 11:58:20 -07003686 if (!msg)
3687 goto fail2;
3688 if (!key_msg ||
3689 nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003690 nla_put_flag(key_msg, wpa_alg_bip(alg) ?
Hai Shalomfdcde762020-04-02 11:19:20 -07003691 (key_idx == 6 || key_idx == 7 ?
3692 NL80211_KEY_DEFAULT_BEACON :
3693 NL80211_KEY_DEFAULT_MGMT) :
3694 NL80211_KEY_DEFAULT))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003695 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003697 struct nlattr *types;
3698
Hai Shalomc3565922019-10-28 11:58:20 -07003699 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003700 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003701 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003702 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003703 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003704 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003705 struct nlattr *types;
3706
Hai Shalomc3565922019-10-28 11:58:20 -07003707 types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003708 if (!types ||
Hai Shalomc3565922019-10-28 11:58:20 -07003709 nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003710 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07003711 nla_nest_end(key_msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003712 }
3713
Hai Shalomc3565922019-10-28 11:58:20 -07003714 if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg))
3715 goto fail;
3716 nl80211_nlmsg_clear(key_msg);
3717 nlmsg_free(key_msg);
3718 key_msg = NULL;
3719
Hai Shalomfdcde762020-04-02 11:19:20 -07003720 if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
3721 wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d",
3722 vlan_id);
3723 if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id))
3724 goto fail;
3725 }
3726
Sunil Ravi77d572f2023-01-17 23:58:31 +00003727 if (link_id != -1) {
3728 wpa_printf(MSG_DEBUG, "nl80211: set_key default - Link ID %d",
3729 link_id);
3730 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
3731 goto fail;
3732 }
3733
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003734 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003735 if (ret)
Hai Shalomfdcde762020-04-02 11:19:20 -07003736 wpa_printf(MSG_DEBUG,
3737 "nl80211: set_key default failed; err=%d %s",
3738 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003739 return ret;
3740
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003741fail:
3742 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003743 nlmsg_free(msg);
Hai Shalomc3565922019-10-28 11:58:20 -07003744fail2:
3745 nl80211_nlmsg_clear(key_msg);
3746 nlmsg_free(key_msg);
Hai Shalomfdcde762020-04-02 11:19:20 -07003747 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003748}
3749
3750
3751static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
3752 int key_idx, int defkey,
3753 const u8 *seq, size_t seq_len,
3754 const u8 *key, size_t key_len)
3755{
3756 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003757 u32 suite;
3758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003759 if (!key_attr)
3760 return -1;
3761
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003762 suite = wpa_alg_to_cipher_suite(alg, key_len);
3763 if (!suite)
3764 return -1;
3765
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003766 if (defkey && wpa_alg_bip(alg)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003767 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
3768 return -1;
3769 } else if (defkey) {
3770 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
3771 return -1;
3772 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003773
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003774 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003775 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003776 (seq && seq_len &&
3777 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
3778 nla_put(msg, NL80211_KEY_DATA, key_len, key))
3779 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003780
3781 nla_nest_end(msg, key_attr);
3782
3783 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003784}
3785
3786
3787static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
3788 struct nl_msg *msg)
3789{
3790 int i, privacy = 0;
3791 struct nlattr *nl_keys, *nl_key;
3792
3793 for (i = 0; i < 4; i++) {
3794 if (!params->wep_key[i])
3795 continue;
3796 privacy = 1;
3797 break;
3798 }
3799 if (params->wps == WPS_MODE_PRIVACY)
3800 privacy = 1;
3801 if (params->pairwise_suite &&
3802 params->pairwise_suite != WPA_CIPHER_NONE)
3803 privacy = 1;
3804
3805 if (!privacy)
3806 return 0;
3807
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003808 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3809 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003810
3811 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
3812 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003813 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003814
3815 for (i = 0; i < 4; i++) {
3816 if (!params->wep_key[i])
3817 continue;
3818
3819 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003820 if (!nl_key ||
3821 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
3822 params->wep_key[i]) ||
3823 nla_put_u32(msg, NL80211_KEY_CIPHER,
3824 params->wep_key_len[i] == 5 ?
Paul Stewart092955c2017-02-06 09:13:09 -08003825 RSN_CIPHER_SUITE_WEP40 :
3826 RSN_CIPHER_SUITE_WEP104) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003827 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
3828 (i == params->wep_tx_keyidx &&
3829 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
3830 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003831
3832 nla_nest_end(msg, nl_key);
3833 }
3834 nla_nest_end(msg, nl_keys);
3835
3836 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003837}
3838
3839
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003840int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
3841 const u8 *addr, int cmd, u16 reason_code,
Hai Shalom74f70d42019-02-11 14:42:39 -08003842 int local_state_change,
Hai Shalomc1a21442022-02-04 13:43:00 -08003843 struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003844{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003845 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003846 struct nl_msg *msg;
3847
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003848 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
3849 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
3850 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
3851 (local_state_change &&
3852 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
3853 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003854 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003855 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003856
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003857 ret = send_and_recv(drv->global, bss->nl_connect, msg,
3858 NULL, NULL, NULL, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003859 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003860 wpa_dbg(drv->ctx, MSG_DEBUG,
3861 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3862 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003863 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864 return ret;
3865}
3866
3867
3868static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Hai Shalom81f62d82019-07-22 12:10:00 -07003869 u16 reason_code,
Hai Shalomc1a21442022-02-04 13:43:00 -08003870 struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003871{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003872 int ret;
3873
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003874 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003875 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003876 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003877 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
Hai Shalomc1a21442022-02-04 13:43:00 -08003878 reason_code, 0, bss);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003879 /*
3880 * For locally generated disconnect, supplicant already generates a
3881 * DEAUTH event, so ignore the event from NL80211.
3882 */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003883 if (ret == 0)
3884 drv->ignore_next_local_disconnect = send_event_marker(drv);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003885
3886 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887}
3888
3889
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003890static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
Hai Shalom81f62d82019-07-22 12:10:00 -07003891 const u8 *addr, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003892{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003893 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003894 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003895
3896 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
3897 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003898 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07003899 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003900 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Hai Shalomc1a21442022-02-04 13:43:00 -08003901 return wpa_driver_nl80211_disconnect(drv, reason_code, bss);
Hai Shalom74f70d42019-02-11 14:42:39 -08003902 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
3904 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003905 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003906 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
Hai Shalomc1a21442022-02-04 13:43:00 -08003907 reason_code, 0, bss);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003908 /*
3909 * For locally generated deauthenticate, supplicant already generates a
3910 * DEAUTH event, so ignore the event from NL80211.
3911 */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003912 if (ret == 0)
3913 drv->ignore_next_local_deauth = send_event_marker(drv);
Hai Shalomce48b4a2018-09-05 11:41:35 -07003914
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003915 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003916}
3917
3918
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003919static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
3920 struct wpa_driver_auth_params *params)
3921{
3922 int i;
3923
3924 drv->auth_freq = params->freq;
3925 drv->auth_alg = params->auth_alg;
3926 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
3927 drv->auth_local_state_change = params->local_state_change;
3928 drv->auth_p2p = params->p2p;
3929
3930 if (params->bssid)
3931 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
3932 else
3933 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
3934
3935 if (params->ssid) {
3936 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
3937 drv->auth_ssid_len = params->ssid_len;
3938 } else
3939 drv->auth_ssid_len = 0;
3940
3941
3942 os_free(drv->auth_ie);
3943 drv->auth_ie = NULL;
3944 drv->auth_ie_len = 0;
3945 if (params->ie) {
3946 drv->auth_ie = os_malloc(params->ie_len);
3947 if (drv->auth_ie) {
3948 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
3949 drv->auth_ie_len = params->ie_len;
3950 }
3951 }
3952
Sunil Ravi77d572f2023-01-17 23:58:31 +00003953 if (params->mld && params->ap_mld_addr) {
3954 drv->auth_mld = params->mld;
3955 drv->auth_mld_link_id = params->mld_link_id;
3956 os_memcpy(drv->auth_ap_mld_addr, params->ap_mld_addr, ETH_ALEN);
3957 } else {
3958 drv->auth_mld = false;
3959 drv->auth_mld_link_id = -1;
3960 }
3961
Hai Shalom60840252021-02-19 19:02:11 -08003962 os_free(drv->auth_data);
3963 drv->auth_data = NULL;
3964 drv->auth_data_len = 0;
3965 if (params->auth_data) {
3966 drv->auth_data = os_memdup(params->auth_data,
3967 params->auth_data_len);
3968 if (drv->auth_data)
3969 drv->auth_data_len = params->auth_data_len;
3970 }
3971
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003972 for (i = 0; i < 4; i++) {
3973 if (params->wep_key[i] && params->wep_key_len[i] &&
3974 params->wep_key_len[i] <= 16) {
3975 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
3976 params->wep_key_len[i]);
3977 drv->auth_wep_key_len[i] = params->wep_key_len[i];
3978 } else
3979 drv->auth_wep_key_len[i] = 0;
3980 }
3981}
3982
3983
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003984static void nl80211_unmask_11b_rates(struct i802_bss *bss)
3985{
3986 struct wpa_driver_nl80211_data *drv = bss->drv;
3987
3988 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
3989 return;
3990
3991 /*
3992 * Looks like we failed to unmask 11b rates previously. This could
3993 * happen, e.g., if the interface was down at the point in time when a
3994 * P2P group was terminated.
3995 */
3996 wpa_printf(MSG_DEBUG,
3997 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3998 bss->ifname);
3999 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
4000}
4001
4002
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004003static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg)
4004{
4005 if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
4006 return NL80211_AUTHTYPE_OPEN_SYSTEM;
4007 if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
4008 return NL80211_AUTHTYPE_SHARED_KEY;
4009 if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
4010 return NL80211_AUTHTYPE_NETWORK_EAP;
4011 if (wpa_auth_alg & WPA_AUTH_ALG_FT)
4012 return NL80211_AUTHTYPE_FT;
4013 if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
4014 return NL80211_AUTHTYPE_SAE;
4015 if (wpa_auth_alg & WPA_AUTH_ALG_FILS)
4016 return NL80211_AUTHTYPE_FILS_SK;
4017 if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS)
4018 return NL80211_AUTHTYPE_FILS_SK_PFS;
4019
4020 return NL80211_AUTHTYPE_MAX;
4021}
4022
4023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004024static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004025 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004026{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004027 struct wpa_driver_nl80211_data *drv = bss->drv;
4028 int ret = -1, i;
4029 struct nl_msg *msg;
4030 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004031 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004033 int is_retry;
Hai Shalomfdcde762020-04-02 11:19:20 -07004034 struct wpa_driver_set_key_params p;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004035
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004036 nl80211_unmask_11b_rates(bss);
4037
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004038 is_retry = drv->retry_auth;
4039 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07004040 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004041
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004042 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004044 if (params->bssid)
4045 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4046 else
4047 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004048 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004049 nlmode = params->p2p ?
4050 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4051 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004052 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004053 return -1;
4054
4055retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004056 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
4057 drv->ifindex);
4058
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004059 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
4060 if (!msg)
4061 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062
Hai Shalomfdcde762020-04-02 11:19:20 -07004063 os_memset(&p, 0, sizeof(p));
4064 p.ifname = bss->ifname;
4065 p.alg = WPA_ALG_WEP;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004066 p.link_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004067 for (i = 0; i < 4; i++) {
4068 if (!params->wep_key[i])
4069 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07004070 p.key_idx = i;
4071 p.set_tx = i == params->wep_tx_keyidx;
4072 p.key = params->wep_key[i];
4073 p.key_len = params->wep_key_len[i];
4074 p.key_flag = i == params->wep_tx_keyidx ?
4075 KEY_FLAG_GROUP_RX_TX_DEFAULT :
4076 KEY_FLAG_GROUP_RX_TX;
4077 wpa_driver_nl80211_set_key(bss, &p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004078 if (params->wep_tx_keyidx != i)
4079 continue;
4080 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004081 params->wep_key[i], params->wep_key_len[i]))
4082 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 }
4084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085 if (params->bssid) {
4086 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4087 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004088 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4089 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004090 }
4091 if (params->freq) {
4092 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004093 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
4094 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095 }
4096 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004097 wpa_printf(MSG_DEBUG, " * SSID=%s",
4098 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004099 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4100 params->ssid))
4101 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004102 }
4103 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004104 if (params->ie &&
4105 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
4106 goto fail;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004107 if (params->auth_data) {
4108 wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data,
4109 params->auth_data_len);
4110 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len,
4111 params->auth_data))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004112 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004113 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004114 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004115 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004116 if (type == NL80211_AUTHTYPE_MAX ||
4117 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004118 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004119 if (params->local_state_change) {
4120 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004121 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
4122 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004123 }
4124
Sunil Ravi77d572f2023-01-17 23:58:31 +00004125 if (params->mld && params->ap_mld_addr) {
4126 wpa_printf(MSG_DEBUG, " * MLD: link_id=%u, MLD addr=" MACSTR,
4127 params->mld_link_id, MAC2STR(params->ap_mld_addr));
4128
4129 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
4130 params->mld_link_id) ||
4131 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
4132 params->ap_mld_addr))
4133 goto fail;
4134 }
4135
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004136 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004137 msg = NULL;
4138 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004139 wpa_dbg(drv->ctx, MSG_DEBUG,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004140 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
4141 count, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004142 count++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004143 if ((ret == -EALREADY || ret == -EEXIST) && count == 1 &&
4144 params->bssid && !params->local_state_change) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004145 /*
4146 * mac80211 does not currently accept new
4147 * authentication if we are already authenticated. As a
4148 * workaround, force deauthentication and try again.
4149 */
4150 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
4151 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07004152 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004153 wpa_driver_nl80211_deauthenticate(
4154 bss, params->bssid,
4155 WLAN_REASON_PREV_AUTH_NOT_VALID);
4156 nlmsg_free(msg);
4157 goto retry;
4158 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004159
4160 if (ret == -ENOENT && params->freq && !is_retry) {
4161 /*
4162 * cfg80211 has likely expired the BSS entry even
4163 * though it was previously available in our internal
4164 * BSS table. To recover quickly, start a single
4165 * channel scan on the specified channel.
4166 */
4167 struct wpa_driver_scan_params scan;
4168 int freqs[2];
4169
4170 os_memset(&scan, 0, sizeof(scan));
4171 scan.num_ssids = 1;
4172 if (params->ssid) {
4173 scan.ssids[0].ssid = params->ssid;
4174 scan.ssids[0].ssid_len = params->ssid_len;
4175 }
4176 freqs[0] = params->freq;
4177 freqs[1] = 0;
4178 scan.freqs = freqs;
4179 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
4180 "channel scan to refresh cfg80211 BSS "
4181 "entry");
4182 ret = wpa_driver_nl80211_scan(bss, &scan);
4183 if (ret == 0) {
4184 nl80211_copy_auth_params(drv, params);
4185 drv->scan_for_auth = 1;
4186 }
4187 } else if (is_retry) {
4188 /*
4189 * Need to indicate this with an event since the return
4190 * value from the retry is not delivered to core code.
4191 */
4192 union wpa_event_data event;
4193 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
4194 "failed");
4195 os_memset(&event, 0, sizeof(event));
4196 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
4197 ETH_ALEN);
4198 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
4199 &event);
4200 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004201 } else {
4202 wpa_printf(MSG_DEBUG,
4203 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004204 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004205
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004206fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004207 nlmsg_free(msg);
4208 return ret;
4209}
4210
4211
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004212int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004213{
4214 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004215 struct i802_bss *bss = drv->first_bss;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004216 u8 ap_mld_addr[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004217 int i;
4218
4219 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
4220
4221 os_memset(&params, 0, sizeof(params));
4222 params.freq = drv->auth_freq;
4223 params.auth_alg = drv->auth_alg;
4224 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
4225 params.local_state_change = drv->auth_local_state_change;
4226 params.p2p = drv->auth_p2p;
4227
4228 if (!is_zero_ether_addr(drv->auth_bssid_))
4229 params.bssid = drv->auth_bssid_;
4230
4231 if (drv->auth_ssid_len) {
4232 params.ssid = drv->auth_ssid;
4233 params.ssid_len = drv->auth_ssid_len;
4234 }
4235
4236 params.ie = drv->auth_ie;
4237 params.ie_len = drv->auth_ie_len;
Hai Shalom60840252021-02-19 19:02:11 -08004238 params.auth_data = drv->auth_data;
4239 params.auth_data_len = drv->auth_data_len;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004240 params.mld = drv->auth_mld;
4241 params.mld_link_id = drv->auth_mld_link_id;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004242 if (drv->auth_mld) {
4243 os_memcpy(ap_mld_addr, drv->auth_ap_mld_addr, ETH_ALEN);
4244 params.ap_mld_addr = ap_mld_addr;
4245 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004246
4247 for (i = 0; i < 4; i++) {
4248 if (drv->auth_wep_key_len[i]) {
4249 params.wep_key[i] = drv->auth_wep_key[i];
4250 params.wep_key_len[i] = drv->auth_wep_key_len[i];
4251 }
4252 }
4253
4254 drv->retry_auth = 1;
4255 return wpa_driver_nl80211_authenticate(bss, &params);
4256}
4257
4258
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004259struct i802_link * nl80211_get_link(struct i802_bss *bss, s8 link_id)
4260{
Sunil Ravi88611412024-06-28 17:34:56 +00004261 unsigned int i;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004262
Sunil Ravi88611412024-06-28 17:34:56 +00004263 for (i = 0; i < bss->n_links; i++) {
4264 if (bss->links[i].link_id != link_id)
4265 continue;
4266
4267 return &bss->links[i];
4268 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004269
4270 return bss->flink;
4271}
4272
4273
4274static void nl80211_link_set_freq(struct i802_bss *bss, s8 link_id, int freq)
4275{
4276 struct i802_link *link = nl80211_get_link(bss, link_id);
4277
4278 link->freq = freq;
4279}
4280
4281
4282static int nl80211_get_link_freq(struct i802_bss *bss, const u8 *addr,
4283 bool bss_freq_debug)
4284{
Sunil Ravi88611412024-06-28 17:34:56 +00004285 size_t i;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004286
Sunil Ravi88611412024-06-28 17:34:56 +00004287 for (i = 0; i < bss->n_links; i++) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004288 if (ether_addr_equal(bss->links[i].addr, addr)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004289 wpa_printf(MSG_DEBUG,
4290 "nl80211: Use link freq=%d for address "
4291 MACSTR,
4292 bss->links[i].freq, MAC2STR(addr));
4293 return bss->links[i].freq;
4294 }
4295 }
4296
4297 if (bss_freq_debug)
4298 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
4299 bss->flink->freq);
4300
4301 return bss->flink->freq;
4302}
4303
4304
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004305static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
4306 size_t data_len, int noack,
4307 unsigned int freq, int no_cck,
4308 int offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004309 unsigned int wait_time,
4310 const u16 *csa_offs,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004311 size_t csa_offs_len, int no_encrypt,
4312 int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004313{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004314 struct wpa_driver_nl80211_data *drv = bss->drv;
4315 struct ieee80211_mgmt *mgmt;
Hai Shalomfdcde762020-04-02 11:19:20 -07004316 int encrypt = !no_encrypt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004317 u16 fc;
Hai Shalomfdcde762020-04-02 11:19:20 -07004318 int use_cookie = 1;
4319 int res;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004320 struct i802_link *link = nl80211_get_link(bss, link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004321
4322 mgmt = (struct ieee80211_mgmt *) data;
4323 fc = le_to_host16(mgmt->frame_control);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004324 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR " sa=" MACSTR
4325 " bssid=" MACSTR
Hai Shalomfdcde762020-04-02 11:19:20 -07004326 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d",
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004327 MAC2STR(mgmt->da), MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
4328 noack, freq, no_cck, offchanok, wait_time,
Hai Shalomfdcde762020-04-02 11:19:20 -07004329 no_encrypt, fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004330
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004331 if ((is_sta_interface(drv->nlmode) ||
4332 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004333 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4334 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
4335 /*
4336 * The use of last_mgmt_freq is a bit of a hack,
4337 * but it works due to the single-threaded nature
4338 * of wpa_supplicant.
4339 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07004340 if (freq == 0) {
4341 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
4342 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004343 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07004344 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004345 wait_time = 0;
4346 use_cookie = 0;
4347 no_cck = 1;
4348 offchanok = 1;
4349 goto send_frame_cmd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004350 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004351
4352 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004353 unsigned int link_freq = nl80211_get_link_freq(bss, mgmt->sa,
4354 !freq);
4355
4356 if (!freq)
4357 freq = link_freq;
4358
4359 if (freq == link_freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07004360 wait_time = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004361
Hai Shalomfdcde762020-04-02 11:19:20 -07004362 goto send_frame_cmd;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07004363 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07004364
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004365 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4366 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
4367 /*
4368 * Only one of the authentication frame types is encrypted.
4369 * In order for static WEP encryption to work properly (i.e.,
4370 * to not encrypt the frame), we need to tell mac80211 about
4371 * the frames that must not be encrypted.
4372 */
4373 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
4374 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
4375 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
4376 encrypt = 0;
4377 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004378
Hai Shalom60840252021-02-19 19:02:11 -08004379 if (is_sta_interface(drv->nlmode) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004380 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4381 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
Hai Shalom60840252021-02-19 19:02:11 -08004382 if (freq == 0 &&
4383 (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
4384 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
4385 freq = nl80211_get_assoc_freq(drv);
4386 wpa_printf(MSG_DEBUG,
4387 "nl80211: send_mlme - Use assoc_freq=%u for external auth",
4388 freq);
4389 }
4390
4391 /* Allow off channel for PASN authentication */
4392 if (data_len >= IEEE80211_HDRLEN + 2 &&
4393 WPA_GET_LE16(data + IEEE80211_HDRLEN) == WLAN_AUTH_PASN &&
4394 !offchanok) {
4395 wpa_printf(MSG_DEBUG,
4396 "nl80211: send_mlme: allow off channel for PASN");
4397 offchanok = 1;
4398 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004399 }
4400
Hai Shalomc1a21442022-02-04 13:43:00 -08004401#ifdef CONFIG_PASN
4402 if (is_sta_interface(drv->nlmode) &&
4403 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4404 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DEAUTH) {
4405 wpa_printf(MSG_DEBUG,
4406 "nl80211: send_mlme: allow Deauthentication frame for PASN");
4407
4408 use_cookie = 0;
4409 offchanok = 1;
4410 goto send_frame_cmd;
4411 }
4412#endif /* CONFIG_PASN */
4413
Hai Shalomfdcde762020-04-02 11:19:20 -07004414 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
4415 freq = nl80211_get_assoc_freq(drv);
4416 wpa_printf(MSG_DEBUG,
4417 "nl80211: send_mlme - Use assoc_freq=%u for IBSS",
4418 freq);
4419 }
4420 if (freq == 0) {
4421 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u",
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004422 link->freq);
4423 freq = link->freq;
Hai Shalomfdcde762020-04-02 11:19:20 -07004424 }
4425
Hai Shalomc1a21442022-02-04 13:43:00 -08004426 if (drv->use_monitor && is_ap_interface(drv->nlmode)) {
Hai Shalomfdcde762020-04-02 11:19:20 -07004427 wpa_printf(MSG_DEBUG,
4428 "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004429 freq, link->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07004430 return nl80211_send_monitor(drv, data, data_len, encrypt,
4431 noack);
4432 }
4433
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004434 if ((noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
4435 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) &&
4436 link_id == NL80211_DRV_LINK_ID_NA)
Hai Shalomfdcde762020-04-02 11:19:20 -07004437 use_cookie = 0;
4438send_frame_cmd:
4439#ifdef CONFIG_TESTING_OPTIONS
4440 if (no_encrypt && !encrypt && !drv->use_monitor) {
4441 wpa_printf(MSG_DEBUG,
4442 "nl80211: Request to send an unencrypted frame - use a monitor interface for this");
4443 if (nl80211_create_monitor_interface(drv) < 0)
4444 return -1;
4445 res = nl80211_send_monitor(drv, data, data_len, encrypt,
4446 noack);
4447 nl80211_remove_monitor_interface(drv);
4448 return res;
4449 }
4450#endif /* CONFIG_TESTING_OPTIONS */
4451
4452 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd");
4453 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len,
4454 use_cookie, no_cck, noack, offchanok,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004455 csa_offs, csa_offs_len, link_id);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004456 if (!res)
4457 drv->send_frame_link_id = link_id;
Hai Shalomfdcde762020-04-02 11:19:20 -07004458
4459 return res;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004460}
4461
4462
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004463static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
4464{
4465 u8 rates[NL80211_MAX_SUPP_RATES];
4466 u8 rates_len = 0;
4467 int i;
4468
4469 if (!basic_rates)
4470 return 0;
4471
4472 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
4473 rates[rates_len++] = basic_rates[i] / 5;
4474
4475 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
4476}
4477
4478
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004479static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
4480 int slot, int ht_opmode, int ap_isolate,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004481 const int *basic_rates, int link_id)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004482{
4483 struct wpa_driver_nl80211_data *drv = bss->drv;
4484 struct nl_msg *msg;
4485
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004486 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
4487 (cts >= 0 &&
4488 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
4489 (preamble >= 0 &&
4490 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
4491 (slot >= 0 &&
4492 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
4493 (ht_opmode >= 0 &&
4494 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
4495 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004496 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004497 nl80211_put_basic_rates(msg, basic_rates) ||
4498 (link_id != NL80211_DRV_LINK_ID_NA &&
4499 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004500 nlmsg_free(msg);
4501 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004502 }
4503
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004504 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004505}
4506
4507
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004508static int wpa_driver_nl80211_set_acl(void *priv,
4509 struct hostapd_acl_params *params)
4510{
4511 struct i802_bss *bss = priv;
4512 struct wpa_driver_nl80211_data *drv = bss->drv;
4513 struct nl_msg *msg;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004514 struct nl_msg *acl;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004515 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 int ret;
Hai Shalomc1a21442022-02-04 13:43:00 -08004517 size_t acl_nla_sz, acl_nlmsg_sz, nla_sz, nlmsg_sz;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004518
4519 if (!(drv->capa.max_acl_mac_addrs))
4520 return -ENOTSUP;
4521
4522 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
4523 return -ENOTSUP;
4524
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004525 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
4526 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
4527
Hai Shalomc1a21442022-02-04 13:43:00 -08004528 acl_nla_sz = nla_total_size(ETH_ALEN) * params->num_mac_acl;
4529 acl_nlmsg_sz = nlmsg_total_size(acl_nla_sz);
4530 acl = nlmsg_alloc_size(acl_nlmsg_sz);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004531 if (!acl)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004532 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004533 for (i = 0; i < params->num_mac_acl; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004534 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
4535 nlmsg_free(acl);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004536 return -ENOMEM;
4537 }
4538 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004539
Hai Shalomc1a21442022-02-04 13:43:00 -08004540 /*
4541 * genetlink message header (Length of user header is 0) +
4542 * u32 attr: NL80211_ATTR_IFINDEX +
4543 * u32 attr: NL80211_ATTR_ACL_POLICY +
4544 * nested acl attr
4545 */
4546 nla_sz = GENL_HDRLEN +
4547 nla_total_size(4) * 2 +
4548 nla_total_size(acl_nla_sz);
4549 nlmsg_sz = nlmsg_total_size(nla_sz);
4550 if (!(msg = nl80211_ifindex_msg_build(drv, nlmsg_alloc_size(nlmsg_sz),
4551 drv->ifindex, 0,
4552 NL80211_CMD_SET_MAC_ACL)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004553 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
4554 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
4555 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
4556 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
4557 nlmsg_free(msg);
4558 nlmsg_free(acl);
4559 return -ENOMEM;
4560 }
4561 nlmsg_free(acl);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004562
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004563 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004564 if (ret) {
4565 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
4566 ret, strerror(-ret));
4567 }
4568
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004569 return ret;
4570}
4571
4572
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004573static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
4574{
4575 if (beacon_int > 0) {
4576 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
4577 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
4578 beacon_int);
4579 }
4580
4581 return 0;
4582}
4583
4584
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004585static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period)
4586{
4587 if (dtim_period > 0) {
4588 wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period);
4589 return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
4590 }
4591
4592 return 0;
4593}
4594
4595
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004596#ifdef CONFIG_MESH
4597static int nl80211_set_mesh_config(void *priv,
4598 struct wpa_driver_mesh_bss_params *params)
4599{
4600 struct i802_bss *bss = priv;
4601 struct wpa_driver_nl80211_data *drv = bss->drv;
4602 struct nl_msg *msg;
4603 int ret;
4604
4605 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG);
4606 if (!msg)
4607 return -1;
4608
4609 ret = nl80211_put_mesh_config(msg, params);
4610 if (ret < 0) {
4611 nlmsg_free(msg);
4612 return ret;
4613 }
4614
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004615 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004616 if (ret) {
4617 wpa_printf(MSG_ERROR,
4618 "nl80211: Mesh config set failed: %d (%s)",
4619 ret, strerror(-ret));
4620 return ret;
4621 }
4622 return 0;
4623}
4624#endif /* CONFIG_MESH */
4625
4626
Hai Shalom60840252021-02-19 19:02:11 -08004627static int nl80211_put_beacon_rate(struct nl_msg *msg, u64 flags, u64 flags2,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004628 struct wpa_driver_ap_params *params)
4629{
4630 struct nlattr *bands, *band;
4631 struct nl80211_txrate_vht vht_rate;
Hai Shalom60840252021-02-19 19:02:11 -08004632 struct nl80211_txrate_he he_rate;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004633
4634 if (!params->freq ||
4635 (params->beacon_rate == 0 &&
4636 params->rate_type == BEACON_RATE_LEGACY))
4637 return 0;
4638
4639 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
4640 if (!bands)
4641 return -1;
4642
4643 switch (params->freq->mode) {
4644 case HOSTAPD_MODE_IEEE80211B:
4645 case HOSTAPD_MODE_IEEE80211G:
4646 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
4647 break;
4648 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom60840252021-02-19 19:02:11 -08004649 if (is_6ghz_freq(params->freq->freq))
4650 band = nla_nest_start(msg, NL80211_BAND_6GHZ);
4651 else
4652 band = nla_nest_start(msg, NL80211_BAND_5GHZ);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004653 break;
4654 case HOSTAPD_MODE_IEEE80211AD:
4655 band = nla_nest_start(msg, NL80211_BAND_60GHZ);
4656 break;
4657 default:
4658 return 0;
4659 }
4660
4661 if (!band)
4662 return -1;
4663
4664 os_memset(&vht_rate, 0, sizeof(vht_rate));
Hai Shalom60840252021-02-19 19:02:11 -08004665 os_memset(&he_rate, 0, sizeof(he_rate));
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004666
4667 switch (params->rate_type) {
4668 case BEACON_RATE_LEGACY:
4669 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) {
4670 wpa_printf(MSG_INFO,
4671 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
4672 return -1;
4673 }
4674
4675 if (nla_put_u8(msg, NL80211_TXRATE_LEGACY,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004676 (u8) (params->beacon_rate / 5)) ||
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004677 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
4678 (params->freq->vht_enabled &&
4679 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4680 &vht_rate)))
4681 return -1;
4682
4683 wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)",
4684 params->beacon_rate);
4685 break;
4686 case BEACON_RATE_HT:
4687 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) {
4688 wpa_printf(MSG_INFO,
4689 "nl80211: Driver does not support setting Beacon frame rate (HT)");
4690 return -1;
4691 }
4692 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
4693 nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) ||
4694 (params->freq->vht_enabled &&
4695 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4696 &vht_rate)))
4697 return -1;
4698 wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u",
4699 params->beacon_rate);
4700 break;
4701 case BEACON_RATE_VHT:
4702 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) {
4703 wpa_printf(MSG_INFO,
4704 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
4705 return -1;
4706 }
4707 vht_rate.mcs[0] = BIT(params->beacon_rate);
4708 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL))
4709 return -1;
4710 if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL))
4711 return -1;
4712 if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4713 &vht_rate))
4714 return -1;
4715 wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u",
4716 params->beacon_rate);
4717 break;
Hai Shalom60840252021-02-19 19:02:11 -08004718 case BEACON_RATE_HE:
4719 if (!(flags2 & WPA_DRIVER_FLAGS2_BEACON_RATE_HE)) {
4720 wpa_printf(MSG_INFO,
4721 "nl80211: Driver does not support setting Beacon frame rate (HE)");
4722 return -1;
4723 }
4724 he_rate.mcs[0] = BIT(params->beacon_rate);
4725 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
4726 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
4727 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
4728 &vht_rate) ||
4729 nla_put(msg, NL80211_TXRATE_HE, sizeof(he_rate), &he_rate))
4730 return -1;
4731 wpa_printf(MSG_DEBUG, " * beacon_rate = HE-MCS %u",
4732 params->beacon_rate);
4733 break;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004734 }
4735
4736 nla_nest_end(msg, band);
4737 nla_nest_end(msg, bands);
4738
4739 return 0;
4740}
4741
4742
4743static int nl80211_set_multicast_to_unicast(struct i802_bss *bss,
4744 int multicast_to_unicast)
4745{
4746 struct wpa_driver_nl80211_data *drv = bss->drv;
4747 struct nl_msg *msg;
4748 int ret;
4749
4750 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST);
4751 if (!msg ||
4752 (multicast_to_unicast &&
4753 nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) {
4754 wpa_printf(MSG_ERROR,
4755 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
4756 bss->ifname);
4757 nlmsg_free(msg);
4758 return -ENOBUFS;
4759 }
4760
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004761 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004762
4763 switch (ret) {
4764 case 0:
4765 wpa_printf(MSG_DEBUG,
4766 "nl80211: multicast to unicast %s on interface %s",
4767 multicast_to_unicast ? "enabled" : "disabled",
4768 bss->ifname);
4769 break;
4770 case -EOPNOTSUPP:
4771 if (!multicast_to_unicast)
4772 break;
4773 wpa_printf(MSG_INFO,
4774 "nl80211: multicast to unicast not supported on interface %s",
4775 bss->ifname);
4776 break;
4777 default:
4778 wpa_printf(MSG_ERROR,
4779 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
4780 multicast_to_unicast ? "enabling" : "disabling",
4781 ret, strerror(-ret), bss->ifname);
4782 break;
4783 }
4784
4785 return ret;
4786}
4787
4788
Hai Shalom60840252021-02-19 19:02:11 -08004789#ifdef CONFIG_SAE
Sunil Ravi77d572f2023-01-17 23:58:31 +00004790static int nl80211_put_sae_pwe(struct nl_msg *msg, enum sae_pwe pwe)
Hai Shalom60840252021-02-19 19:02:11 -08004791{
4792 u8 sae_pwe;
4793
4794 wpa_printf(MSG_DEBUG, "nl802111: sae_pwe=%d", pwe);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004795 if (pwe == SAE_PWE_HUNT_AND_PECK)
Hai Shalom60840252021-02-19 19:02:11 -08004796 sae_pwe = NL80211_SAE_PWE_HUNT_AND_PECK;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004797 else if (pwe == SAE_PWE_HASH_TO_ELEMENT)
Hai Shalom60840252021-02-19 19:02:11 -08004798 sae_pwe = NL80211_SAE_PWE_HASH_TO_ELEMENT;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004799 else if (pwe == SAE_PWE_BOTH)
Hai Shalom60840252021-02-19 19:02:11 -08004800 sae_pwe = NL80211_SAE_PWE_BOTH;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004801 else if (pwe == SAE_PWE_FORCE_HUNT_AND_PECK)
Hai Shalom60840252021-02-19 19:02:11 -08004802 return 0; /* special test mode */
4803 else
4804 return -1;
4805 if (nla_put_u8(msg, NL80211_ATTR_SAE_PWE, sae_pwe))
4806 return -1;
4807
4808 return 0;
4809}
4810#endif /* CONFIG_SAE */
4811
4812
4813#ifdef CONFIG_FILS
4814static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg,
4815 struct wpa_driver_ap_params *params)
4816{
4817 struct nlattr *attr;
4818
4819 if (!bss->drv->fils_discovery) {
4820 wpa_printf(MSG_ERROR,
4821 "nl80211: Driver does not support FILS Discovery frame transmission for %s",
4822 bss->ifname);
4823 return -1;
4824 }
4825
4826 attr = nla_nest_start(msg, NL80211_ATTR_FILS_DISCOVERY);
4827 if (!attr ||
4828 nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MIN,
4829 params->fd_min_int) ||
4830 nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MAX,
4831 params->fd_max_int) ||
4832 (params->fd_frame_tmpl &&
4833 nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL,
4834 params->fd_frame_tmpl_len, params->fd_frame_tmpl)))
4835 return -1;
4836
4837 nla_nest_end(msg, attr);
4838 return 0;
4839}
4840#endif /* CONFIG_FILS */
4841
4842
4843#ifdef CONFIG_IEEE80211AX
Sunil Ravi77d572f2023-01-17 23:58:31 +00004844
Hai Shalom60840252021-02-19 19:02:11 -08004845static int nl80211_unsol_bcast_probe_resp(struct i802_bss *bss,
4846 struct nl_msg *msg,
4847 struct wpa_driver_ap_params *params)
4848{
4849 struct nlattr *attr;
4850
4851 if (!bss->drv->unsol_bcast_probe_resp) {
4852 wpa_printf(MSG_ERROR,
4853 "nl80211: Driver does not support unsolicited broadcast Probe Response frame transmission for %s",
4854 bss->ifname);
4855 return -1;
4856 }
4857
4858 wpa_printf(MSG_DEBUG,
4859 "nl80211: Unsolicited broadcast Probe Response frame interval: %u",
4860 params->unsol_bcast_probe_resp_interval);
4861 attr = nla_nest_start(msg, NL80211_ATTR_UNSOL_BCAST_PROBE_RESP);
4862 if (!attr ||
4863 nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT,
4864 params->unsol_bcast_probe_resp_interval) ||
4865 (params->unsol_bcast_probe_resp_tmpl &&
4866 nla_put(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL,
4867 params->unsol_bcast_probe_resp_tmpl_len,
4868 params->unsol_bcast_probe_resp_tmpl)))
4869 return -1;
4870
4871 nla_nest_end(msg, attr);
4872 return 0;
4873}
Sunil Ravi77d572f2023-01-17 23:58:31 +00004874
4875
4876static int nl80211_mbssid(struct nl_msg *msg,
4877 struct wpa_driver_ap_params *params)
4878{
4879 struct nlattr *config, *elems;
4880 int ifidx;
4881
4882 if (!params->mbssid_tx_iface)
4883 return 0;
4884
4885 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG);
4886 if (!config ||
4887 nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_INDEX,
4888 params->mbssid_index))
4889 return -1;
4890
4891 if (params->mbssid_tx_iface) {
4892 ifidx = if_nametoindex(params->mbssid_tx_iface);
4893 if (ifidx <= 0 ||
4894 nla_put_u32(msg, NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX,
4895 ifidx))
4896 return -1;
4897 }
4898
4899 if (params->ema && nla_put_flag(msg, NL80211_MBSSID_CONFIG_ATTR_EMA))
4900 return -1;
4901
4902 nla_nest_end(msg, config);
4903
4904 if (params->mbssid_elem_count && params->mbssid_elem_len &&
4905 params->mbssid_elem_offset && *params->mbssid_elem_offset) {
4906 u8 i, **offs = params->mbssid_elem_offset;
4907
4908 elems = nla_nest_start(msg, NL80211_ATTR_MBSSID_ELEMS);
4909 if (!elems)
4910 return -1;
4911
4912 for (i = 0; i < params->mbssid_elem_count - 1; i++) {
4913 if (nla_put(msg, i + 1, offs[i + 1] - offs[i], offs[i]))
4914 return -1;
4915 }
4916
4917 if (nla_put(msg, i + 1,
4918 *offs + params->mbssid_elem_len - offs[i],
4919 offs[i]))
4920 return -1;
4921
4922 nla_nest_end(msg, elems);
4923 }
4924
Sunil Ravi640215c2023-06-28 23:08:09 +00004925 if (!params->ema)
4926 return 0;
4927
4928 if (params->rnr_elem_count && params->rnr_elem_len &&
4929 params->rnr_elem_offset && *params->rnr_elem_offset) {
4930 u8 i, **offs = params->rnr_elem_offset;
4931
4932 elems = nla_nest_start(msg, NL80211_ATTR_EMA_RNR_ELEMS);
4933 if (!elems)
4934 return -1;
4935
4936 for (i = 0; i < params->rnr_elem_count - 1; i++) {
4937 if (nla_put(msg, i + 1, offs[i + 1] - offs[i], offs[i]))
4938 return -1;
4939 }
4940
4941 if (nla_put(msg, i + 1, *offs + params->rnr_elem_len - offs[i],
4942 offs[i]))
4943 return -1;
4944 nla_nest_end(msg, elems);
4945 }
4946
Sunil Ravi77d572f2023-01-17 23:58:31 +00004947 return 0;
4948}
4949
Hai Shalom60840252021-02-19 19:02:11 -08004950#endif /* CONFIG_IEEE80211AX */
4951
4952
Sunil Ravi640215c2023-06-28 23:08:09 +00004953#ifdef CONFIG_DRIVER_NL80211_QCA
4954static void qca_set_allowed_ap_freqs(struct wpa_driver_nl80211_data *drv,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004955 const int *freqs, int num_freqs,
4956 int link_id)
Sunil Ravi640215c2023-06-28 23:08:09 +00004957{
4958 struct nl_msg *msg;
4959 struct nlattr *params, *freqs_list;
4960 int i, ret;
4961
4962 if (!drv->set_wifi_conf_vendor_cmd_avail || !drv->qca_ap_allowed_freqs)
4963 return;
4964
4965 wpa_printf(MSG_DEBUG, "nl80211: Set AP allowed frequency list");
4966
4967 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
4968 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4969 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4970 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
4971 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
4972 goto err;
4973
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004974 if (link_id != NL80211_DRV_LINK_ID_NA &&
4975 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_MLO_LINK_ID, link_id))
4976 goto err;
4977
Sunil Ravi640215c2023-06-28 23:08:09 +00004978 freqs_list = nla_nest_start(
4979 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_AP_ALLOWED_FREQ_LIST);
4980 if (!freqs_list)
4981 goto err;
4982
4983 for (i = 0; i < num_freqs; i++) {
4984 if (nla_put_u32(msg, i, freqs[i]))
4985 goto err;
4986 }
4987
4988 nla_nest_end(msg, freqs_list);
4989 nla_nest_end(msg, params);
4990
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004991 ret = send_and_recv_cmd(drv, msg);
Sunil Ravi640215c2023-06-28 23:08:09 +00004992 if (ret)
4993 wpa_printf(MSG_ERROR,
4994 "nl80211: Failed set AP alllowed frequency list: %d (%s)",
4995 ret, strerror(-ret));
4996
4997 return;
4998err:
4999 nlmsg_free(msg);
5000}
5001#endif /* CONFIG_DRIVER_NL80211_QCA */
5002
5003
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005004static int nl80211_put_freq_params(struct nl_msg *msg,
5005 const struct hostapd_freq_params *freq)
5006{
5007 enum hostapd_hw_mode hw_mode;
5008 int is_24ghz;
5009 u8 channel;
5010
5011 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
5012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
5013 return -ENOBUFS;
5014
5015 wpa_printf(MSG_DEBUG, " * eht_enabled=%d", freq->eht_enabled);
5016 wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled);
5017 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
5018 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
5019 wpa_printf(MSG_DEBUG, " * radar_background=%d",
5020 freq->radar_background);
5021
5022 hw_mode = ieee80211_freq_to_chan(freq->freq, &channel);
5023 is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G ||
5024 hw_mode == HOSTAPD_MODE_IEEE80211B;
5025
5026 if (freq->vht_enabled ||
5027 ((freq->he_enabled || freq->eht_enabled) && !is_24ghz)) {
5028 enum nl80211_chan_width cw;
5029
5030 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
5031 switch (freq->bandwidth) {
5032 case 20:
5033 cw = NL80211_CHAN_WIDTH_20;
5034 break;
5035 case 40:
5036 cw = NL80211_CHAN_WIDTH_40;
5037 break;
5038 case 80:
5039 if (freq->center_freq2)
5040 cw = NL80211_CHAN_WIDTH_80P80;
5041 else
5042 cw = NL80211_CHAN_WIDTH_80;
5043 break;
5044 case 160:
5045 cw = NL80211_CHAN_WIDTH_160;
5046 break;
5047 case 320:
5048 cw = NL80211_CHAN_WIDTH_320;
5049 break;
5050 default:
5051 return -EINVAL;
5052 }
5053
5054 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
5055 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
5056 freq->center_freq1);
5057 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
5058 freq->center_freq2);
5059 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
5060 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
5061 freq->center_freq1) ||
5062 (freq->center_freq2 &&
5063 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
5064 freq->center_freq2)))
5065 return -ENOBUFS;
5066 } else if (freq->ht_enabled) {
5067 enum nl80211_channel_type ct;
5068
5069 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
5070 freq->sec_channel_offset);
5071 switch (freq->sec_channel_offset) {
5072 case -1:
5073 ct = NL80211_CHAN_HT40MINUS;
5074 break;
5075 case 1:
5076 ct = NL80211_CHAN_HT40PLUS;
5077 break;
5078 default:
5079 ct = NL80211_CHAN_HT20;
5080 break;
5081 }
5082
5083 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
5084 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
5085 return -ENOBUFS;
5086 } else if (freq->edmg.channels && freq->edmg.bw_config) {
5087 wpa_printf(MSG_DEBUG,
5088 " * EDMG configuration: channels=0x%x bw_config=%d",
5089 freq->edmg.channels, freq->edmg.bw_config);
5090 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
5091 freq->edmg.channels) ||
5092 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
5093 freq->edmg.bw_config))
5094 return -1;
5095 } else {
5096 wpa_printf(MSG_DEBUG, " * channel_type=%d",
5097 NL80211_CHAN_NO_HT);
5098 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
5099 NL80211_CHAN_NO_HT))
5100 return -ENOBUFS;
5101 }
5102 if (freq->radar_background &&
5103 nla_put_flag(msg, NL80211_ATTR_RADAR_BACKGROUND))
5104 return -ENOBUFS;
5105
5106 return 0;
5107}
5108
5109
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005110static int wpa_driver_nl80211_set_ap(void *priv,
5111 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005112{
5113 struct i802_bss *bss = priv;
5114 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005115 struct i802_link *link = bss->flink;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005116 struct nl_msg *msg;
5117 u8 cmd = NL80211_CMD_NEW_BEACON;
Hai Shalom74f70d42019-02-11 14:42:39 -08005118 int ret = -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005119 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005120 int num_suites;
Hai Shalomfdcde762020-04-02 11:19:20 -07005121 u32 suites[20], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005122 u32 ver;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005123#ifdef CONFIG_MESH
5124 struct wpa_driver_mesh_bss_params mesh_params;
5125#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005126
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005127 if (params->mld_ap) {
Sunil Ravi88611412024-06-28 17:34:56 +00005128 size_t i;
5129
5130 for (i = 0; i < bss->n_links; i++) {
5131 if (bss->links[i].link_id == params->mld_link_id) {
5132 link = &bss->links[i];
5133 break;
5134 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005135 }
Sunil Raviaf399a82024-05-05 20:56:55 +00005136
Sunil Ravi88611412024-06-28 17:34:56 +00005137 if (i == bss->n_links) {
5138 wpa_printf(MSG_DEBUG, "nl80211: Link ID=%u not found",
5139 params->mld_link_id);
5140 return -EINVAL;
5141 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005142 }
5143
5144 beacon_set = params->reenable ? 0 : link->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005145
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005146 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
5147 beacon_set);
5148 if (beacon_set)
5149 cmd = NL80211_CMD_SET_BEACON;
Paul Stewart092955c2017-02-06 09:13:09 -08005150 else if (!drv->device_ap_sme && !drv->use_monitor &&
5151 !nl80211_get_wiphy_data_ap(bss))
5152 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005153
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005154 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
5155 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005156 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
5157 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005158 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005159 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08005160 wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate);
5161 wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005162 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Hai Shalom74f70d42019-02-11 14:42:39 -08005163 wpa_printf(MSG_DEBUG, "nl80211: ssid=%s",
5164 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005165 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
5166 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
5167 params->head) ||
5168 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
5169 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005170 nl80211_put_beacon_int(msg, params->beacon_int) ||
Hai Shalom60840252021-02-19 19:02:11 -08005171 nl80211_put_beacon_rate(msg, drv->capa.flags, drv->capa.flags2,
5172 params) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005173 nl80211_put_dtim_period(msg, params->dtim_period) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005174 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
5175 goto fail;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005176
5177 if (params->mld_ap) {
5178 wpa_printf(MSG_DEBUG, "nl80211: link_id=%u",
5179 params->mld_link_id);
5180
5181 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
Sunil Ravi88611412024-06-28 17:34:56 +00005182 params->mld_link_id) ||
5183 (params->freq &&
5184 nl80211_put_freq_params(msg, params->freq) < 0))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005185 goto fail;
5186
Sunil Ravi88611412024-06-28 17:34:56 +00005187 nl80211_link_set_freq(bss, params->mld_link_id,
5188 params->freq->freq);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005189 }
5190
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005191 if (params->proberesp && params->proberesp_len) {
5192 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
5193 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005194 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
5195 params->proberesp))
5196 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005197 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005198 switch (params->hide_ssid) {
5199 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005200 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005201 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
5202 NL80211_HIDDEN_SSID_NOT_IN_USE))
5203 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005204 break;
5205 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005206 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005207 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
5208 NL80211_HIDDEN_SSID_ZERO_LEN))
5209 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005210 break;
5211 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005212 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005213 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
5214 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
5215 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005216 break;
5217 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005218 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005219 if (params->privacy &&
5220 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
5221 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005222 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005223 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
5224 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
5225 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005226 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
5227 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
5228 NL80211_AUTHTYPE_SHARED_KEY))
5229 goto fail;
5230 } else {
5231 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
5232 NL80211_AUTHTYPE_OPEN_SYSTEM))
5233 goto fail;
5234 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005235
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005236 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005237 ver = 0;
5238 if (params->wpa_version & WPA_PROTO_WPA)
5239 ver |= NL80211_WPA_VERSION_1;
5240 if (params->wpa_version & WPA_PROTO_RSN)
5241 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005242 if (ver &&
5243 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
5244 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005245
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005246 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
5247 params->key_mgmt_suites);
Hai Shalomfdcde762020-04-02 11:19:20 -07005248 num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites,
5249 suites, ARRAY_SIZE(suites));
5250 if (num_suites > NL80211_MAX_NR_AKM_SUITES)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005251 wpa_printf(MSG_DEBUG,
Hai Shalomfdcde762020-04-02 11:19:20 -07005252 "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)",
5253 num_suites);
5254 else if (num_suites &&
5255 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
5256 suites))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005257 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005258
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005259 if (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suites) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005260 (drv->capa.flags2 & WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005261 params->psk_len &&
5262 nla_put(msg, NL80211_ATTR_PMK, params->psk_len, params->psk))
5263 goto fail;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005264
5265 if (wpa_key_mgmt_sae(params->key_mgmt_suites) &&
5266 (drv->capa.flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005267 params->sae_password &&
5268 nla_put(msg, NL80211_ATTR_SAE_PASSWORD,
5269 os_strlen(params->sae_password), params->sae_password))
5270 goto fail;
5271
5272 if (nl80211_put_control_port(drv, msg) < 0)
5273 goto fail;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005274
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005275 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005276 (!params->pairwise_ciphers ||
5277 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005278 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005279 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005280
Sunil Ravia04bd252022-05-02 22:54:18 -07005281 if (drv->device_ap_sme) {
5282 u32 flags = 0;
5283
Sunil Ravi89eba102022-09-13 21:04:37 -07005284 if (params->key_mgmt_suites & (WPA_KEY_MGMT_SAE |
5285 WPA_KEY_MGMT_SAE_EXT_KEY)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07005286 /* Add the previously used flag attribute to support
5287 * older kernel versions and the newer flag bit for
5288 * newer kernels. */
5289 if (nla_put_flag(msg,
5290 NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
5291 goto fail;
5292 flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
5293 }
5294
5295 flags |= NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT;
5296
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005297 if (nl80211_attr_supported(drv,
5298 NL80211_ATTR_AP_SETTINGS_FLAGS) &&
5299 nla_put_u32(msg, NL80211_ATTR_AP_SETTINGS_FLAGS, flags))
Sunil Ravia04bd252022-05-02 22:54:18 -07005300 goto fail;
5301 }
Hai Shalom5f92bc92019-04-18 11:54:11 -07005302
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005303 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
5304 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005305 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
5306 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005307 if (num_suites &&
5308 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
5309 num_suites * sizeof(u32), suites))
5310 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005311
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005312 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
5313 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005314 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005315 if (suite &&
5316 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
5317 goto fail;
5318
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005319 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005320 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
5321 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005322 if (nla_put(msg, NL80211_ATTR_IE,
5323 wpabuf_len(params->beacon_ies),
5324 wpabuf_head(params->beacon_ies)))
5325 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005326 }
5327 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005328 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
5329 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005330 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
5331 wpabuf_len(params->proberesp_ies),
5332 wpabuf_head(params->proberesp_ies)))
5333 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005334 }
5335 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005336 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
5337 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005338 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
5339 wpabuf_len(params->assocresp_ies),
5340 wpabuf_head(params->assocresp_ies)))
5341 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005342 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005343
Dmitry Shmidt04949592012-07-19 12:16:46 -07005344 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07005345 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
5346 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005347 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
5348 params->ap_max_inactivity))
5349 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005350 }
5351
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005352#ifdef CONFIG_P2P
5353 if (params->p2p_go_ctwindow > 0) {
5354 if (drv->p2p_go_ctwindow_supported) {
5355 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
5356 params->p2p_go_ctwindow);
5357 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
5358 params->p2p_go_ctwindow))
5359 goto fail;
5360 } else {
5361 wpa_printf(MSG_INFO,
5362 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
5363 }
5364 }
5365#endif /* CONFIG_P2P */
5366
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005367 if (params->pbss) {
5368 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
5369 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
5370 goto fail;
5371 }
5372
Hai Shalom74f70d42019-02-11 14:42:39 -08005373 if (params->ftm_responder) {
5374 struct nlattr *ftm;
5375
5376 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) {
5377 ret = -ENOTSUP;
5378 goto fail;
5379 }
5380
5381 ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER);
5382 if (!ftm ||
5383 nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) ||
5384 (params->lci &&
5385 nla_put(msg, NL80211_FTM_RESP_ATTR_LCI,
5386 wpabuf_len(params->lci),
5387 wpabuf_head(params->lci))) ||
5388 (params->civic &&
5389 nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC,
5390 wpabuf_len(params->civic),
5391 wpabuf_head(params->civic))))
5392 goto fail;
5393 nla_nest_end(msg, ftm);
5394 }
5395
Hai Shalomc3565922019-10-28 11:58:20 -07005396#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08005397 if (params->he_spr_ctrl) {
Hai Shalomc3565922019-10-28 11:58:20 -07005398 struct nlattr *spr;
5399
5400 spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD);
Hai Shalom60840252021-02-19 19:02:11 -08005401 wpa_printf(MSG_DEBUG, "nl80211: he_spr_ctrl=0x%x",
5402 params->he_spr_ctrl);
Hai Shalomc3565922019-10-28 11:58:20 -07005403
Hai Shalomfdcde762020-04-02 11:19:20 -07005404 if (!spr ||
Hai Shalom60840252021-02-19 19:02:11 -08005405 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_SR_CTRL,
5406 params->he_spr_ctrl) ||
5407 ((params->he_spr_ctrl &
5408 SPATIAL_REUSE_NON_SRG_OFFSET_PRESENT) &&
5409 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET,
5410 params->he_spr_non_srg_obss_pd_max_offset)))
5411 goto fail;
5412
5413 if ((params->he_spr_ctrl &
5414 SPATIAL_REUSE_SRG_INFORMATION_PRESENT) &&
5415 (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET,
5416 params->he_spr_srg_obss_pd_min_offset) ||
5417 nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET,
5418 params->he_spr_srg_obss_pd_max_offset) ||
5419 nla_put(msg, NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP,
5420 sizeof(params->he_spr_bss_color_bitmap),
5421 params->he_spr_bss_color_bitmap) ||
5422 nla_put(msg, NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP,
5423 sizeof(params->he_spr_partial_bssid_bitmap),
5424 params->he_spr_partial_bssid_bitmap)))
Hai Shalomc3565922019-10-28 11:58:20 -07005425 goto fail;
5426
5427 nla_nest_end(msg, spr);
5428 }
Hai Shalomfdcde762020-04-02 11:19:20 -07005429
Sunil Ravi88611412024-06-28 17:34:56 +00005430 if (params->freq && nl80211_put_freq_params(msg, params->freq) < 0)
5431 goto fail;
5432
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005433 if (params->freq && params->freq->he_enabled &&
5434 nl80211_attr_supported(drv, NL80211_ATTR_HE_BSS_COLOR)) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005435 struct nlattr *bss_color;
5436
5437 bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR);
5438 if (!bss_color ||
5439 (params->he_bss_color_disabled &&
5440 nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) ||
5441 (params->he_bss_color_partial &&
5442 nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) ||
5443 nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR,
5444 params->he_bss_color))
5445 goto fail;
5446 nla_nest_end(msg, bss_color);
5447 }
5448
5449 if (params->twt_responder) {
5450 wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d",
5451 params->twt_responder);
5452 if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER))
5453 goto fail;
5454 }
Hai Shalom60840252021-02-19 19:02:11 -08005455
5456 if (params->unsol_bcast_probe_resp_interval &&
5457 nl80211_unsol_bcast_probe_resp(bss, msg, params) < 0)
5458 goto fail;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005459
5460 if (nl80211_mbssid(msg, params) < 0)
5461 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07005462#endif /* CONFIG_IEEE80211AX */
5463
Hai Shalom60840252021-02-19 19:02:11 -08005464#ifdef CONFIG_SAE
Sunil Ravi89eba102022-09-13 21:04:37 -07005465 if (wpa_key_mgmt_sae(params->key_mgmt_suites) &&
Hai Shalom60840252021-02-19 19:02:11 -08005466 nl80211_put_sae_pwe(msg, params->sae_pwe) < 0)
5467 goto fail;
5468#endif /* CONFIG_SAE */
5469
5470#ifdef CONFIG_FILS
5471 if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0)
5472 goto fail;
5473#endif /* CONFIG_FILS */
5474
Sunil Ravi036cec52023-03-29 11:35:17 -07005475 if (params->punct_bitmap) {
5476 wpa_printf(MSG_DEBUG, "nl80211: Puncturing bitmap=0x%04x",
5477 params->punct_bitmap);
5478 if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP,
5479 params->punct_bitmap))
5480 goto fail;
5481 }
5482
Sunil Ravi640215c2023-06-28 23:08:09 +00005483#ifdef CONFIG_DRIVER_NL80211_QCA
5484 if (cmd == NL80211_CMD_NEW_BEACON && params->allowed_freqs)
5485 qca_set_allowed_ap_freqs(drv, params->allowed_freqs,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005486 int_array_len(params->allowed_freqs),
5487 params->mld_ap ? params->mld_link_id :
5488 NL80211_DRV_LINK_ID_NA);
Sunil Ravi640215c2023-06-28 23:08:09 +00005489#endif /* CONFIG_DRIVER_NL80211_QCA */
5490
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005491 if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
5492 goto fail;
5493 ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL,
5494 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005495 if (ret) {
5496 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
5497 ret, strerror(-ret));
5498 } else {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005499 link->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005500 nl80211_set_bss(bss, params->cts_protect, params->preamble,
5501 params->short_slot_time, params->ht_opmode,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005502 params->isolate, params->basic_rates,
5503 params->mld_ap ? params->mld_link_id :
5504 NL80211_DRV_LINK_ID_NA);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08005505 nl80211_set_multicast_to_unicast(bss,
5506 params->multicast_to_unicast);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005507 if (beacon_set && params->freq &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005508 params->freq->bandwidth != link->bandwidth) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005509 wpa_printf(MSG_DEBUG,
5510 "nl80211: Update BSS %s bandwidth: %d -> %d",
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005511 bss->ifname, link->bandwidth,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005512 params->freq->bandwidth);
5513 ret = nl80211_set_channel(bss, params->freq, 1);
5514 if (ret) {
5515 wpa_printf(MSG_DEBUG,
5516 "nl80211: Frequency set failed: %d (%s)",
5517 ret, strerror(-ret));
5518 } else {
5519 wpa_printf(MSG_DEBUG,
5520 "nl80211: Frequency set succeeded for ht2040 coex");
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005521 link->bandwidth = params->freq->bandwidth;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005522 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005523 } else if (!beacon_set && params->freq) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005524 /*
5525 * cfg80211 updates the driver on frequence change in AP
5526 * mode only at the point when beaconing is started, so
5527 * set the initial value here.
5528 */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005529 link->bandwidth = params->freq->bandwidth;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005532
5533#ifdef CONFIG_MESH
5534 if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) {
5535 os_memset(&mesh_params, 0, sizeof(mesh_params));
5536 mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
5537 mesh_params.ht_opmode = params->ht_opmode;
5538 ret = nl80211_set_mesh_config(priv, &mesh_params);
5539 if (ret < 0)
5540 return ret;
5541 }
5542#endif /* CONFIG_MESH */
5543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005544 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005545fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005546 nlmsg_free(msg);
Hai Shalom74f70d42019-02-11 14:42:39 -08005547 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005548}
5549
5550
Sunil Ravi88611412024-06-28 17:34:56 +00005551static bool nl80211_link_valid(struct i802_bss *bss, s8 link_id)
5552{
5553 unsigned int i;
5554
5555 if (link_id < 0)
5556 return false;
5557
5558 for (i = 0; i < bss->n_links; i++) {
5559 wpa_printf(MSG_DEBUG, "nl80211: %s - i=%u, link_id=%u",
5560 __func__, i, bss->links[i].link_id);
5561 if (bss->links[i].link_id == NL80211_DRV_LINK_ID_NA)
5562 continue;
5563
5564 if (bss->links[i].link_id == link_id)
5565 return true;
5566 }
5567
5568 return false;
5569}
5570
5571
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005572static int nl80211_set_channel(struct i802_bss *bss,
5573 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005574{
5575 struct wpa_driver_nl80211_data *drv = bss->drv;
5576 struct nl_msg *msg;
5577 int ret;
5578
5579 wpa_printf(MSG_DEBUG,
Sunil Ravia04bd252022-05-02 22:54:18 -07005580 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, eht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
5581 freq->freq, freq->ht_enabled, freq->vht_enabled,
5582 freq->he_enabled, freq->eht_enabled, freq->bandwidth,
5583 freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005584
5585 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
5586 NL80211_CMD_SET_WIPHY);
5587 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
5588 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005589 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005590 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005591
Sunil Ravi88611412024-06-28 17:34:56 +00005592 if (nl80211_link_valid(bss, freq->link_id)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005593 wpa_printf(MSG_DEBUG, "nl80211: Set link_id=%u for freq",
5594 freq->link_id);
5595
5596 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, freq->link_id)) {
5597 nlmsg_free(msg);
5598 return -ENOBUFS;
5599 }
5600 }
5601
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005602 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005603 if (ret == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005604 nl80211_link_set_freq(bss, freq->link_id, freq->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005605 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005606 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005607 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005608 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005609 return -1;
5610}
5611
5612
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005613static u32 sta_flags_nl80211(int flags)
5614{
5615 u32 f = 0;
5616
5617 if (flags & WPA_STA_AUTHORIZED)
5618 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
5619 if (flags & WPA_STA_WMM)
5620 f |= BIT(NL80211_STA_FLAG_WME);
5621 if (flags & WPA_STA_SHORT_PREAMBLE)
5622 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
5623 if (flags & WPA_STA_MFP)
5624 f |= BIT(NL80211_STA_FLAG_MFP);
5625 if (flags & WPA_STA_TDLS_PEER)
5626 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005627 if (flags & WPA_STA_AUTHENTICATED)
5628 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005629 if (flags & WPA_STA_ASSOCIATED)
5630 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005631
5632 return f;
5633}
5634
5635
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005636#ifdef CONFIG_MESH
5637static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
5638{
5639 switch (state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005640 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005641 return NL80211_PLINK_LISTEN;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005642 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005643 return NL80211_PLINK_OPN_SNT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005644 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005645 return NL80211_PLINK_OPN_RCVD;
5646 case PLINK_CNF_RCVD:
5647 return NL80211_PLINK_CNF_RCVD;
5648 case PLINK_ESTAB:
5649 return NL80211_PLINK_ESTAB;
5650 case PLINK_HOLDING:
5651 return NL80211_PLINK_HOLDING;
5652 case PLINK_BLOCKED:
5653 return NL80211_PLINK_BLOCKED;
5654 default:
5655 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
5656 state);
5657 }
5658 return -1;
5659}
5660#endif /* CONFIG_MESH */
5661
5662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005663static int wpa_driver_nl80211_sta_add(void *priv,
5664 struct hostapd_sta_add_params *params)
5665{
5666 struct i802_bss *bss = priv;
5667 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005668 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005669 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005670 int ret = -ENOBUFS;
Sunil Ravi036cec52023-03-29 11:35:17 -07005671 u8 cmd;
5672 const char *cmd_string;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005673
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005674 if ((params->flags & WPA_STA_TDLS_PEER) &&
5675 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
5676 return -EOPNOTSUPP;
5677
Sunil Ravi036cec52023-03-29 11:35:17 -07005678 if (params->mld_link_sta) {
5679 cmd = params->set ? NL80211_CMD_MODIFY_LINK_STA :
5680 NL80211_CMD_ADD_LINK_STA;
5681 cmd_string = params->set ? "NL80211_CMD_MODIFY_LINK_STA" :
5682 "NL80211_CMD_ADD_LINK_STA";
5683 } else {
5684 cmd = params->set ? NL80211_CMD_SET_STATION :
5685 NL80211_CMD_NEW_STATION;
5686 cmd_string = params->set ? "NL80211_CMD_SET_STATION" :
5687 "NL80211_CMD_NEW_STATION";
5688 }
5689
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005690 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
Sunil Ravi036cec52023-03-29 11:35:17 -07005691 cmd_string, MAC2STR(params->addr));
5692 msg = nl80211_bss_msg(bss, 0, cmd);
5693 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005694 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005695
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005696 /*
5697 * Set the below properties only in one of the following cases:
5698 * 1. New station is added, already associated.
5699 * 2. Set WPA_STA_TDLS_PEER station.
5700 * 3. Set an already added unassociated station, if driver supports
5701 * full AP client state. (Set these properties after station became
5702 * associated will be rejected by the driver).
5703 */
5704 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
5705 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
5706 (params->flags & WPA_STA_ASSOCIATED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005707 wpa_hexdump(MSG_DEBUG, " * supported rates",
5708 params->supp_rates, params->supp_rates_len);
5709 wpa_printf(MSG_DEBUG, " * capability=0x%x",
5710 params->capability);
5711 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
5712 params->supp_rates_len, params->supp_rates) ||
5713 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
5714 params->capability))
5715 goto fail;
5716
5717 if (params->ht_capabilities) {
5718 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
5719 (u8 *) params->ht_capabilities,
5720 sizeof(*params->ht_capabilities));
5721 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
5722 sizeof(*params->ht_capabilities),
5723 params->ht_capabilities))
5724 goto fail;
5725 }
5726
5727 if (params->vht_capabilities) {
5728 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
5729 (u8 *) params->vht_capabilities,
5730 sizeof(*params->vht_capabilities));
5731 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
5732 sizeof(*params->vht_capabilities),
5733 params->vht_capabilities))
5734 goto fail;
5735 }
5736
Hai Shalom81f62d82019-07-22 12:10:00 -07005737 if (params->he_capab) {
5738 wpa_hexdump(MSG_DEBUG, " * he_capab",
5739 params->he_capab, params->he_capab_len);
5740 if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY,
5741 params->he_capab_len, params->he_capab))
5742 goto fail;
5743 }
5744
Hai Shalom60840252021-02-19 19:02:11 -08005745 if (params->he_6ghz_capab) {
5746 wpa_hexdump(MSG_DEBUG, " * he_6ghz_capab",
5747 params->he_6ghz_capab,
5748 sizeof(*params->he_6ghz_capab));
5749 if (nla_put(msg, NL80211_ATTR_HE_6GHZ_CAPABILITY,
5750 sizeof(*params->he_6ghz_capab),
5751 params->he_6ghz_capab))
5752 goto fail;
5753 }
5754
Sunil Ravia04bd252022-05-02 22:54:18 -07005755 if (params->eht_capab) {
5756 wpa_hexdump(MSG_DEBUG, " * eht_capab",
5757 params->eht_capab, params->eht_capab_len);
5758 if (nla_put(msg, NL80211_ATTR_EHT_CAPABILITY,
5759 params->eht_capab_len, params->eht_capab))
5760 goto fail;
5761 }
5762
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005763 if (params->ext_capab) {
5764 wpa_hexdump(MSG_DEBUG, " * ext_capab",
5765 params->ext_capab, params->ext_capab_len);
5766 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
5767 params->ext_capab_len, params->ext_capab))
5768 goto fail;
5769 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005770
5771 if (is_ap_interface(drv->nlmode) &&
5772 nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS,
5773 params->support_p2p_ps ?
5774 NL80211_P2P_PS_SUPPORTED :
5775 NL80211_P2P_PS_UNSUPPORTED))
5776 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005777 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005778 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07005779 if (params->aid) {
5780 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005781 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
5782 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07005783 } else {
5784 /*
5785 * cfg80211 validates that AID is non-zero, so we have
5786 * to make this a non-zero value for the TDLS case where
Hai Shalomc1a21442022-02-04 13:43:00 -08005787 * a stub STA entry is used for now and for a station
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005788 * that is still not associated.
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07005789 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005790 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
5791 (params->flags & WPA_STA_TDLS_PEER) ?
5792 "TDLS" : "UNASSOC_STA");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005793 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
5794 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07005795 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005796 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
5797 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005798 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
5799 params->listen_interval))
5800 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005801 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
5802 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005803 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
5804 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005805 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
5806 (params->flags & WPA_STA_ASSOCIATED)) {
5807 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
5808 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
5809 params->listen_interval);
5810 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
5811 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
5812 params->listen_interval))
5813 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005814 }
5815
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005816 if (params->vht_opmode_enabled) {
5817 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005818 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
5819 params->vht_opmode))
5820 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005821 }
5822
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005823 if (params->supp_channels) {
5824 wpa_hexdump(MSG_DEBUG, " * supported channels",
5825 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005826 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
5827 params->supp_channels_len, params->supp_channels))
5828 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005829 }
5830
5831 if (params->supp_oper_classes) {
5832 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
5833 params->supp_oper_classes,
5834 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005835 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
5836 params->supp_oper_classes_len,
5837 params->supp_oper_classes))
5838 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005839 }
5840
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005841 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005842 upd.set = sta_flags_nl80211(params->flags);
5843 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005844
5845 /*
5846 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
5847 * flags, as nl80211 driver moves a new station, by default, into
5848 * associated state.
5849 *
5850 * On the other hand, if the driver supports that feature and the
5851 * station is added in unauthenticated state, set the
5852 * authenticated/associated bits in the mask to prevent moving this
5853 * station to associated state before it is actually associated.
5854 *
5855 * This is irrelevant for mesh mode where the station is added to the
5856 * driver as authenticated already, and ASSOCIATED isn't part of the
5857 * nl80211 API.
5858 */
5859 if (!is_mesh_interface(drv->nlmode)) {
5860 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
5861 wpa_printf(MSG_DEBUG,
5862 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
5863 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
5864 BIT(NL80211_STA_FLAG_AUTHENTICATED));
5865 } else if (!params->set &&
5866 !(params->flags & WPA_STA_TDLS_PEER)) {
5867 if (!(params->flags & WPA_STA_AUTHENTICATED))
5868 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
5869 if (!(params->flags & WPA_STA_ASSOCIATED))
5870 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
5871 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005872#ifdef CONFIG_MESH
5873 } else {
5874 if (params->plink_state == PLINK_ESTAB && params->peer_aid) {
5875 ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID,
5876 params->peer_aid);
5877 if (ret)
5878 goto fail;
5879 }
5880#endif /* CONFIG_MESH */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005881 }
5882
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005883 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
5884 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005885 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
5886 goto fail;
5887
5888#ifdef CONFIG_MESH
5889 if (params->plink_state &&
5890 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
5891 sta_plink_state_nl80211(params->plink_state)))
5892 goto fail;
5893#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005894
Hai Shalomc3565922019-10-28 11:58:20 -07005895 if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
5896 FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) &&
5897 (params->flags & WPA_STA_WMM)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005898 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
5899
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005900 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005901 if (!wme ||
5902 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
5903 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
5904 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
5905 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
5906 WMM_QOSINFO_STA_SP_MASK))
5907 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07005908 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005909 }
5910
Sunil Ravi036cec52023-03-29 11:35:17 -07005911 /* In case we are an AP MLD need to always specify the link ID */
5912 if (params->mld_link_id >= 0) {
5913 wpa_printf(MSG_DEBUG, " * mld_link_id=%d",
5914 params->mld_link_id);
5915 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
5916 params->mld_link_id))
5917 goto fail;
5918
5919 /*
5920 * If the link address is specified the station is a non-AP MLD
5921 * and thus need to provide the MLD address as the station
5922 * address, and the non-AP MLD link address as the link address.
5923 */
5924 if (params->mld_link_addr) {
5925 wpa_printf(MSG_DEBUG, " * mld_link_addr=" MACSTR,
5926 MAC2STR(params->mld_link_addr));
5927
5928 if (nla_put(msg, NL80211_ATTR_MLD_ADDR,
5929 ETH_ALEN, params->addr) ||
5930 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
5931 params->mld_link_addr))
5932 goto fail;
5933 } else {
5934 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
5935 params->addr))
5936 goto fail;
5937 }
5938 } else {
5939 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
5940 goto fail;
5941 }
5942
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005943 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005944 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005945 if (ret)
Sunil Ravi036cec52023-03-29 11:35:17 -07005946 wpa_printf(MSG_DEBUG, "nl80211: %s result: %d (%s)",
5947 cmd_string, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005948 if (ret == -EEXIST)
5949 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005950fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005951 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005952 return ret;
5953}
5954
5955
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005956static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
5957{
Sunil Ravi88611412024-06-28 17:34:56 +00005958#ifdef CONFIG_LIBNL3_ROUTE
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005959 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi88611412024-06-28 17:34:56 +00005960 struct rtnl_neigh *rn;
5961 struct nl_addr *nl_addr;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005962 int err;
5963
Sunil Ravi88611412024-06-28 17:34:56 +00005964 rn = rtnl_neigh_alloc();
5965 if (!rn)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005966 return;
5967
Sunil Ravi88611412024-06-28 17:34:56 +00005968 rtnl_neigh_set_family(rn, AF_BRIDGE);
5969 rtnl_neigh_set_ifindex(rn, bss->ifindex);
5970 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
5971 if (!nl_addr) {
5972 rtnl_neigh_put(rn);
5973 return;
5974 }
5975 rtnl_neigh_set_lladdr(rn, nl_addr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005976
Sunil Ravi88611412024-06-28 17:34:56 +00005977 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005978 if (err < 0) {
5979 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
5980 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
5981 bss->ifindex, nl_geterror(err));
5982 } else {
5983 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
5984 MACSTR, MAC2STR(addr));
5985 }
5986
Sunil Ravi88611412024-06-28 17:34:56 +00005987 nl_addr_put(nl_addr);
5988 rtnl_neigh_put(rn);
5989#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005990}
5991
5992
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005993static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
5994 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005995{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005996 struct wpa_driver_nl80211_data *drv = bss->drv;
5997 struct nl_msg *msg;
5998 int ret;
5999
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006000 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
6001 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
6002 (deauth == 0 &&
6003 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
6004 WLAN_FC_STYPE_DISASSOC)) ||
6005 (deauth == 1 &&
6006 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
6007 WLAN_FC_STYPE_DEAUTH)) ||
6008 (reason_code &&
6009 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
6010 nlmsg_free(msg);
6011 return -ENOBUFS;
6012 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006013
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006014 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006015 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
6016 " --> %d (%s)",
6017 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006018
6019 if (drv->rtnl_sk)
6020 rtnl_neigh_delete_fdb_entry(bss, addr);
6021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006022 if (ret == -ENOENT)
6023 return 0;
6024 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006025}
6026
6027
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006028void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006029{
6030 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006031 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006032
6033 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
6034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006036 dl_list_for_each(drv2, &drv->global->interfaces,
6037 struct wpa_driver_nl80211_data, list)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006038 {
6039 del_ifidx(drv2, ifidx, IFIDX_ANY);
6040 /* Remove all bridges learned for this iface */
6041 del_ifidx(drv2, IFIDX_ANY, ifidx);
6042 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006043
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006044 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006045 if (send_and_recv_cmd(drv, msg) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006046 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006047 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
6048}
6049
6050
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07006051const char * nl80211_iftype_str(enum nl80211_iftype mode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006052{
6053 switch (mode) {
6054 case NL80211_IFTYPE_ADHOC:
6055 return "ADHOC";
6056 case NL80211_IFTYPE_STATION:
6057 return "STATION";
6058 case NL80211_IFTYPE_AP:
6059 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07006060 case NL80211_IFTYPE_AP_VLAN:
6061 return "AP_VLAN";
6062 case NL80211_IFTYPE_WDS:
6063 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006064 case NL80211_IFTYPE_MONITOR:
6065 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07006066 case NL80211_IFTYPE_MESH_POINT:
6067 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006068 case NL80211_IFTYPE_P2P_CLIENT:
6069 return "P2P_CLIENT";
6070 case NL80211_IFTYPE_P2P_GO:
6071 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006072 case NL80211_IFTYPE_P2P_DEVICE:
6073 return "P2P_DEVICE";
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006074 case NL80211_IFTYPE_OCB:
6075 return "OCB";
6076 case NL80211_IFTYPE_NAN:
6077 return "NAN";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006078 default:
6079 return "unknown";
6080 }
6081}
6082
6083
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006084static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
6085 const char *ifname,
6086 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006087 const u8 *addr, int wds,
6088 int (*handler)(struct nl_msg *, void *),
6089 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006090{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006091 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006092 int ifidx;
6093 int ret = -ENOBUFS;
6094
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006095 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
6096 iftype, nl80211_iftype_str(iftype));
6097
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006098 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
6099 if (!msg ||
6100 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
6101 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
6102 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006103
6104 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006105 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006107 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006108 if (!flags ||
6109 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
6110 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006111
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006112 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006113 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006114 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
6115 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006116 }
6117
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07006118 /*
6119 * Tell cfg80211 that the interface belongs to the socket that created
6120 * it, and the interface should be deleted when the socket is closed.
6121 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006122 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
6123 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07006124
Hai Shalom60840252021-02-19 19:02:11 -08006125 if ((addr && iftype == NL80211_IFTYPE_P2P_DEVICE) &&
6126 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
6127 goto fail;
6128
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006129 ret = send_and_recv_resp(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006130 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006131 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006132 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006133 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006134 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
6135 ifname, ret, strerror(-ret));
6136 return ret;
6137 }
6138
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006139 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
6140 return 0;
6141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006142 ifidx = if_nametoindex(ifname);
6143 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
6144 ifname, ifidx);
6145
6146 if (ifidx <= 0)
6147 return -1;
6148
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006149 /*
6150 * Some virtual interfaces need to process EAPOL packets and events on
6151 * the parent interface. This is used mainly with hostapd.
6152 */
6153 if (drv->hostapd ||
6154 iftype == NL80211_IFTYPE_AP_VLAN ||
6155 iftype == NL80211_IFTYPE_WDS ||
6156 iftype == NL80211_IFTYPE_MONITOR) {
6157 /* start listening for EAPOL on this interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006158 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006159 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006160
6161 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006162 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006163 nl80211_remove_iface(drv, ifidx);
6164 return -1;
6165 }
6166
6167 return ifidx;
6168}
6169
6170
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006171int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
6172 const char *ifname, enum nl80211_iftype iftype,
6173 const u8 *addr, int wds,
6174 int (*handler)(struct nl_msg *, void *),
6175 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006176{
6177 int ret;
6178
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006179 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
6180 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006182 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006183 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006184 if (use_existing) {
6185 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
6186 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006187 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
6188 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
6189 addr) < 0 &&
6190 (linux_set_iface_flags(drv->global->ioctl_sock,
6191 ifname, 0) < 0 ||
6192 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
6193 addr) < 0 ||
6194 linux_set_iface_flags(drv->global->ioctl_sock,
6195 ifname, 1) < 0))
6196 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006197 return -ENFILE;
6198 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006199 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
6200
6201 /* Try to remove the interface that was already there. */
6202 nl80211_remove_iface(drv, if_nametoindex(ifname));
6203
6204 /* Try to create the interface again */
6205 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006206 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006207 }
6208
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006209 if (ret >= 0 && is_p2p_net_interface(iftype)) {
6210 wpa_printf(MSG_DEBUG,
6211 "nl80211: Interface %s created for P2P - disable 11b rates",
6212 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006213 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006214 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006215
6216 return ret;
6217}
6218
6219
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006220static int nl80211_setup_ap(struct i802_bss *bss)
6221{
6222 struct wpa_driver_nl80211_data *drv = bss->drv;
6223
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006224 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
6225 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006226
6227 /*
6228 * Disable Probe Request reporting unless we need it in this way for
6229 * devices that include the AP SME, in the other case (unless using
6230 * monitor iface) we'll get it through the nl_mgmt socket instead.
6231 */
6232 if (!drv->device_ap_sme)
6233 wpa_driver_nl80211_probe_req_report(bss, 0);
6234
6235 if (!drv->device_ap_sme && !drv->use_monitor)
6236 if (nl80211_mgmt_subscribe_ap(bss))
6237 return -1;
6238
6239 if (drv->device_ap_sme && !drv->use_monitor)
6240 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006241 wpa_printf(MSG_DEBUG,
6242 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006243
6244 if (!drv->device_ap_sme && drv->use_monitor &&
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006245 nl80211_create_monitor_interface(drv) &&
6246 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006247 return -1;
6248
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006249 if (drv->device_ap_sme &&
6250 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
6251 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
6252 "Probe Request frame reporting in AP mode");
6253 /* Try to survive without this */
6254 }
6255
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006256 return 0;
6257}
6258
6259
6260static void nl80211_teardown_ap(struct i802_bss *bss)
6261{
6262 struct wpa_driver_nl80211_data *drv = bss->drv;
6263
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006264 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
6265 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006266 if (drv->device_ap_sme) {
6267 wpa_driver_nl80211_probe_req_report(bss, 0);
6268 if (!drv->use_monitor)
6269 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
6270 } else if (drv->use_monitor)
6271 nl80211_remove_monitor_interface(drv);
6272 else
6273 nl80211_mgmt_unsubscribe(bss, "AP teardown");
6274
Paul Stewart092955c2017-02-06 09:13:09 -08006275 nl80211_put_wiphy_data_ap(bss);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006276 if (bss->flink)
6277 bss->flink->beacon_set = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006278}
6279
6280
Hai Shalomfdcde762020-04-02 11:19:20 -07006281static int nl80211_tx_control_port(void *priv, const u8 *dest,
6282 u16 proto, const u8 *buf, size_t len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006283 int no_encrypt, int link_id)
Hai Shalomfdcde762020-04-02 11:19:20 -07006284{
Hai Shalom899fcc72020-10-19 14:38:18 -07006285 struct nl80211_ack_ext_arg ext_arg;
Hai Shalomfdcde762020-04-02 11:19:20 -07006286 struct i802_bss *bss = priv;
6287 struct nl_msg *msg;
Hai Shalom899fcc72020-10-19 14:38:18 -07006288 u64 cookie = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07006289 int ret;
6290
6291 wpa_printf(MSG_DEBUG,
6292 "nl80211: Send over control port dest=" MACSTR
6293 " proto=0x%04x len=%u no_encrypt=%d",
6294 MAC2STR(dest), proto, (unsigned int) len, no_encrypt);
6295
6296 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME);
6297 if (!msg ||
6298 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
6299 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) ||
6300 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
6301 (no_encrypt &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006302 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) ||
6303 (link_id != NL80211_DRV_LINK_ID_NA &&
6304 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) {
Hai Shalomfdcde762020-04-02 11:19:20 -07006305 nlmsg_free(msg);
6306 return -ENOBUFS;
6307 }
6308
Hai Shalom899fcc72020-10-19 14:38:18 -07006309 os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg));
6310 ext_arg.ext_data = &cookie;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006311 ret = send_and_recv(bss->drv->global, bss->drv->global->nl, msg,
6312 NULL, NULL, ack_handler_cookie, &ext_arg, NULL);
Hai Shalom899fcc72020-10-19 14:38:18 -07006313 if (ret) {
Hai Shalomfdcde762020-04-02 11:19:20 -07006314 wpa_printf(MSG_DEBUG,
6315 "nl80211: tx_control_port failed: ret=%d (%s)",
6316 ret, strerror(-ret));
Hai Shalom899fcc72020-10-19 14:38:18 -07006317 } else {
6318 struct wpa_driver_nl80211_data *drv = bss->drv;
6319
6320 wpa_printf(MSG_DEBUG,
6321 "nl80211: tx_control_port cookie=0x%llx",
6322 (long long unsigned int) cookie);
6323 drv->eapol_tx_cookie = cookie;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006324 drv->eapol_tx_link_id = link_id;
Hai Shalom899fcc72020-10-19 14:38:18 -07006325 }
Hai Shalomfdcde762020-04-02 11:19:20 -07006326
6327 return ret;
6328}
6329
6330
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006331static int nl80211_send_eapol_data(struct i802_bss *bss,
6332 const u8 *addr, const u8 *data,
6333 size_t data_len)
6334{
6335 struct sockaddr_ll ll;
6336 int ret;
6337
6338 if (bss->drv->eapol_tx_sock < 0) {
6339 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
6340 return -1;
6341 }
6342
6343 os_memset(&ll, 0, sizeof(ll));
6344 ll.sll_family = AF_PACKET;
6345 ll.sll_ifindex = bss->ifindex;
6346 ll.sll_protocol = htons(ETH_P_PAE);
6347 ll.sll_halen = ETH_ALEN;
6348 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
6349 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
6350 (struct sockaddr *) &ll, sizeof(ll));
6351 if (ret < 0)
6352 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
6353 strerror(errno));
6354
6355 return ret;
6356}
6357
6358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006359static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
6360
6361static int wpa_driver_nl80211_hapd_send_eapol(
6362 void *priv, const u8 *addr, const u8 *data,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006363 size_t data_len, int encrypt, const u8 *own_addr, u32 flags,
6364 int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006365{
6366 struct i802_bss *bss = priv;
6367 struct wpa_driver_nl80211_data *drv = bss->drv;
6368 struct ieee80211_hdr *hdr;
6369 size_t len;
6370 u8 *pos;
6371 int res;
6372 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08006373
Hai Shalomb755a2a2020-04-23 21:49:02 -07006374 /* For now, disable EAPOL TX over control port in AP mode by default
6375 * since it does not provide TX status notifications. */
6376 if (drv->control_port_ap &&
6377 (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT))
Hai Shalomfdcde762020-04-02 11:19:20 -07006378 return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006379 data, data_len, !encrypt,
6380 link_id);
Hai Shalomfdcde762020-04-02 11:19:20 -07006381
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006382 if (drv->device_ap_sme || !drv->use_monitor)
6383 return nl80211_send_eapol_data(bss, addr, data, data_len);
6384
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006385 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
6386 data_len;
6387 hdr = os_zalloc(len);
6388 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006389 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
6390 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006391 return -1;
6392 }
6393
6394 hdr->frame_control =
6395 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
6396 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
6397 if (encrypt)
6398 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
6399 if (qos) {
6400 hdr->frame_control |=
6401 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
6402 }
6403
6404 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
6405 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
6406 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
6407 pos = (u8 *) (hdr + 1);
6408
6409 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006410 /* Set highest priority in QoS header */
6411 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006412 pos[1] = 0;
6413 pos += 2;
6414 }
6415
6416 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
6417 pos += sizeof(rfc1042_header);
6418 WPA_PUT_BE16(pos, ETH_P_PAE);
6419 pos += 2;
6420 memcpy(pos, data, data_len);
6421
Hai Shalomfdcde762020-04-02 11:19:20 -07006422 res = nl80211_send_monitor(drv, hdr, len, encrypt, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006423 if (res < 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07006424 wpa_printf(MSG_ERROR,
6425 "hapd_send_eapol - packet len: %lu - failed",
6426 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006427 }
6428 os_free(hdr);
6429
6430 return res;
6431}
6432
6433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006434static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006435 unsigned int total_flags,
6436 unsigned int flags_or,
6437 unsigned int flags_and)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006438{
6439 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006440 struct nl_msg *msg;
6441 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006442 struct nl80211_sta_flag_update upd;
6443
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006444 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
6445 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
6446 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
6447 !!(total_flags & WPA_STA_AUTHORIZED));
6448
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006449 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6450 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
6451 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006452
6453 /*
6454 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
6455 * can be removed eventually.
6456 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006457 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006458 if (!flags ||
6459 ((total_flags & WPA_STA_AUTHORIZED) &&
6460 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
6461 ((total_flags & WPA_STA_WMM) &&
6462 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
6463 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
6464 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
6465 ((total_flags & WPA_STA_MFP) &&
6466 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
6467 ((total_flags & WPA_STA_TDLS_PEER) &&
6468 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
6469 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006470
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006471 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006472
6473 os_memset(&upd, 0, sizeof(upd));
6474 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
6475 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006476 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
6477 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006478
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006479 return send_and_recv_cmd(bss->drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006480fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006481 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006482 return -ENOBUFS;
6483}
6484
6485
Hai Shalom81f62d82019-07-22 12:10:00 -07006486static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr,
6487 unsigned int weight)
6488{
6489 struct i802_bss *bss = priv;
6490 struct nl_msg *msg;
Hai Shalomc1a21442022-02-04 13:43:00 -08006491 int ret;
Hai Shalom81f62d82019-07-22 12:10:00 -07006492
6493 wpa_printf(MSG_DEBUG,
6494 "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR
6495 " weight=%u", bss->ifname, MAC2STR(addr), weight);
6496
6497 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6498 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
6499 nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight))
6500 goto fail;
6501
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006502 ret = send_and_recv_cmd(bss->drv, msg);
Hai Shalomc1a21442022-02-04 13:43:00 -08006503 if (ret) {
6504 wpa_printf(MSG_DEBUG,
6505 "nl80211: SET_STATION[AIRTIME_WEIGHT] failed: ret=%d (%s)",
6506 ret, strerror(-ret));
6507 }
6508 return ret;
Hai Shalom81f62d82019-07-22 12:10:00 -07006509fail:
6510 nlmsg_free(msg);
6511 return -ENOBUFS;
6512}
6513
6514
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006515static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
6516 struct wpa_driver_associate_params *params)
6517{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006518 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006519
6520 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006521 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
6522 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006523 nlmode = NL80211_IFTYPE_P2P_GO;
6524 } else
6525 nlmode = NL80211_IFTYPE_AP;
6526
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006527 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006528 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006529 nl80211_remove_monitor_interface(drv);
6530 return -1;
6531 }
6532
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006533 if (params->freq.freq &&
6534 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006535 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006536 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006537 nl80211_remove_monitor_interface(drv);
6538 return -1;
6539 }
6540
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006541 return 0;
6542}
6543
6544
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006545static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
6546 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006547{
6548 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006549 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006550
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006551 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006552 ret = send_and_recv(drv->global, drv->first_bss->nl_connect, msg, NULL,
6553 NULL, NULL, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006554 if (ret) {
6555 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
6556 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006557 } else {
6558 wpa_printf(MSG_DEBUG,
6559 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006560 }
6561
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006562 if (reset_mode &&
6563 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07006564 NL80211_IFTYPE_STATION)) {
6565 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
6566 "station mode");
6567 }
6568
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006569 return ret;
6570}
6571
6572
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006573static int nl80211_ht_vht_overrides(struct nl_msg *msg,
6574 struct wpa_driver_associate_params *params)
6575{
6576 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
6577 return -1;
6578
6579 if (params->htcaps && params->htcaps_mask) {
6580 int sz = sizeof(struct ieee80211_ht_capabilities);
6581 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
6582 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
6583 params->htcaps_mask, sz);
6584 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
6585 params->htcaps) ||
6586 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
6587 params->htcaps_mask))
6588 return -1;
6589 }
6590
6591#ifdef CONFIG_VHT_OVERRIDES
6592 if (params->disable_vht) {
6593 wpa_printf(MSG_DEBUG, " * VHT disabled");
6594 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
6595 return -1;
6596 }
6597
6598 if (params->vhtcaps && params->vhtcaps_mask) {
6599 int sz = sizeof(struct ieee80211_vht_capabilities);
6600 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
6601 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
6602 params->vhtcaps_mask, sz);
6603 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
6604 params->vhtcaps) ||
6605 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
6606 params->vhtcaps_mask))
6607 return -1;
6608 }
6609#endif /* CONFIG_VHT_OVERRIDES */
6610
Hai Shalomc1a21442022-02-04 13:43:00 -08006611#ifdef CONFIG_HE_OVERRIDES
6612 if (params->disable_he) {
6613 wpa_printf(MSG_DEBUG, " * HE disabled");
6614 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_HE))
6615 return -1;
6616 }
6617#endif /* CONFIG_HE_OVERRIDES */
6618
Sunil Ravi77d572f2023-01-17 23:58:31 +00006619 if (params->disable_eht) {
6620 wpa_printf(MSG_DEBUG, " * EHT disabled");
6621 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_EHT))
6622 return -1;
6623 }
6624
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006625 return 0;
6626}
6627
6628
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006629static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
6630 struct wpa_driver_associate_params *params)
6631{
6632 struct nl_msg *msg;
6633 int ret = -1;
6634 int count = 0;
6635
6636 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
6637
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006638 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006639 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
6640 "IBSS mode");
6641 return -1;
6642 }
6643
6644retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006645 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
6646 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
6647 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006648
Hai Shalom74f70d42019-02-11 14:42:39 -08006649 wpa_printf(MSG_DEBUG, " * SSID=%s",
6650 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006651 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
6652 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006653 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
6654 drv->ssid_len = params->ssid_len;
6655
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006656 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
6657 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006658 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006659
6660 ret = nl80211_set_conn_keys(params, msg);
6661 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006662 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006663
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006664 if (params->bssid && params->fixed_bssid) {
6665 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
6666 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006667 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
6668 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006669 }
6670
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006671 if (params->fixed_freq) {
6672 wpa_printf(MSG_DEBUG, " * fixed_freq");
6673 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
6674 goto fail;
6675 }
6676
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006677 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
6678 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
6679 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006680 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
6681 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006682 wpa_printf(MSG_DEBUG, " * control port");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006683 if (nl80211_put_control_port(drv, msg))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006684 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006685 }
6686
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006687 if (params->wpa_ie) {
6688 wpa_hexdump(MSG_DEBUG,
6689 " * Extra IEs for Beacon/Probe Response frames",
6690 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006691 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
6692 params->wpa_ie))
6693 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006694 }
6695
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08006696 ret = nl80211_ht_vht_overrides(msg, params);
6697 if (ret < 0)
6698 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006699
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006700 if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
6701 goto fail;
6702 ret = send_and_recv(drv->global, drv->first_bss->nl_connect, msg, NULL,
6703 NULL, NULL, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006704 msg = NULL;
6705 if (ret) {
6706 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
6707 ret, strerror(-ret));
6708 count++;
6709 if (ret == -EALREADY && count == 1) {
6710 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
6711 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006712 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006713 nlmsg_free(msg);
6714 goto retry;
6715 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006716 } else {
6717 wpa_printf(MSG_DEBUG,
6718 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006719 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006720
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006721fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006722 nlmsg_free(msg);
6723 return ret;
6724}
6725
6726
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006727static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv,
6728 struct wpa_driver_associate_params *params,
6729 struct nl_msg *msg)
6730{
6731 if (params->fils_erp_username_len) {
6732 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username",
6733 params->fils_erp_username,
6734 params->fils_erp_username_len);
6735 if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME,
6736 params->fils_erp_username_len,
6737 params->fils_erp_username))
6738 return -1;
6739 }
6740
6741 if (params->fils_erp_realm_len) {
6742 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm",
6743 params->fils_erp_realm,
6744 params->fils_erp_realm_len);
6745 if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM,
6746 params->fils_erp_realm_len, params->fils_erp_realm))
6747 return -1;
6748 }
6749
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006750 if (params->fils_erp_rrk_len) {
Vinita S. Maloo3a5b4412020-05-19 17:43:22 +05306751 wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u",
6752 params->fils_erp_next_seq_num);
6753 if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
6754 params->fils_erp_next_seq_num))
6755 return -1;
6756
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006757 wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)",
6758 (unsigned long) params->fils_erp_rrk_len);
6759 if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK,
6760 params->fils_erp_rrk_len, params->fils_erp_rrk))
6761 return -1;
6762 }
6763
6764 return 0;
6765}
6766
6767
Sunil Ravi89eba102022-09-13 21:04:37 -07006768static unsigned int num_bits_set(u32 val)
6769{
6770 unsigned int c;
6771
6772 for (c = 0; val; c++)
6773 val &= val - 1;
6774
6775 return c;
6776}
6777
6778
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006779static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
6780 struct wpa_driver_associate_params *params,
6781 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006782{
Sunil Ravi77d572f2023-01-17 23:58:31 +00006783 if (params->mld_params.mld_addr && params->mld_params.valid_links > 0) {
6784 struct wpa_driver_mld_params *mld_params = &params->mld_params;
6785 struct nlattr *links, *attr;
Sunil Ravi88611412024-06-28 17:34:56 +00006786 int i;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006787 u8 link_id;
6788
6789 wpa_printf(MSG_DEBUG, " * MLD: MLD addr=" MACSTR,
6790 MAC2STR(mld_params->mld_addr));
6791
6792 if (nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
6793 mld_params->mld_addr) ||
6794 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
6795 mld_params->assoc_link_id))
6796 return -1;
6797
6798 links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
6799 if (!links)
6800 return -1;
6801
Sunil Ravi88611412024-06-28 17:34:56 +00006802 attr = nla_nest_start(msg, 0);
6803 if (!attr)
6804 return -1;
6805
6806 /* First add the association link ID */
6807 link_id = mld_params->assoc_link_id;
6808 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id) ||
6809 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
6810 mld_params->mld_links[link_id].bssid) ||
6811 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
6812 mld_params->mld_links[link_id].freq))
6813 return -1;
6814
6815 os_memcpy(drv->sta_mlo_info.links[link_id].bssid,
6816 mld_params->mld_links[link_id].bssid, ETH_ALEN);
6817
6818 nla_nest_end(msg, attr);
6819
6820 for (i = 1, link_id = 0; link_id < MAX_NUM_MLD_LINKS;
6821 link_id++) {
6822 if (!(mld_params->valid_links & BIT(link_id)) ||
6823 link_id == mld_params->assoc_link_id)
6824 continue;
6825
6826 attr = nla_nest_start(msg, i);
Sunil Ravi77d572f2023-01-17 23:58:31 +00006827 if (!attr)
6828 return -1;
6829
6830 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
6831 link_id) ||
6832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
6833 mld_params->mld_links[link_id].bssid) ||
6834 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
6835 mld_params->mld_links[link_id].freq) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006836 (mld_params->mld_links[i].disabled &&
6837 nla_put_flag(msg,
6838 NL80211_ATTR_MLO_LINK_DISABLED)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00006839 (mld_params->mld_links[link_id].ies &&
Sunil Ravi88611412024-06-28 17:34:56 +00006840 mld_params->mld_links[i].ies_len &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00006841 nla_put(msg, NL80211_ATTR_IE,
6842 mld_params->mld_links[link_id].ies_len,
6843 mld_params->mld_links[link_id].ies)))
6844 return -1;
6845
6846 os_memcpy(drv->sta_mlo_info.links[link_id].bssid,
6847 mld_params->mld_links[link_id].bssid,
6848 ETH_ALEN);
6849 nla_nest_end(msg, attr);
Sunil Ravi88611412024-06-28 17:34:56 +00006850 i++;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006851 }
6852
6853 nla_nest_end(msg, links);
6854
6855 os_memcpy(drv->sta_mlo_info.ap_mld_addr,
6856 params->mld_params.mld_addr, ETH_ALEN);
6857 drv->sta_mlo_info.assoc_link_id = mld_params->assoc_link_id;
6858 drv->sta_mlo_info.req_links = mld_params->valid_links;
6859 }
6860
Paul Stewart092955c2017-02-06 09:13:09 -08006861 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
6862 return -1;
6863
Sunil Ravi77d572f2023-01-17 23:58:31 +00006864 if (params->bssid && !params->mld_params.mld_addr) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006865 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
6866 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006867 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
6868 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006869 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006870
Dmitry Shmidt96be6222014-02-13 10:16:51 -08006871 if (params->bssid_hint) {
6872 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
6873 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006874 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
6875 params->bssid_hint))
6876 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08006877 }
6878
Sunil Ravi77d572f2023-01-17 23:58:31 +00006879 if (params->freq.freq && !params->mld_params.mld_addr) {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006880 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
6882 params->freq.freq))
6883 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07006884 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006885 } else
6886 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006887
Dmitry Shmidt96be6222014-02-13 10:16:51 -08006888 if (params->freq_hint) {
6889 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006890 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
6891 params->freq_hint))
6892 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08006893 }
6894
Hai Shalomc3565922019-10-28 11:58:20 -07006895 if (params->freq.edmg.channels && params->freq.edmg.bw_config) {
6896 wpa_printf(MSG_DEBUG,
6897 " * EDMG configuration: channels=0x%x bw_config=%d",
6898 params->freq.edmg.channels,
6899 params->freq.edmg.bw_config);
6900 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS,
6901 params->freq.edmg.channels) ||
6902 nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG,
6903 params->freq.edmg.bw_config))
6904 return -1;
6905 }
6906
Dmitry Shmidt04949592012-07-19 12:16:46 -07006907 if (params->bg_scan_period >= 0) {
6908 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
6909 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006910 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
6911 params->bg_scan_period))
6912 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006913 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006915 if (params->ssid) {
Hai Shalom74f70d42019-02-11 14:42:39 -08006916 wpa_printf(MSG_DEBUG, " * SSID=%s",
6917 wpa_ssid_txt(params->ssid, params->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006918 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
6919 params->ssid))
6920 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006921 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006922 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006923 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
6924 drv->ssid_len = params->ssid_len;
6925 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006926
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006927 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006928 if (params->wpa_ie &&
6929 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
6930 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006931
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006932 if (params->wpa_proto) {
6933 enum nl80211_wpa_versions ver = 0;
6934
6935 if (params->wpa_proto & WPA_PROTO_WPA)
6936 ver |= NL80211_WPA_VERSION_1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006937 if (params->wpa_proto & WPA_PROTO_RSN) {
6938#if !defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(CONFIG_DRIVER_NL80211_SYNA)
6939 /*
6940 * NL80211_ATTR_SAE_PASSWORD is related and was added
6941 * at the same time as NL80211_WPA_VERSION_3.
6942 */
6943 if (nl80211_attr_supported(drv,
6944 NL80211_ATTR_SAE_PASSWORD) &&
6945 wpa_key_mgmt_sae(params->key_mgmt_suite))
6946 ver |= NL80211_WPA_VERSION_3;
6947 else
6948#endif
6949 ver |= NL80211_WPA_VERSION_2;
6950 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006951
6952 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006953 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
6954 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006955 }
6956
6957 if (params->pairwise_suite != WPA_CIPHER_NONE) {
6958 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
6959 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006960 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
6961 cipher))
6962 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006963 }
6964
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08006965 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
6966 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
6967 /*
6968 * This is likely to work even though many drivers do not
6969 * advertise support for operations without GTK.
6970 */
6971 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
6972 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006973 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
6974 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006975 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
6976 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006977 }
6978
6979 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
6980 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
6981 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
6982 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07006983 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07006984 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
6985 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006986 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07006987 params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
Sunil Ravi89eba102022-09-13 21:04:37 -07006988 params->key_mgmt_suite == WPA_KEY_MGMT_SAE_EXT_KEY ||
Hai Shalom021b0b52019-04-10 11:17:58 -07006989 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE ||
Sunil Ravi89eba102022-09-13 21:04:37 -07006990 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE_EXT_KEY ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006991 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006992 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
Hai Shalom021b0b52019-04-10 11:17:58 -07006993 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006994 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 ||
6995 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 ||
6996 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07006997 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 ||
6998 params->key_mgmt_suite == WPA_KEY_MGMT_OWE ||
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006999 params->key_mgmt_suite == WPA_KEY_MGMT_DPP ||
7000 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) {
Sunil Ravi89eba102022-09-13 21:04:37 -07007001 u32 *mgmt;
7002 unsigned int akm_count = 1, i;
7003
7004 /*
7005 * Make sure the driver has capability to handle default AKM in
7006 * key_mgmt_suite plus allowed AKMs in allowed_key_mgmts.
7007 */
7008 if (drv->capa.max_num_akms <=
7009 num_bits_set(params->allowed_key_mgmts)) {
7010 wpa_printf(MSG_INFO,
7011 "nl80211: Not enough support for the allowed AKMs (max_num_akms=%u <= num_bits_set=%u)",
7012 drv->capa.max_num_akms,
7013 num_bits_set(params->allowed_key_mgmts));
7014 return -1;
7015 }
7016
7017 mgmt = os_malloc(sizeof(u32) * drv->capa.max_num_akms);
7018 if (!mgmt)
7019 return -1;
7020
7021 mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007022
7023 switch (params->key_mgmt_suite) {
7024 case WPA_KEY_MGMT_CCKM:
Sunil Ravi89eba102022-09-13 21:04:37 -07007025 mgmt[0] = RSN_AUTH_KEY_MGMT_CCKM;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007026 break;
7027 case WPA_KEY_MGMT_IEEE8021X:
Sunil Ravi89eba102022-09-13 21:04:37 -07007028 mgmt[0] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007029 break;
7030 case WPA_KEY_MGMT_FT_IEEE8021X:
Sunil Ravi89eba102022-09-13 21:04:37 -07007031 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007032 break;
7033 case WPA_KEY_MGMT_FT_PSK:
Sunil Ravi89eba102022-09-13 21:04:37 -07007034 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_PSK;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007035 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07007036 case WPA_KEY_MGMT_IEEE8021X_SHA256:
Sunil Ravi89eba102022-09-13 21:04:37 -07007037 mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07007038 break;
7039 case WPA_KEY_MGMT_PSK_SHA256:
Sunil Ravi89eba102022-09-13 21:04:37 -07007040 mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_SHA256;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07007041 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007042 case WPA_KEY_MGMT_OSEN:
Sunil Ravi89eba102022-09-13 21:04:37 -07007043 mgmt[0] = RSN_AUTH_KEY_MGMT_OSEN;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007044 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07007045 case WPA_KEY_MGMT_SAE:
Sunil Ravi89eba102022-09-13 21:04:37 -07007046 mgmt[0] = RSN_AUTH_KEY_MGMT_SAE;
7047 break;
7048 case WPA_KEY_MGMT_SAE_EXT_KEY:
7049 mgmt[0] = RSN_AUTH_KEY_MGMT_SAE_EXT_KEY;
Hai Shalom021b0b52019-04-10 11:17:58 -07007050 break;
7051 case WPA_KEY_MGMT_FT_SAE:
Sunil Ravi89eba102022-09-13 21:04:37 -07007052 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE;
7053 break;
7054 case WPA_KEY_MGMT_FT_SAE_EXT_KEY:
7055 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY;
Hai Shalom021b0b52019-04-10 11:17:58 -07007056 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007057 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
Sunil Ravi89eba102022-09-13 21:04:37 -07007058 mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007059 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08007060 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
Sunil Ravi89eba102022-09-13 21:04:37 -07007061 mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08007062 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07007063 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
Sunil Ravi89eba102022-09-13 21:04:37 -07007064 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384;
Hai Shalom021b0b52019-04-10 11:17:58 -07007065 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007066 case WPA_KEY_MGMT_FILS_SHA256:
Sunil Ravi89eba102022-09-13 21:04:37 -07007067 mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA256;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007068 break;
7069 case WPA_KEY_MGMT_FILS_SHA384:
Sunil Ravi89eba102022-09-13 21:04:37 -07007070 mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007071 break;
7072 case WPA_KEY_MGMT_FT_FILS_SHA256:
Sunil Ravi89eba102022-09-13 21:04:37 -07007073 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007074 break;
7075 case WPA_KEY_MGMT_FT_FILS_SHA384:
Sunil Ravi89eba102022-09-13 21:04:37 -07007076 mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007077 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007078 case WPA_KEY_MGMT_OWE:
Sunil Ravi89eba102022-09-13 21:04:37 -07007079 mgmt[0] = RSN_AUTH_KEY_MGMT_OWE;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007080 break;
7081 case WPA_KEY_MGMT_DPP:
Sunil Ravi89eba102022-09-13 21:04:37 -07007082 mgmt[0] = RSN_AUTH_KEY_MGMT_DPP;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007083 break;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007084 case WPA_KEY_MGMT_IEEE8021X_SHA384:
7085 mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA384;
7086 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007087 case WPA_KEY_MGMT_PSK:
7088 default:
Sunil Ravi89eba102022-09-13 21:04:37 -07007089 mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007090 break;
7091 }
Sunil Ravi89eba102022-09-13 21:04:37 -07007092
7093 if (drv->capa.max_num_akms > 1) {
7094 akm_count += wpa_key_mgmt_to_suites(
7095 params->allowed_key_mgmts, &mgmt[1],
7096 drv->capa.max_num_akms - 1);
7097 }
7098
7099 for (i = 0; i < akm_count; i++)
7100 wpa_printf(MSG_DEBUG, " * akm[%d]=0x%x", i, mgmt[i]);
7101
7102 if (nla_put(msg, NL80211_ATTR_AKM_SUITES,
7103 akm_count * sizeof(u32), mgmt)) {
7104 os_free(mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007105 return -1;
Sunil Ravi89eba102022-09-13 21:04:37 -07007106 }
7107
7108 os_free(mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007109 }
7110
Isaac Chiou6ce580d2024-04-24 17:07:24 +08007111#if (defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(WIFI_BRCM_OPEN_SOURCE_MULTI_AKM)) || \
7112 defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05307113 if (IS_CROSS_AKM_ROAM_KEY_MGMT(params->key_mgmt_suite)) {
7114 int num_suites;
7115 u32 suites[NL80211_MAX_NR_AKM_SUITES];
7116
7117 wpa_printf(MSG_INFO, "nl80211: key_mgmt_suites=0x%x",
7118 params->key_mgmt_suite);
7119 num_suites = wpa_cross_akm_key_mgmt_to_suites(params->key_mgmt_suite,
7120 suites, ARRAY_SIZE(suites));
7121 if (num_suites &&
7122 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), suites)) {
7123 wpa_printf(MSG_ERROR, "Updating multi akm_suite failed");
7124 return -1;
7125 }
7126 }
Isaac Chiou6ce580d2024-04-24 17:07:24 +08007127#endif /* (CONFIG_DRIVER_NL80211_BRCM && !WIFI_BRCM_OPEN_SOURCE_MULTI_AKM) ||
7128 * CONFIG_DRIVER_NL80211_SYNA */
Hai Shalomc3565922019-10-28 11:58:20 -07007129 if (params->req_handshake_offload &&
Hai Shalom74f70d42019-02-11 14:42:39 -08007130 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) {
7131 wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS");
7132 if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS))
7133 return -1;
7134 }
7135
Roshan Pius3a1667e2018-07-03 15:17:14 -07007136 /* Add PSK in case of 4-way handshake offload */
7137 if (params->psk &&
Hai Shalom74f70d42019-02-11 14:42:39 -08007138 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07007139 wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32);
7140 if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk))
7141 return -1;
7142 }
7143
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007144 if (nl80211_put_control_port(drv, msg))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007145 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007146
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07007147 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
7148 (params->pairwise_suite == WPA_CIPHER_NONE ||
7149 params->pairwise_suite == WPA_CIPHER_WEP104 ||
7150 params->pairwise_suite == WPA_CIPHER_WEP40) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007151 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07007152 return -1;
7153
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007154 if (params->rrm_used) {
7155 u32 drv_rrm_flags = drv->capa.rrm_flags;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007156 if ((!((drv_rrm_flags &
7157 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) &&
7158 (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) &&
7159 !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007160 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
7161 return -1;
7162 }
7163
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007164 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007165 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007166
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007167 if (params->p2p)
7168 wpa_printf(MSG_DEBUG, " * P2P group");
7169
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007170 if (params->pbss) {
7171 wpa_printf(MSG_DEBUG, " * PBSS");
7172 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
7173 return -1;
7174 }
7175
Dmitry Shmidte4663042016-04-04 10:07:49 -07007176 drv->connect_reassoc = 0;
7177 if (params->prev_bssid) {
7178 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
7179 MAC2STR(params->prev_bssid));
7180 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
7181 params->prev_bssid))
7182 return -1;
7183 drv->connect_reassoc = 1;
7184 }
7185
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007186 if ((params->auth_alg & WPA_AUTH_ALG_FILS) &&
7187 nl80211_put_fils_connect_params(drv, params, msg) != 0)
7188 return -1;
7189
Sunil Ravi89eba102022-09-13 21:04:37 -07007190 if ((wpa_key_mgmt_sae(params->key_mgmt_suite) ||
7191 wpa_key_mgmt_sae(params->allowed_key_mgmts)) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07007192 (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) &&
7193 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
7194 return -1;
7195
Sunil Ravi036cec52023-03-29 11:35:17 -07007196 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME) &&
7197 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT))
7198 return -1;
7199
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007200 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007201}
7202
7203
7204static int wpa_driver_nl80211_try_connect(
7205 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007206 struct wpa_driver_associate_params *params,
Hai Shalomc1a21442022-02-04 13:43:00 -08007207 struct i802_bss *bss)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007208{
7209 struct nl_msg *msg;
7210 enum nl80211_auth_type type;
7211 int ret;
7212 int algs;
7213
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007214#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007215 if (params->req_key_mgmt_offload && params->psk &&
Sunil Ravi89eba102022-09-13 21:04:37 -07007216 (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suite) ||
7217 wpa_key_mgmt_wpa_psk_no_sae(params->allowed_key_mgmts))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007218 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
7219 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
7220 if (ret)
7221 return ret;
7222 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007223#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007224
7225 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
7226 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007227 if (!msg)
7228 return -1;
7229
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007230 ret = nl80211_connect_common(drv, params, msg);
7231 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007232 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007233
Roshan Pius3a1667e2018-07-03 15:17:14 -07007234 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
7235 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
7236 goto fail;
7237
7238 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL &&
7239 (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) &&
7240 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL))
7241 goto fail;
7242
Hai Shalom60840252021-02-19 19:02:11 -08007243#ifdef CONFIG_SAE
Sunil Ravi89eba102022-09-13 21:04:37 -07007244 if ((wpa_key_mgmt_sae(params->key_mgmt_suite) ||
7245 wpa_key_mgmt_sae(params->allowed_key_mgmts)) &&
Hai Shalom60840252021-02-19 19:02:11 -08007246 nl80211_put_sae_pwe(msg, params->sae_pwe) < 0)
7247 goto fail;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007248
7249 /* Add SAE password in case of SAE authentication offload */
7250 if ((params->sae_password || params->passphrase) &&
7251 (drv->capa.flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA)) {
7252 const char *password;
7253 size_t pwd_len;
7254
7255 if (params->sae_password && params->sae_password_id) {
7256 wpa_printf(MSG_INFO,
7257 "nl80211: Use of SAE password identifiers not supported with driver-based SAE");
7258 goto fail;
7259 }
7260
7261 password = params->sae_password;
7262 if (!password)
7263 password = params->passphrase;
7264 pwd_len = os_strlen(password);
7265 wpa_printf(MSG_DEBUG, " * SAE password");
7266 if (nla_put(msg, NL80211_ATTR_SAE_PASSWORD, pwd_len, password))
7267 goto fail;
7268 }
Hai Shalom60840252021-02-19 19:02:11 -08007269#endif /* CONFIG_SAE */
7270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007271 algs = 0;
7272 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
7273 algs++;
7274 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
7275 algs++;
7276 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
7277 algs++;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007278 if (params->auth_alg & WPA_AUTH_ALG_FILS)
7279 algs++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007280 if (params->auth_alg & WPA_AUTH_ALG_FT)
7281 algs++;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007282 if (params->auth_alg & WPA_AUTH_ALG_SAE)
7283 algs++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007284 if (algs > 1) {
7285 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
7286 "selection");
7287 goto skip_auth_type;
7288 }
7289
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007290 type = get_nl_auth_type(params->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007291 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007292 if (type == NL80211_AUTHTYPE_MAX ||
7293 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007294 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007295
7296skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007297 ret = nl80211_set_conn_keys(params, msg);
7298 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007299 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007300
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007301 if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
7302 goto fail;
7303 ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL,
7304 NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007305 msg = NULL;
7306 if (ret) {
7307 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
7308 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007309 } else {
Hai Shalom60840252021-02-19 19:02:11 -08007310#ifdef CONFIG_DRIVER_NL80211_QCA
7311 drv->roam_indication_done = false;
7312#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007313 wpa_printf(MSG_DEBUG,
7314 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007315 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007316
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007317fail:
Hai Shalom74f70d42019-02-11 14:42:39 -08007318 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007319 nlmsg_free(msg);
7320 return ret;
7321
7322}
7323
7324
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007325static int wpa_driver_nl80211_connect(
7326 struct wpa_driver_nl80211_data *drv,
Roshan Pius3a1667e2018-07-03 15:17:14 -07007327 struct wpa_driver_associate_params *params,
Hai Shalomc1a21442022-02-04 13:43:00 -08007328 struct i802_bss *bss)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007329{
Jithu Jancea7c60b42014-12-03 18:54:40 +05307330 int ret;
7331
7332 /* Store the connection attempted bssid for future use */
7333 if (params->bssid)
7334 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
7335 else
7336 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
7337
Hai Shalomc1a21442022-02-04 13:43:00 -08007338 ret = wpa_driver_nl80211_try_connect(drv, params, bss);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007339 if (ret == -EALREADY) {
7340 /*
7341 * cfg80211 does not currently accept new connections if
7342 * we are already connected. As a workaround, force
7343 * disconnection and try again.
7344 */
7345 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
7346 "disconnecting before reassociation "
7347 "attempt");
7348 if (wpa_driver_nl80211_disconnect(
Hai Shalomc1a21442022-02-04 13:43:00 -08007349 drv, WLAN_REASON_PREV_AUTH_NOT_VALID, bss))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007350 return -1;
Hai Shalomc1a21442022-02-04 13:43:00 -08007351 ret = wpa_driver_nl80211_try_connect(drv, params, bss);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007352 }
7353 return ret;
7354}
7355
7356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007357static int wpa_driver_nl80211_associate(
7358 void *priv, struct wpa_driver_associate_params *params)
7359{
7360 struct i802_bss *bss = priv;
7361 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007362 struct nl80211_err_info err_info;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007363 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007364 struct nl_msg *msg;
7365
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007366 nl80211_unmask_11b_rates(bss);
7367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007368 if (params->mode == IEEE80211_MODE_AP)
7369 return wpa_driver_nl80211_ap(drv, params);
7370
7371 if (params->mode == IEEE80211_MODE_IBSS)
7372 return wpa_driver_nl80211_ibss(drv, params);
7373
7374 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007375 enum nl80211_iftype nlmode = params->p2p ?
7376 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
7377
7378 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007379 return -1;
Hai Shalom74f70d42019-02-11 14:42:39 -08007380
Hai Shalomc1a21442022-02-04 13:43:00 -08007381 return wpa_driver_nl80211_connect(drv, params, bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007382 }
7383
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007384 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007385
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007386 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
7387 drv->ifindex);
7388 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007389 if (!msg)
7390 return -1;
7391
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007392 ret = nl80211_connect_common(drv, params, msg);
7393 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007394 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007395
Roshan Pius3a1667e2018-07-03 15:17:14 -07007396 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
7397 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
7398 goto fail;
7399
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007400 if (params->fils_kek) {
7401 wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)",
7402 (unsigned int) params->fils_kek_len);
7403 if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len,
7404 params->fils_kek))
7405 goto fail;
7406 }
7407 if (params->fils_nonces) {
7408 wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)",
7409 params->fils_nonces,
7410 params->fils_nonces_len);
7411 if (nla_put(msg, NL80211_ATTR_FILS_NONCES,
7412 params->fils_nonces_len, params->fils_nonces))
7413 goto fail;
7414 }
7415
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007416 if (!TEST_FAIL_TAG("assoc")) {
7417 if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
7418 goto fail;
7419 ret = send_and_recv(drv->global, drv->first_bss->nl_connect,
7420 msg, NULL, NULL, NULL, NULL, &err_info);
7421 msg = NULL;
7422 } else {
7423 int i;
7424
7425 /* Error and force TEST_FAIL checking for each link */
7426 ret = -EINVAL;
7427 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
7428 if (!(params->mld_params.valid_links & BIT(i)))
7429 continue;
7430
7431 if (TEST_FAIL_TAG("link"))
7432 err_info.link_id = i;
7433 }
7434 }
7435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007436 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007437 wpa_dbg(drv->ctx, MSG_DEBUG,
7438 "nl80211: MLME command failed (assoc): ret=%d (%s)",
7439 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007440 nl80211_dump_scan(drv);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007441
7442 /* Mark failed link within params */
7443 if (err_info.link_id >= 0) {
7444 if (err_info.link_id >= MAX_NUM_MLD_LINKS ||
7445 !(params->mld_params.valid_links &
7446 BIT(err_info.link_id))) {
7447 wpa_printf(MSG_DEBUG,
7448 "nl80211: Invalid errorred link_id %d",
7449 err_info.link_id);
7450 goto fail;
7451 }
7452 params->mld_params.mld_links[err_info.link_id].error =
7453 ret;
7454 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007455 } else {
7456 wpa_printf(MSG_DEBUG,
7457 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007458 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007459
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007460fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007461 nlmsg_free(msg);
7462 return ret;
7463}
7464
7465
7466static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007467 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007468{
7469 struct nl_msg *msg;
7470 int ret = -ENOBUFS;
7471
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007472 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
7473 ifindex, mode, nl80211_iftype_str(mode));
7474
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007475 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
7476 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
7477 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007478
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007479 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007480 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007481 if (!ret)
7482 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007483fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007484 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007485 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
7486 " %d (%s)", ifindex, mode, ret, strerror(-ret));
7487 return ret;
7488}
7489
7490
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007491static int wpa_driver_nl80211_set_mode_impl(
7492 struct i802_bss *bss,
7493 enum nl80211_iftype nlmode,
7494 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007495{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007496 struct wpa_driver_nl80211_data *drv = bss->drv;
7497 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007498 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007499 int was_ap = is_ap_interface(drv->nlmode);
7500 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007501 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007502
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07007503 if (TEST_FAIL())
7504 return -1;
7505
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007506 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
7507 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
7508 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007509
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007510 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007511 drv->nlmode = nlmode;
7512 ret = 0;
7513 goto done;
7514 }
7515
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007516 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007517 return -1;
7518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007519 if (nlmode == drv->nlmode) {
7520 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
7521 "requested mode - ignore error");
7522 ret = 0;
7523 goto done; /* Already in the requested mode */
7524 }
7525
7526 /* mac80211 doesn't allow mode changes while the device is up, so
7527 * take the device down, try to set the mode again, and bring the
7528 * device back up.
7529 */
7530 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
7531 "interface down");
7532 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007533 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007534 if (res == -EACCES || res == -ENODEV)
7535 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007536 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007537 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
7538 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007539 os_sleep(0, 100000);
7540 continue;
7541 }
7542
7543 /*
7544 * Setting the mode will fail for some drivers if the phy is
7545 * on a frequency that the mode is disallowed in.
7546 */
7547 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007548 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007549 if (res) {
7550 wpa_printf(MSG_DEBUG,
7551 "nl80211: Failed to set frequency on interface");
7552 }
7553 }
7554
Hai Shalom4fbc08f2020-05-18 12:37:00 -07007555 if (i == 0 && was_ap && !is_ap_interface(nlmode) &&
7556 bss->brname[0] &&
7557 (bss->added_if_into_bridge || bss->already_in_bridge)) {
7558 wpa_printf(MSG_DEBUG,
7559 "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION",
7560 bss->ifname, bss->brname);
7561 if (linux_br_del_if(drv->global->ioctl_sock,
7562 bss->brname, bss->ifname) < 0)
7563 wpa_printf(MSG_INFO,
7564 "nl80211: Failed to remove interface %s from bridge %s: %s",
7565 bss->ifname, bss->brname,
7566 strerror(errno));
7567 }
7568
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007569 /* Try to set the mode again while the interface is down */
7570 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
7571 if (mode_switch_res == -EBUSY) {
7572 wpa_printf(MSG_DEBUG,
7573 "nl80211: Delaying mode set while interface going down");
7574 os_sleep(0, 100000);
7575 continue;
7576 }
7577 ret = mode_switch_res;
7578 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007579 }
7580
7581 if (!ret) {
7582 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
7583 "interface is down");
7584 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007585 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007586 }
7587
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007588 /* Bring the interface back up */
7589 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
7590 if (res != 0) {
7591 wpa_printf(MSG_DEBUG,
7592 "nl80211: Failed to set interface up after switching mode");
7593 ret = -1;
7594 }
7595
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007596done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007597 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007598 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
7599 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007600 return ret;
7601 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007602
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007603 if (is_p2p_net_interface(nlmode)) {
7604 wpa_printf(MSG_DEBUG,
7605 "nl80211: Interface %s mode change to P2P - disable 11b rates",
7606 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007607 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007608 } else if (drv->disabled_11b_rates) {
7609 wpa_printf(MSG_DEBUG,
7610 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
7611 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007612 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007613 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007614
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007615 if (is_ap_interface(nlmode)) {
7616 nl80211_mgmt_unsubscribe(bss, "start AP");
7617 /* Setup additional AP mode functionality if needed */
7618 if (nl80211_setup_ap(bss))
7619 return -1;
7620 } else if (was_ap) {
7621 /* Remove additional AP mode functionality */
7622 nl80211_teardown_ap(bss);
7623 } else {
7624 nl80211_mgmt_unsubscribe(bss, "mode change");
7625 }
7626
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007627 if (is_mesh_interface(nlmode) &&
7628 nl80211_mgmt_subscribe_mesh(bss))
7629 return -1;
7630
Dmitry Shmidt04949592012-07-19 12:16:46 -07007631 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007632 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007633 nl80211_mgmt_subscribe_non_ap(bss) < 0)
7634 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
7635 "frame processing - ignore for now");
7636
7637 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007638}
7639
7640
Hai Shalom4fbc08f2020-05-18 12:37:00 -07007641void nl80211_restore_ap_mode(struct i802_bss *bss)
7642{
7643 struct wpa_driver_nl80211_data *drv = bss->drv;
7644 int was_ap = is_ap_interface(drv->nlmode);
leslc3979c32021-03-29 22:34:02 +08007645 int br_ifindex;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07007646
7647 wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station);
7648 if (!was_ap && is_ap_interface(drv->ap_scan_as_station) &&
7649 bss->brname[0] &&
7650 (bss->added_if_into_bridge || bss->already_in_bridge)) {
7651 wpa_printf(MSG_DEBUG,
7652 "nl80211: Add AP interface %s back into the bridge %s",
7653 bss->ifname, bss->brname);
7654 if (linux_br_add_if(drv->global->ioctl_sock, bss->brname,
7655 bss->ifname) < 0) {
7656 wpa_printf(MSG_WARNING,
7657 "nl80211: Failed to add interface %s into bridge %s: %s",
7658 bss->ifname, bss->brname, strerror(errno));
7659 }
leslc3979c32021-03-29 22:34:02 +08007660 br_ifindex = if_nametoindex(bss->brname);
7661 add_ifidx(drv, br_ifindex, drv->ifindex);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07007662 }
7663 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
7664}
7665
7666
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007667int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
7668 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007669{
7670 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
7671}
7672
7673
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007674static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
7675 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007676{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007677 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007678 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07007679}
7680
7681
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007682static int wpa_driver_nl80211_get_capa(void *priv,
7683 struct wpa_driver_capa *capa)
7684{
7685 struct i802_bss *bss = priv;
7686 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07007687
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007688 if (!drv->has_capability)
7689 return -1;
7690 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007691 if (drv->extended_capa && drv->extended_capa_mask) {
7692 capa->extended_capa = drv->extended_capa;
7693 capa->extended_capa_mask = drv->extended_capa_mask;
7694 capa->extended_capa_len = drv->extended_capa_len;
7695 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007696
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007697 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007698}
7699
7700
7701static int wpa_driver_nl80211_set_operstate(void *priv, int state)
7702{
7703 struct i802_bss *bss = priv;
7704 struct wpa_driver_nl80211_data *drv = bss->drv;
7705
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007706 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
7707 bss->ifname, drv->operstate, state,
7708 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007709 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007710 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007711 state ? IF_OPER_UP : IF_OPER_DORMANT);
7712}
7713
7714
7715static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
7716{
7717 struct i802_bss *bss = priv;
7718 struct wpa_driver_nl80211_data *drv = bss->drv;
7719 struct nl_msg *msg;
7720 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007721 int ret;
Sunil Ravi89eba102022-09-13 21:04:37 -07007722 const u8 *connected_addr = drv->sta_mlo_info.valid_links ?
7723 drv->sta_mlo_info.ap_mld_addr : drv->bssid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007724
Sunil Ravi89eba102022-09-13 21:04:37 -07007725 if (!drv->associated && is_zero_ether_addr(connected_addr) &&
7726 !authorized) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007727 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
7728 return 0;
7729 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007730
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007731 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
Sunil Ravi89eba102022-09-13 21:04:37 -07007732 MACSTR, authorized ? "" : "un", MAC2STR(connected_addr));
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007733
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007734 os_memset(&upd, 0, sizeof(upd));
7735 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
7736 if (authorized)
7737 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007738
7739 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
Sunil Ravi89eba102022-09-13 21:04:37 -07007740 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007741 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
7742 nlmsg_free(msg);
7743 return -ENOBUFS;
7744 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007745
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007746 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007747 if (!ret)
7748 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007749 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
7750 ret, strerror(-ret));
7751 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007752}
7753
7754
Jouni Malinen75ecf522011-06-27 15:19:46 -07007755/* Set kernel driver on given frequency (MHz) */
7756static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007757{
Jouni Malinen75ecf522011-06-27 15:19:46 -07007758 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07007759 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007760}
7761
7762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007763static inline int min_int(int a, int b)
7764{
7765 if (a < b)
7766 return a;
7767 return b;
7768}
7769
7770
7771static int get_key_handler(struct nl_msg *msg, void *arg)
7772{
7773 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7774 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7775
7776 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7777 genlmsg_attrlen(gnlh, 0), NULL);
7778
7779 /*
7780 * TODO: validate the key index and mac address!
7781 * Otherwise, there's a race condition as soon as
7782 * the kernel starts sending key notifications.
7783 */
7784
7785 if (tb[NL80211_ATTR_KEY_SEQ])
7786 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
7787 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
Hai Shalom021b0b52019-04-10 11:17:58 -07007788 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007789 return NL_SKIP;
7790}
7791
7792
7793static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007794 int idx, int link_id, u8 *seq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007795{
7796 struct i802_bss *bss = priv;
7797 struct wpa_driver_nl80211_data *drv = bss->drv;
7798 struct nl_msg *msg;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007799 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007800
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007801 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
7802 NL80211_CMD_GET_KEY);
7803 if (!msg ||
7804 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007805 (link_id != NL80211_DRV_LINK_ID_NA &&
7806 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007807 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
7808 nlmsg_free(msg);
7809 return -ENOBUFS;
7810 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007811
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007812 os_memset(seq, 0, 6);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007813 res = send_and_recv_resp(drv, msg, get_key_handler, seq);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007814 if (res) {
7815 wpa_printf(MSG_DEBUG,
7816 "nl80211: Failed to get current TX sequence for a key (link_id=%d idx=%d): %d (%s)",
7817 link_id, idx, res, strerror(-res));
7818 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007819
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007820 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007821}
7822
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007823
7824static int i802_set_rts(void *priv, int rts)
7825{
7826 struct i802_bss *bss = priv;
7827 struct wpa_driver_nl80211_data *drv = bss->drv;
7828 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007829 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007830 u32 val;
7831
Hai Shalom021b0b52019-04-10 11:17:58 -07007832 if (rts >= 2347 || rts == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007833 val = (u32) -1;
7834 else
7835 val = rts;
7836
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007837 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
7838 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
7839 nlmsg_free(msg);
7840 return -ENOBUFS;
7841 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007842
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007843 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007844 if (!ret)
7845 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007846 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
7847 "%d (%s)", rts, ret, strerror(-ret));
7848 return ret;
7849}
7850
7851
7852static int i802_set_frag(void *priv, int frag)
7853{
7854 struct i802_bss *bss = priv;
7855 struct wpa_driver_nl80211_data *drv = bss->drv;
7856 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007857 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007858 u32 val;
7859
Hai Shalom021b0b52019-04-10 11:17:58 -07007860 if (frag >= 2346 || frag == -1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007861 val = (u32) -1;
7862 else
7863 val = frag;
7864
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007865 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
7866 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
7867 nlmsg_free(msg);
7868 return -ENOBUFS;
7869 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007870
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007871 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007872 if (!ret)
7873 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007874 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
7875 "%d: %d (%s)", frag, ret, strerror(-ret));
7876 return ret;
7877}
7878
7879
7880static int i802_flush(void *priv)
7881{
7882 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007883 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007884 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007885
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007886 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
7887 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007888
7889 /*
7890 * XXX: FIX! this needs to flush all VLANs too
7891 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007892 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007893 res = send_and_recv_cmd(bss->drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007894 if (res) {
7895 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
7896 "(%s)", res, strerror(-res));
7897 }
7898 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007899}
7900
7901
Hai Shalom81f62d82019-07-22 12:10:00 -07007902static void get_sta_tid_stats(struct hostap_sta_driver_data *data,
7903 struct nlattr *attr)
7904{
7905 struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr;
7906 struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1];
7907 static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = {
7908 [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 },
7909 [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 },
7910 };
7911 int rem;
7912
7913 nla_for_each_nested(tidattr, attr, rem) {
7914 if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX,
7915 tidattr, NULL) != 0 ||
7916 !tid_stats[NL80211_TID_STATS_TXQ_STATS] ||
7917 nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX,
7918 tid_stats[NL80211_TID_STATS_TXQ_STATS],
7919 txq_stats_policy) != 0)
7920 continue;
7921 /* sum the backlogs over all TIDs for station */
7922 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES])
7923 data->backlog_bytes += nla_get_u32(
7924 txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]);
7925 if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS])
7926 data->backlog_bytes += nla_get_u32(
7927 txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]);
7928 }
7929}
7930
7931
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007932static int get_sta_handler(struct nl_msg *msg, void *arg)
7933{
7934 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7935 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7936 struct hostap_sta_driver_data *data = arg;
7937 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
7938 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
7939 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
7940 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
7941 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007942 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007943 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
7944 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007945 [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007946 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007947 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
7948 [NL80211_STA_INFO_CONNECTED_TIME] = { .type = NLA_U32 },
7949 [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32 },
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007950 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
7951 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007952 [NL80211_STA_INFO_EXPECTED_THROUGHPUT] = { .type = NLA_U32 },
7953 [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64 },
7954 [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64 },
7955 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8},
Hai Shalom81f62d82019-07-22 12:10:00 -07007956 [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007957 [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 },
7958 [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_S8 },
7959 [NL80211_STA_INFO_RX_MPDUS] = { .type = NLA_U32 },
7960 [NL80211_STA_INFO_FCS_ERROR_COUNT] = { .type = NLA_U32 },
Hai Shalom81f62d82019-07-22 12:10:00 -07007961 [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 },
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007962 };
7963 struct nlattr *rate[NL80211_RATE_INFO_MAX + 1];
7964 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
7965 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
7966 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
7967 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
7968 [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 },
7969 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
7970 [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 },
Sunil Ravi77d572f2023-01-17 23:58:31 +00007971 [NL80211_RATE_INFO_HE_MCS] = { .type = NLA_U8 },
7972 [NL80211_RATE_INFO_HE_NSS] = { .type = NLA_U8 },
Sunil Ravi036cec52023-03-29 11:35:17 -07007973 [NL80211_RATE_INFO_HE_GI] = { .type = NLA_U8 },
7974 [NL80211_RATE_INFO_HE_DCM] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007975 };
7976
7977 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7978 genlmsg_attrlen(gnlh, 0), NULL);
7979
7980 /*
7981 * TODO: validate the interface and mac address!
7982 * Otherwise, there's a race condition as soon as
7983 * the kernel starts sending station notifications.
7984 */
7985
7986 if (!tb[NL80211_ATTR_STA_INFO]) {
7987 wpa_printf(MSG_DEBUG, "sta stats missing!");
7988 return NL_SKIP;
7989 }
7990 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
7991 tb[NL80211_ATTR_STA_INFO],
7992 stats_policy)) {
7993 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
7994 return NL_SKIP;
7995 }
7996
7997 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
7998 data->inactive_msec =
7999 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008000 /* For backwards compatibility, fetch the 32-bit counters first. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008001 if (stats[NL80211_STA_INFO_RX_BYTES])
8002 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
8003 if (stats[NL80211_STA_INFO_TX_BYTES])
8004 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008005 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
8006 stats[NL80211_STA_INFO_TX_BYTES64]) {
8007 /*
8008 * The driver supports 64-bit counters, so use them to override
8009 * the 32-bit values.
8010 */
8011 data->rx_bytes =
8012 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
8013 data->tx_bytes =
8014 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
8015 data->bytes_64bit = 1;
8016 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00008017 if (stats[NL80211_STA_INFO_SIGNAL])
8018 data->signal = (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008019 if (stats[NL80211_STA_INFO_RX_PACKETS])
8020 data->rx_packets =
8021 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
8022 if (stats[NL80211_STA_INFO_TX_PACKETS])
8023 data->tx_packets =
8024 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Sunil Ravi77d572f2023-01-17 23:58:31 +00008025 if (stats[NL80211_STA_INFO_TX_RETRIES])
8026 data->tx_retry_count =
8027 nla_get_u32(stats[NL80211_STA_INFO_TX_RETRIES]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008028 if (stats[NL80211_STA_INFO_TX_FAILED])
8029 data->tx_retry_failed =
8030 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Sunil Ravi77d572f2023-01-17 23:58:31 +00008031 if (stats[NL80211_STA_INFO_SIGNAL_AVG])
8032 data->avg_signal =
8033 (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL_AVG]);
Hai Shalomc1a21442022-02-04 13:43:00 -08008034 if (stats[NL80211_STA_INFO_CONNECTED_TIME]) {
8035 data->connected_sec =
8036 nla_get_u32(stats[NL80211_STA_INFO_CONNECTED_TIME]);
8037 data->flags |= STA_DRV_DATA_CONN_TIME;
8038 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00008039 if (stats[NL80211_STA_INFO_BEACON_LOSS])
8040 data->beacon_loss_count =
8041 nla_get_u32(stats[NL80211_STA_INFO_BEACON_LOSS]);
8042 if (stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT])
8043 data->expected_throughput =
8044 nla_get_u32(stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT]);
8045 if (stats[NL80211_STA_INFO_RX_DROP_MISC])
8046 data->rx_drop_misc =
8047 nla_get_u64(stats[NL80211_STA_INFO_RX_DROP_MISC]);
8048 if (stats[NL80211_STA_INFO_BEACON_RX])
8049 data->beacons_count =
8050 nla_get_u64(stats[NL80211_STA_INFO_BEACON_RX]);
8051 if (stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
8052 data->avg_beacon_signal =
8053 (s8) nla_get_u8(stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
8054 if (stats[NL80211_STA_INFO_RX_DURATION])
8055 data->rx_airtime =
8056 nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]);
8057 if (stats[NL80211_STA_INFO_ACK_SIGNAL]) {
8058 data->last_ack_rssi =
8059 nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]);
8060 data->flags |= STA_DRV_DATA_LAST_ACK_RSSI;
8061 }
8062 if (stats[NL80211_STA_INFO_ACK_SIGNAL_AVG])
8063 data->avg_ack_signal =
8064 nla_get_s8(stats[NL80211_STA_INFO_ACK_SIGNAL_AVG]);
8065 if (stats[NL80211_STA_INFO_RX_MPDUS])
8066 data->rx_mpdus = nla_get_u32(stats[NL80211_STA_INFO_RX_MPDUS]);
8067 if (stats[NL80211_STA_INFO_FCS_ERROR_COUNT])
8068 data->fcs_error_count =
8069 nla_get_u32(stats[NL80211_STA_INFO_FCS_ERROR_COUNT]);
8070 if (stats[NL80211_STA_INFO_TX_DURATION])
8071 data->tx_airtime =
8072 nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]);
Hai Shalomc1a21442022-02-04 13:43:00 -08008073
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008074 if (stats[NL80211_STA_INFO_TX_BITRATE] &&
8075 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
8076 stats[NL80211_STA_INFO_TX_BITRATE],
8077 rate_policy) == 0) {
8078 if (rate[NL80211_RATE_INFO_BITRATE32])
8079 data->current_tx_rate =
8080 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
8081 else if (rate[NL80211_RATE_INFO_BITRATE])
8082 data->current_tx_rate =
8083 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
8084
Sunil Ravi77d572f2023-01-17 23:58:31 +00008085 /* Convert from 100 kbps to kbps; it's a more convenient unit.
8086 * It's also safe up until ~1Tbps. */
8087 data->current_tx_rate = data->current_tx_rate * 100;
8088
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008089 if (rate[NL80211_RATE_INFO_MCS]) {
8090 data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
8091 data->flags |= STA_DRV_DATA_TX_MCS;
8092 }
8093 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
8094 data->tx_vhtmcs =
8095 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
8096 data->flags |= STA_DRV_DATA_TX_VHT_MCS;
8097 }
Sunil Ravi036cec52023-03-29 11:35:17 -07008098 if (rate[NL80211_RATE_INFO_SHORT_GI]) {
8099 data->tx_guard_interval = GUARD_INTERVAL_0_4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008100 data->flags |= STA_DRV_DATA_TX_SHORT_GI;
Sunil Ravi036cec52023-03-29 11:35:17 -07008101 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008102 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
8103 data->tx_vht_nss =
8104 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
8105 data->flags |= STA_DRV_DATA_TX_VHT_NSS;
8106 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00008107 if (rate[NL80211_RATE_INFO_HE_MCS]) {
8108 data->tx_hemcs =
8109 nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]);
8110 data->flags |= STA_DRV_DATA_TX_HE_MCS;
8111 }
8112 if (rate[NL80211_RATE_INFO_HE_NSS]) {
8113 data->tx_he_nss =
8114 nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]);
8115 data->flags |= STA_DRV_DATA_TX_HE_NSS;
8116 }
Sunil Ravi036cec52023-03-29 11:35:17 -07008117 if (rate[NL80211_RATE_INFO_HE_GI]) {
8118 switch (nla_get_u8(rate[NL80211_RATE_INFO_HE_GI])) {
8119 case NL80211_RATE_INFO_HE_GI_0_8:
8120 data->tx_guard_interval = GUARD_INTERVAL_0_8;
8121 break;
8122 case NL80211_RATE_INFO_HE_GI_1_6:
8123 data->tx_guard_interval = GUARD_INTERVAL_1_6;
8124 break;
8125 case NL80211_RATE_INFO_HE_GI_3_2:
8126 data->tx_guard_interval = GUARD_INTERVAL_3_2;
8127 break;
8128 }
8129 data->flags |= STA_DRV_DATA_TX_HE_GI;
8130 }
8131 if (rate[NL80211_RATE_INFO_HE_DCM]) {
8132 data->tx_dcm =
8133 nla_get_u8(rate[NL80211_RATE_INFO_HE_DCM]);
8134 data->flags |= STA_DRV_DATA_TX_HE_DCM;
8135 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008136 }
8137
8138 if (stats[NL80211_STA_INFO_RX_BITRATE] &&
8139 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
8140 stats[NL80211_STA_INFO_RX_BITRATE],
8141 rate_policy) == 0) {
8142 if (rate[NL80211_RATE_INFO_BITRATE32])
8143 data->current_rx_rate =
8144 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
8145 else if (rate[NL80211_RATE_INFO_BITRATE])
8146 data->current_rx_rate =
8147 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
8148
Sunil Ravi77d572f2023-01-17 23:58:31 +00008149 /* Convert from 100 kbps to kbps; it's a more convenient unit.
8150 * It's also safe up until ~1Tbps. */
8151 data->current_rx_rate = data->current_rx_rate * 100;
8152
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008153 if (rate[NL80211_RATE_INFO_MCS]) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00008154 data->rx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008155 data->flags |= STA_DRV_DATA_RX_MCS;
8156 }
8157 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
8158 data->rx_vhtmcs =
8159 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
8160 data->flags |= STA_DRV_DATA_RX_VHT_MCS;
8161 }
Sunil Ravi036cec52023-03-29 11:35:17 -07008162 if (rate[NL80211_RATE_INFO_SHORT_GI]) {
8163 data->rx_guard_interval = GUARD_INTERVAL_0_4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008164 data->flags |= STA_DRV_DATA_RX_SHORT_GI;
Sunil Ravi036cec52023-03-29 11:35:17 -07008165 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008166 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
8167 data->rx_vht_nss =
8168 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
8169 data->flags |= STA_DRV_DATA_RX_VHT_NSS;
8170 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00008171 if (rate[NL80211_RATE_INFO_HE_MCS]) {
8172 data->rx_hemcs =
8173 nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]);
8174 data->flags |= STA_DRV_DATA_RX_HE_MCS;
8175 }
8176 if (rate[NL80211_RATE_INFO_HE_NSS]) {
8177 data->rx_he_nss =
8178 nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]);
8179 data->flags |= STA_DRV_DATA_RX_HE_NSS;
8180 }
Sunil Ravi036cec52023-03-29 11:35:17 -07008181 if (rate[NL80211_RATE_INFO_HE_GI]) {
8182 switch (nla_get_u8(rate[NL80211_RATE_INFO_HE_GI])) {
8183 case NL80211_RATE_INFO_HE_GI_0_8:
8184 data->rx_guard_interval = GUARD_INTERVAL_0_8;
8185 break;
8186 case NL80211_RATE_INFO_HE_GI_1_6:
8187 data->rx_guard_interval = GUARD_INTERVAL_1_6;
8188 break;
8189 case NL80211_RATE_INFO_HE_GI_3_2:
8190 data->rx_guard_interval = GUARD_INTERVAL_3_2;
8191 break;
8192 }
8193 data->flags |= STA_DRV_DATA_RX_HE_GI;
8194 }
8195 if (rate[NL80211_RATE_INFO_HE_DCM]) {
8196 data->rx_dcm =
8197 nla_get_u8(rate[NL80211_RATE_INFO_HE_DCM]);
8198 data->flags |= STA_DRV_DATA_RX_HE_DCM;
8199 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008200 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008201
Hai Shalom81f62d82019-07-22 12:10:00 -07008202 if (stats[NL80211_STA_INFO_TID_STATS])
8203 get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]);
8204
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008205 return NL_SKIP;
8206}
8207
Sunil Ravi77d572f2023-01-17 23:58:31 +00008208
8209int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
8210 const u8 *bssid,
8211 struct hostap_sta_driver_data *data)
8212{
8213 struct nl_msg *msg;
8214
8215 data->signal = -WPA_INVALID_NOISE;
8216 data->current_tx_rate = 0;
8217
8218 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
8219 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) {
8220 nlmsg_free(msg);
8221 return -ENOBUFS;
8222 }
8223
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008224 return send_and_recv_resp(drv, msg, get_sta_handler, data);
Sunil Ravi77d572f2023-01-17 23:58:31 +00008225}
8226
8227
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008228static int i802_read_sta_data(struct i802_bss *bss,
8229 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008230 const u8 *addr)
8231{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008232 struct nl_msg *msg;
8233
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008234 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
8235 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8236 nlmsg_free(msg);
8237 return -ENOBUFS;
8238 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008239
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008240 return send_and_recv_resp(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008241}
8242
8243
8244static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008245 int cw_min, int cw_max, int burst_time,
8246 int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008247{
8248 struct i802_bss *bss = priv;
8249 struct wpa_driver_nl80211_data *drv = bss->drv;
8250 struct nl_msg *msg;
8251 struct nlattr *txq, *params;
Hai Shalom74f70d42019-02-11 14:42:39 -08008252 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008253
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008254 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008255 if (!msg)
8256 return -1;
8257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008258 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
8259 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008260 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008261
8262 /* We are only sending parameters for a single TXQ at a time */
8263 params = nla_nest_start(msg, 1);
8264 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008265 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008266
8267 switch (queue) {
8268 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008269 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
8270 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008271 break;
8272 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008273 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
8274 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008275 break;
8276 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008277 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
8278 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008279 break;
8280 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008281 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
8282 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008283 break;
8284 }
8285 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
8286 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008287 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
8288 (burst_time * 100 + 16) / 32) ||
8289 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
8290 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
8291 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
8292 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008293
8294 nla_nest_end(msg, params);
8295
8296 nla_nest_end(msg, txq);
8297
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008298 if (link_id != NL80211_DRV_LINK_ID_NA &&
8299 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
8300 goto fail;
8301
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008302 res = send_and_recv_cmd(drv, msg);
Hai Shalom74f70d42019-02-11 14:42:39 -08008303 wpa_printf(MSG_DEBUG,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008304 "nl80211: link=%d: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d",
8305 link_id, queue, aifs, cw_min, cw_max, burst_time, res);
Hai Shalom74f70d42019-02-11 14:42:39 -08008306 if (res == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008307 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008308 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008309fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008310 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008311 return -1;
8312}
8313
8314
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008315static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008316 const char *ifname, int vlan_id, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008317{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008318 struct wpa_driver_nl80211_data *drv = bss->drv;
8319 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008320 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008321
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008322 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
8323 ", ifname=%s[%d], vlan_id=%d)",
8324 bss->ifname, if_nametoindex(bss->ifname),
8325 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008326 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
8327 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Hai Shalom899fcc72020-10-19 14:38:18 -07008328 (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07008329 nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) ||
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008330 (link_id != NL80211_DRV_LINK_ID_NA &&
8331 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008332 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
8333 nlmsg_free(msg);
8334 return -ENOBUFS;
8335 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008336
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008337 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008338 if (ret < 0) {
8339 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
8340 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
8341 MAC2STR(addr), ifname, vlan_id, ret,
8342 strerror(-ret));
8343 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008344 return ret;
8345}
8346
8347
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008348static int i802_get_inact_sec(void *priv, const u8 *addr)
8349{
8350 struct hostap_sta_driver_data data;
8351 int ret;
8352
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08008353 os_memset(&data, 0, sizeof(data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008354 data.inactive_msec = (unsigned long) -1;
8355 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008356 if (ret == -ENOENT)
8357 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008358 if (ret || data.inactive_msec == (unsigned long) -1)
8359 return -1;
8360 return data.inactive_msec / 1000;
8361}
8362
8363
8364static int i802_sta_clear_stats(void *priv, const u8 *addr)
8365{
8366#if 0
8367 /* TODO */
8368#endif
8369 return 0;
8370}
8371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008372
8373static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008374 u16 reason, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008375{
8376 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008377 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008378 struct ieee80211_mgmt mgmt;
Dmitry Shmidt29333592017-01-09 12:27:11 -08008379 u8 channel;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008380 struct i802_link *link = nl80211_get_link(bss, link_id);
Dmitry Shmidt29333592017-01-09 12:27:11 -08008381
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008382 if (ieee80211_freq_to_chan(link->freq, &channel) ==
Dmitry Shmidt29333592017-01-09 12:27:11 -08008383 HOSTAPD_MODE_IEEE80211AD) {
8384 /* Deauthentication is not used in DMG/IEEE 802.11ad;
8385 * disassociate the STA instead. */
8386 return i802_sta_disassoc(priv, own_addr, addr, reason);
8387 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008388
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008389 if (is_mesh_interface(drv->nlmode))
8390 return -1;
8391
Dmitry Shmidt04949592012-07-19 12:16:46 -07008392 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008393 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008394
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008395 memset(&mgmt, 0, sizeof(mgmt));
8396 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
8397 WLAN_FC_STYPE_DEAUTH);
8398 memcpy(mgmt.da, addr, ETH_ALEN);
8399 memcpy(mgmt.sa, own_addr, ETH_ALEN);
8400 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
8401 mgmt.u.deauth.reason_code = host_to_le16(reason);
8402 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
8403 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008404 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008405 0, NULL, 0, 0, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008406}
8407
8408
8409static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -07008410 u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008411{
8412 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008413 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008414 struct ieee80211_mgmt mgmt;
8415
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008416 if (is_mesh_interface(drv->nlmode))
8417 return -1;
8418
Dmitry Shmidt04949592012-07-19 12:16:46 -07008419 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008420 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008422 memset(&mgmt, 0, sizeof(mgmt));
8423 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
8424 WLAN_FC_STYPE_DISASSOC);
8425 memcpy(mgmt.da, addr, ETH_ALEN);
8426 memcpy(mgmt.sa, own_addr, ETH_ALEN);
8427 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
8428 mgmt.u.disassoc.reason_code = host_to_le16(reason);
8429 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
8430 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008431 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008432 0, NULL, 0, 0, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008433}
8434
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008435
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008436static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
8437{
8438 char buf[200], *pos, *end;
8439 int i, res;
8440
8441 pos = buf;
8442 end = pos + sizeof(buf);
8443
8444 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07008445 if (!drv->if_indices[i].ifindex)
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008446 continue;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008447 res = os_snprintf(pos, end - pos, " %d(%d)",
Hai Shalom81f62d82019-07-22 12:10:00 -07008448 drv->if_indices[i].ifindex,
8449 drv->if_indices[i].reason);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008450 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008451 break;
8452 pos += res;
8453 }
8454 *pos = '\0';
8455
8456 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
8457 drv->num_if_indices, buf);
8458}
8459
8460
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008461static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
8462 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008463{
8464 int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07008465 struct drv_nl80211_if_info *old;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008466
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008467 wpa_printf(MSG_DEBUG,
8468 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
8469 ifidx, ifidx_reason);
8470 if (have_ifidx(drv, ifidx, ifidx_reason)) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008471 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
8472 ifidx);
8473 return;
8474 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07008475 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07008476 if (drv->if_indices[i].ifindex == 0) {
8477 drv->if_indices[i].ifindex = ifidx;
8478 drv->if_indices[i].reason = ifidx_reason;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008479 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008480 return;
8481 }
8482 }
8483
8484 if (drv->if_indices != drv->default_if_indices)
8485 old = drv->if_indices;
8486 else
8487 old = NULL;
8488
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008489 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
Hai Shalom81f62d82019-07-22 12:10:00 -07008490 sizeof(*old));
Jouni Malinen75ecf522011-06-27 15:19:46 -07008491 if (!drv->if_indices) {
8492 if (!old)
8493 drv->if_indices = drv->default_if_indices;
8494 else
8495 drv->if_indices = old;
8496 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
8497 "interfaces");
8498 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
8499 return;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008500 }
8501 if (!old)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008502 os_memcpy(drv->if_indices, drv->default_if_indices,
8503 sizeof(drv->default_if_indices));
Hai Shalom81f62d82019-07-22 12:10:00 -07008504 drv->if_indices[drv->num_if_indices].ifindex = ifidx;
8505 drv->if_indices[drv->num_if_indices].reason = ifidx_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008506 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008507 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008508}
8509
8510
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008511static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
8512 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008513{
8514 int i;
8515
8516 for (i = 0; i < drv->num_if_indices; i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07008517 if ((drv->if_indices[i].ifindex == ifidx ||
8518 ifidx == IFIDX_ANY) &&
8519 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008520 ifidx_reason == IFIDX_ANY)) {
Hai Shalom81f62d82019-07-22 12:10:00 -07008521 drv->if_indices[i].ifindex = 0;
8522 drv->if_indices[i].reason = 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008523 break;
8524 }
8525 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07008526 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008527}
8528
8529
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008530static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
8531 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008532{
8533 int i;
8534
8535 for (i = 0; i < drv->num_if_indices; i++)
Hai Shalom81f62d82019-07-22 12:10:00 -07008536 if (drv->if_indices[i].ifindex == ifidx &&
8537 (drv->if_indices[i].reason == ifidx_reason ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008538 ifidx_reason == IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07008539 return 1;
8540
8541 return 0;
8542}
8543
8544
8545static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07008546 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008547{
8548 struct i802_bss *bss = priv;
8549 struct wpa_driver_nl80211_data *drv = bss->drv;
8550 char name[IFNAMSIZ + 1];
Roshan Pius3a1667e2018-07-03 15:17:14 -07008551 union wpa_event_data event;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008552 int ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008553
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008554 ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
8555 if (ret >= (int) sizeof(name))
8556 wpa_printf(MSG_WARNING,
8557 "nl80211: WDS interface name was truncated");
8558 else if (ret < 0)
8559 return ret;
8560
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07008561 if (ifname_wds)
8562 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
8563
Jouni Malinen75ecf522011-06-27 15:19:46 -07008564 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
8565 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
8566 if (val) {
8567 if (!if_nametoindex(name)) {
8568 if (nl80211_create_iface(drv, name,
8569 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008570 bss->addr, 1, NULL, NULL, 0) <
8571 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008572 return -1;
8573 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008574 linux_br_add_if(drv->global->ioctl_sock,
8575 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07008576 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008577
8578 os_memset(&event, 0, sizeof(event));
8579 event.wds_sta_interface.sta_addr = addr;
8580 event.wds_sta_interface.ifname = name;
8581 event.wds_sta_interface.istatus = INTERFACE_ADDED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07008582 wpa_supplicant_event(bss->ctx,
Roshan Pius3a1667e2018-07-03 15:17:14 -07008583 EVENT_WDS_STA_INTERFACE_STATUS,
8584 &event);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008585 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008586 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
8587 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
8588 "interface %s up", name);
8589 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008590 return i802_set_sta_vlan(priv, addr, name, 0,
8591 NL80211_DRV_LINK_ID_NA);
Jouni Malinen75ecf522011-06-27 15:19:46 -07008592 } else {
Hai Shalom74f70d42019-02-11 14:42:39 -08008593 if (bridge_ifname &&
8594 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
8595 name) < 0)
8596 wpa_printf(MSG_INFO,
8597 "nl80211: Failed to remove interface %s from bridge %s: %s",
8598 name, bridge_ifname, strerror(errno));
Dmitry Shmidtaa532512012-09-24 10:35:31 -07008599
Sunil Ravi2a14cf12023-11-21 00:54:38 +00008600 i802_set_sta_vlan(priv, addr, bss->ifname, 0,
8601 NL80211_DRV_LINK_ID_NA);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008602 nl80211_remove_iface(drv, if_nametoindex(name));
Roshan Pius3a1667e2018-07-03 15:17:14 -07008603 os_memset(&event, 0, sizeof(event));
8604 event.wds_sta_interface.sta_addr = addr;
8605 event.wds_sta_interface.ifname = name;
8606 event.wds_sta_interface.istatus = INTERFACE_REMOVED;
Hai Shalomce48b4a2018-09-05 11:41:35 -07008607 wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS,
Roshan Pius3a1667e2018-07-03 15:17:14 -07008608 &event);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008609 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07008610 }
8611}
8612
8613
8614static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
8615{
8616 struct wpa_driver_nl80211_data *drv = eloop_ctx;
8617 struct sockaddr_ll lladdr;
8618 unsigned char buf[3000];
8619 int len;
8620 socklen_t fromlen = sizeof(lladdr);
8621
8622 len = recvfrom(sock, buf, sizeof(buf), 0,
8623 (struct sockaddr *)&lladdr, &fromlen);
8624 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008625 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
8626 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07008627 return;
8628 }
8629
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008630 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07008631 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
8632}
8633
8634
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008635static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
8636 struct i802_bss *bss,
8637 const char *brname, const char *ifname)
8638{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008639 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008640 char in_br[IFNAMSIZ];
8641
8642 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008643 br_ifindex = if_nametoindex(brname);
8644 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008645 /*
8646 * Bridge was configured, but the bridge device does
8647 * not exist. Try to add it now.
8648 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008649 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008650 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
8651 "bridge interface %s: %s",
8652 brname, strerror(errno));
8653 return -1;
8654 }
8655 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008656 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008657 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008658 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008659 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008660
8661 if (linux_br_get(in_br, ifname) == 0) {
Hai Shalomc9e41a12018-07-31 14:41:42 -07008662 if (os_strcmp(in_br, brname) == 0) {
8663 bss->already_in_bridge = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008664 return 0; /* already in the bridge */
Hai Shalomc9e41a12018-07-31 14:41:42 -07008665 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008666
8667 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
8668 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008669 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
8670 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008671 wpa_printf(MSG_ERROR, "nl80211: Failed to "
8672 "remove interface %s from bridge "
8673 "%s: %s",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008674 ifname, in_br, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008675 return -1;
8676 }
8677 }
8678
8679 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
8680 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008681 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008682 wpa_printf(MSG_WARNING,
8683 "nl80211: Failed to add interface %s into bridge %s: %s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008684 ifname, brname, strerror(errno));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008685 /* Try to continue without the interface being in a bridge. This
8686 * may be needed for some cases, e.g., with Open vSwitch, where
8687 * an external component will need to handle bridge
8688 * configuration. */
8689 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008690 }
8691 bss->added_if_into_bridge = 1;
8692
8693 return 0;
8694}
8695
8696
8697static void *i802_init(struct hostapd_data *hapd,
8698 struct wpa_init_params *params)
8699{
8700 struct wpa_driver_nl80211_data *drv;
8701 struct i802_bss *bss;
8702 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008703 char master_ifname[IFNAMSIZ];
8704 int ifindex, br_ifindex = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008705 int br_added = 0;
8706
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008707 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
8708 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008709 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008710 if (bss == NULL)
8711 return NULL;
8712
8713 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008714
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008715 if (linux_br_get(master_ifname, params->ifname) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008716 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008717 params->ifname, master_ifname);
8718 br_ifindex = if_nametoindex(master_ifname);
8719 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
8720 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
8721 linux_master_get(master_ifname, params->ifname) == 0) {
8722 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
8723 params->ifname, master_ifname);
8724 /* start listening for EAPOL on the master interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008725 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08008726
8727 /* check if master itself is under bridge */
8728 if (linux_br_get(master_ifname, master_ifname) == 0) {
8729 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
8730 master_ifname);
8731 br_ifindex = if_nametoindex(master_ifname);
8732 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
8733 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008734 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008735 master_ifname[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008736 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008737
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008738 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008740 for (i = 0; i < params->num_bridge; i++) {
8741 if (params->bridge[i]) {
8742 ifindex = if_nametoindex(params->bridge[i]);
8743 if (ifindex)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008744 add_ifidx(drv, ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008745 if (ifindex == br_ifindex)
8746 br_added = 1;
8747 }
8748 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008749
8750 /* start listening for EAPOL on the default AP interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008751 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008752
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008753 if (params->num_bridge && params->bridge[0]) {
8754 if (i802_check_bridge(drv, bss, params->bridge[0],
8755 params->ifname) < 0)
8756 goto failed;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008757 if (os_strcmp(params->bridge[0], master_ifname) != 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008758 br_added = 1;
8759 }
8760
8761 if (!br_added && br_ifindex &&
8762 (params->num_bridge == 0 || !params->bridge[0]))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08008763 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008764
Sunil Ravi88611412024-06-28 17:34:56 +00008765#ifdef CONFIG_LIBNL3_ROUTE
Hai Shalomc9e41a12018-07-31 14:41:42 -07008766 if (bss->added_if_into_bridge || bss->already_in_bridge) {
Hai Shalomfdcde762020-04-02 11:19:20 -07008767 int err;
8768
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008769 drv->rtnl_sk = nl_socket_alloc();
8770 if (drv->rtnl_sk == NULL) {
8771 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
8772 goto failed;
8773 }
8774
Hai Shalomfdcde762020-04-02 11:19:20 -07008775 err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
8776 if (err) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008777 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -07008778 nl_geterror(err));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008779 goto failed;
8780 }
8781 }
Sunil Ravi88611412024-06-28 17:34:56 +00008782#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008783
Hai Shalomb755a2a2020-04-23 21:49:02 -07008784 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
8785 wpa_printf(MSG_DEBUG,
8786 "nl80211: Do not open EAPOL RX socket - using control port for RX");
8787 goto skip_eapol_sock;
8788 }
8789
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008790 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
8791 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008792 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
8793 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008794 goto failed;
8795 }
8796
8797 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
8798 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008799 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008800 goto failed;
8801 }
Hai Shalomb755a2a2020-04-23 21:49:02 -07008802skip_eapol_sock:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008803
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008804 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
8805 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008806 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008807 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008808
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008809 memcpy(bss->addr, params->own_addr, ETH_ALEN);
8810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008811 return bss;
8812
8813failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008814 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008815 return NULL;
8816}
8817
8818
8819static void i802_deinit(void *priv)
8820{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008821 struct i802_bss *bss = priv;
8822 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008823}
8824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008825
8826static enum nl80211_iftype wpa_driver_nl80211_if_type(
8827 enum wpa_driver_if_type type)
8828{
8829 switch (type) {
8830 case WPA_IF_STATION:
8831 return NL80211_IFTYPE_STATION;
8832 case WPA_IF_P2P_CLIENT:
8833 case WPA_IF_P2P_GROUP:
8834 return NL80211_IFTYPE_P2P_CLIENT;
8835 case WPA_IF_AP_VLAN:
8836 return NL80211_IFTYPE_AP_VLAN;
8837 case WPA_IF_AP_BSS:
8838 return NL80211_IFTYPE_AP;
8839 case WPA_IF_P2P_GO:
8840 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008841 case WPA_IF_P2P_DEVICE:
8842 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008843 case WPA_IF_MESH:
8844 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008845 default:
8846 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008847 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008848}
8849
8850
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008851static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
8852{
8853 struct wpa_driver_nl80211_data *drv;
8854 dl_list_for_each(drv, &global->interfaces,
8855 struct wpa_driver_nl80211_data, list) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008856 if (ether_addr_equal(addr, drv->first_bss->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008857 return 1;
8858 }
8859 return 0;
8860}
8861
8862
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008863static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008864{
8865 unsigned int idx;
8866
8867 if (!drv->global)
8868 return -1;
8869
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008870 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008871 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008872 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008873 new_addr[0] ^= idx << 2;
8874 if (!nl80211_addr_in_use(drv->global, new_addr))
8875 break;
8876 }
8877 if (idx == 64)
8878 return -1;
8879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008880 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008881 MACSTR, MAC2STR(new_addr));
8882
8883 return 0;
8884}
8885
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008886
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008887struct wdev_info {
8888 u64 wdev_id;
8889 int wdev_id_set;
8890 u8 macaddr[ETH_ALEN];
8891};
8892
8893static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
8894{
8895 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8896 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8897 struct wdev_info *wi = arg;
8898
8899 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8900 genlmsg_attrlen(gnlh, 0), NULL);
8901 if (tb[NL80211_ATTR_WDEV]) {
8902 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
8903 wi->wdev_id_set = 1;
8904 }
8905
8906 if (tb[NL80211_ATTR_MAC])
8907 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
8908 ETH_ALEN);
8909
8910 return NL_SKIP;
8911}
8912
8913
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008914static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
8915 const char *ifname, const u8 *addr,
8916 void *bss_ctx, void **drv_priv,
8917 char *force_ifname, u8 *if_addr,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008918 const char *bridge, int use_existing,
8919 int setup_ap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008920{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008921 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008922 struct i802_bss *bss = priv;
8923 struct wpa_driver_nl80211_data *drv = bss->drv;
8924 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008925 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008926
8927 if (addr)
8928 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008929 nlmode = wpa_driver_nl80211_if_type(type);
8930 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
8931 struct wdev_info p2pdev_info;
8932
8933 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
8934 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
8935 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008936 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008937 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
8938 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
8939 ifname);
8940 return -1;
8941 }
8942
8943 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
8944 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
Mir Ali8a8f1002020-10-06 22:41:40 +05308945 if (!is_zero_ether_addr(p2pdev_info.macaddr)) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008946 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
Mir Ali8a8f1002020-10-06 22:41:40 +05308947 os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN);
8948 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008949 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
8950 ifname,
8951 (long long unsigned int) p2pdev_info.wdev_id);
8952 } else {
8953 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008954 0, NULL, NULL, use_existing);
8955 if (use_existing && ifidx == -ENFILE) {
8956 added = 0;
8957 ifidx = if_nametoindex(ifname);
8958 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008959 return -1;
8960 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008961 }
8962
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008963 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07008964 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008965 os_memcpy(if_addr, bss->addr, ETH_ALEN);
8966 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07008967 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008968 if (added)
8969 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008970 return -1;
8971 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008972 }
8973
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008974 if (!addr &&
8975 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07008976 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00008977 type == WPA_IF_STATION || type == WPA_IF_AP_BSS)) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07008978 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008979 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008980
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008981 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008982 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07008983 if (added)
8984 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008985 return -1;
8986 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008987 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008988 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07008989 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008990 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07008991 if (added)
8992 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008993 return -1;
8994 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008995 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008996 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07008997 if (added)
8998 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008999 return -1;
9000 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009001 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07009002 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009003 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009004
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009005 if (type == WPA_IF_AP_BSS && setup_ap) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009006 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
Sunil Ravi88611412024-06-28 17:34:56 +00009007 unsigned int i;
Sunil Ravi036cec52023-03-29 11:35:17 -07009008
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009009 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009010 if (added)
9011 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009012 return -1;
9013 }
9014
Sunil Ravi88611412024-06-28 17:34:56 +00009015 /* Initialize here before any failure path */
9016 for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
9017 new_bss->links[i].link_id = NL80211_DRV_LINK_ID_NA;
9018
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009019 if (bridge &&
9020 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
9021 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
9022 "interface %s to a bridge %s",
9023 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009024 if (added)
9025 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009026 os_free(new_bss);
9027 return -1;
9028 }
9029
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009030 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
9031 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07009032 if (added)
9033 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009034 os_free(new_bss);
9035 return -1;
9036 }
9037 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009038 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009039 new_bss->ifindex = ifidx;
9040 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009041 new_bss->next = drv->first_bss->next;
Sunil Ravi036cec52023-03-29 11:35:17 -07009042 new_bss->flink = &new_bss->links[0];
Sunil Ravi88611412024-06-28 17:34:56 +00009043 new_bss->n_links = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07009044 os_memcpy(new_bss->flink->addr, new_bss->addr, ETH_ALEN);
9045
9046 new_bss->flink->freq = drv->first_bss->flink->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08009047 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009048 new_bss->added_if = added;
9049 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009050 if (drv_priv)
9051 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009052 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009053
9054 /* Subscribe management frames for this WPA_IF_AP_BSS */
9055 if (nl80211_setup_ap(new_bss))
9056 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009057 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009058
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009059 if (drv->global)
9060 drv->global->if_add_ifindex = ifidx;
9061
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07009062 /*
9063 * Some virtual interfaces need to process EAPOL packets and events on
9064 * the parent interface. This is used mainly with hostapd.
9065 */
9066 if (ifidx > 0 &&
9067 (drv->hostapd ||
9068 nlmode == NL80211_IFTYPE_AP_VLAN ||
9069 nlmode == NL80211_IFTYPE_WDS ||
9070 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08009071 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07009072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009073 return 0;
9074}
9075
9076
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009077static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009078 enum wpa_driver_if_type type,
9079 const char *ifname)
9080{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009081 struct wpa_driver_nl80211_data *drv = bss->drv;
9082 int ifindex = if_nametoindex(ifname);
9083
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009084 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
9085 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08009086 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07009087 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009088 else if (ifindex > 0 && !bss->added_if) {
9089 struct wpa_driver_nl80211_data *drv2;
9090 dl_list_for_each(drv2, &drv->global->interfaces,
Dmitry Shmidt9c175262016-03-03 10:20:07 -08009091 struct wpa_driver_nl80211_data, list) {
9092 del_ifidx(drv2, ifindex, IFIDX_ANY);
9093 del_ifidx(drv2, IFIDX_ANY, ifindex);
9094 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009095 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07009096
Dmitry Shmidtaa532512012-09-24 10:35:31 -07009097 if (type != WPA_IF_AP_BSS)
9098 return 0;
9099
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009100 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009101 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
9102 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009103 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
9104 "interface %s from bridge %s: %s",
9105 bss->ifname, bss->brname, strerror(errno));
9106 }
9107 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009108 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009109 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
9110 "bridge %s: %s",
9111 bss->brname, strerror(errno));
9112 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009113
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009114 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009115 struct i802_bss *tbss;
9116
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009117 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
9118 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009119 if (tbss->next == bss) {
9120 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009121 /* Unsubscribe management frames */
9122 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009123 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07009124 if (!bss->added_if)
9125 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009126 os_free(bss);
9127 bss = NULL;
9128 break;
9129 }
9130 }
9131 if (bss)
9132 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
9133 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009134 } else {
9135 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
9136 nl80211_teardown_ap(bss);
9137 if (!bss->added_if && !drv->first_bss->next)
Sunil Ravi036cec52023-03-29 11:35:17 -07009138 wpa_driver_nl80211_del_beacon_all(bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009139 nl80211_destroy_bss(bss);
9140 if (!bss->added_if)
9141 i802_set_iface_flags(bss, 0);
9142 if (drv->first_bss->next) {
9143 drv->first_bss = drv->first_bss->next;
9144 drv->ctx = drv->first_bss->ctx;
9145 os_free(bss);
9146 } else {
9147 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
9148 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009149 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009150
9151 return 0;
9152}
9153
9154
9155static int cookie_handler(struct nl_msg *msg, void *arg)
9156{
9157 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9158 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9159 u64 *cookie = arg;
9160 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9161 genlmsg_attrlen(gnlh, 0), NULL);
9162 if (tb[NL80211_ATTR_COOKIE])
9163 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
9164 return NL_SKIP;
9165}
9166
9167
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009168static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009169 unsigned int freq, unsigned int wait,
9170 const u8 *buf, size_t buf_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07009171 int save_cookie, int no_cck, int no_ack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009172 int offchanok, const u16 *csa_offs,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009173 size_t csa_offs_len, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009174{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009175 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009176 struct nl_msg *msg;
9177 u64 cookie;
9178 int ret = -1;
9179
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07009180 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07009181 "no_ack=%d offchanok=%d",
9182 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07009183 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009184
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009185 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009186 ((link_id != NL80211_DRV_LINK_ID_NA) &&
9187 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009188 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9189 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
9190 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
9191 drv->test_use_roc_tx) &&
9192 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
9193 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
9194 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009195 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
9196 csa_offs_len * sizeof(u16), csa_offs)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009197 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
9198 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009199
9200 cookie = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009201 ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009202 msg = NULL;
9203 if (ret) {
9204 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07009205 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
9206 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009207 } else {
9208 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
9209 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
9210 (long long unsigned int) cookie);
9211
Hai Shalomfdcde762020-04-02 11:19:20 -07009212 if (save_cookie)
9213 drv->send_frame_cookie = no_ack ? (u64) -1 : cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009214
Sunil Ravia04bd252022-05-02 22:54:18 -07009215 if (!wait) {
9216 /* There is no need to store this cookie since there
9217 * is no wait that could be canceled later. */
9218 goto fail;
9219 }
Hai Shalomfdcde762020-04-02 11:19:20 -07009220 if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009221 wpa_printf(MSG_DEBUG,
Hai Shalomfdcde762020-04-02 11:19:20 -07009222 "nl80211: Drop oldest pending send frame cookie 0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009223 (long long unsigned int)
Hai Shalomfdcde762020-04-02 11:19:20 -07009224 drv->send_frame_cookies[0]);
9225 os_memmove(&drv->send_frame_cookies[0],
9226 &drv->send_frame_cookies[1],
9227 (MAX_SEND_FRAME_COOKIES - 1) *
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009228 sizeof(u64));
Hai Shalomfdcde762020-04-02 11:19:20 -07009229 drv->num_send_frame_cookies--;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009230 }
Hai Shalomfdcde762020-04-02 11:19:20 -07009231 drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie;
9232 drv->num_send_frame_cookies++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009233 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009234
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009235fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009236 nlmsg_free(msg);
9237 return ret;
9238}
9239
9240
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009241static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
9242 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009243 unsigned int wait_time,
9244 const u8 *dst, const u8 *src,
9245 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009246 const u8 *data, size_t data_len,
9247 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009248{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009249 struct wpa_driver_nl80211_data *drv = bss->drv;
9250 int ret = -1;
9251 u8 *buf;
9252 struct ieee80211_hdr *hdr;
Hai Shalomfdcde762020-04-02 11:19:20 -07009253 int offchanok = 1;
9254
Sunil Ravi036cec52023-03-29 11:35:17 -07009255 if (is_ap_interface(drv->nlmode) && (int) freq == bss->flink->freq &&
9256 bss->flink->beacon_set)
Hai Shalomfdcde762020-04-02 11:19:20 -07009257 offchanok = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009258
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009259 if (!freq && is_sta_interface(drv->nlmode))
9260 offchanok = 0;
9261
9262 wpa_printf(MSG_DEBUG,
9263 "nl80211: Send Action frame (ifindex=%d, freq=%u MHz wait=%d ms no_cck=%d offchanok=%d dst="
9264 MACSTR " src=" MACSTR " bssid=" MACSTR ")",
9265 drv->ifindex, freq, wait_time, no_cck, offchanok,
9266 MAC2STR(dst), MAC2STR(src), MAC2STR(bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009267
9268 buf = os_zalloc(24 + data_len);
9269 if (buf == NULL)
9270 return ret;
9271 os_memcpy(buf + 24, data, data_len);
9272 hdr = (struct ieee80211_hdr *) buf;
9273 hdr->frame_control =
9274 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
9275 os_memcpy(hdr->addr1, dst, ETH_ALEN);
9276 os_memcpy(hdr->addr2, src, ETH_ALEN);
9277 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
9278
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009279 if (!ether_addr_equal(bss->addr, src)) {
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009280 wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR,
9281 MAC2STR(src));
9282 os_memcpy(bss->rand_addr, src, ETH_ALEN);
9283 } else {
9284 os_memset(bss->rand_addr, 0, ETH_ALEN);
9285 }
9286
Hai Shalom60840252021-02-19 19:02:11 -08009287#ifdef CONFIG_MESH
9288 if (is_mesh_interface(drv->nlmode)) {
9289 struct hostapd_hw_modes *modes;
9290 u16 num_modes, flags;
9291 u8 dfs_domain;
9292 int i;
9293
9294 modes = nl80211_get_hw_feature_data(bss, &num_modes,
9295 &flags, &dfs_domain);
9296 if (dfs_domain != HOSTAPD_DFS_REGION_ETSI &&
Sunil Ravi036cec52023-03-29 11:35:17 -07009297 ieee80211_is_dfs(bss->flink->freq, modes, num_modes))
Hai Shalom60840252021-02-19 19:02:11 -08009298 offchanok = 0;
9299 if (modes) {
9300 for (i = 0; i < num_modes; i++) {
9301 os_free(modes[i].channels);
9302 os_free(modes[i].rates);
9303 }
9304 os_free(modes);
9305 }
9306 }
9307#endif /* CONFIG_MESH */
9308
Dmitry Shmidt56052862013-10-04 10:23:25 -07009309 if (is_ap_interface(drv->nlmode) &&
9310 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
Sunil Ravi036cec52023-03-29 11:35:17 -07009311 (int) freq == bss->flink->freq || drv->device_ap_sme ||
Dmitry Shmidt56052862013-10-04 10:23:25 -07009312 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009313 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07009314 0, freq, no_cck, offchanok,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00009315 wait_time, NULL, 0, 0, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009316 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009317 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009318 24 + data_len, 1, no_cck, 0,
9319 offchanok, NULL, 0,
9320 NL80211_DRV_LINK_ID_NA);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009321
9322 os_free(buf);
9323 return ret;
9324}
9325
9326
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009327static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009328{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009329 struct wpa_driver_nl80211_data *drv = bss->drv;
9330 struct nl_msg *msg;
9331 int ret;
9332
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08009333 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009334 (long long unsigned int) cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009335 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009336 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009337 nlmsg_free(msg);
9338 return;
9339 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009340
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009341 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009342 if (ret)
9343 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
9344 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009345}
9346
9347
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009348static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
9349{
9350 struct i802_bss *bss = priv;
9351 struct wpa_driver_nl80211_data *drv = bss->drv;
9352 unsigned int i;
9353 u64 cookie;
9354
9355 /* Cancel the last pending TX cookie */
Sunil Ravia04bd252022-05-02 22:54:18 -07009356 if (drv->send_frame_cookie != (u64) -1)
9357 nl80211_frame_wait_cancel(bss, drv->send_frame_cookie);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009358
9359 /*
9360 * Cancel the other pending TX cookies, if any. This is needed since
9361 * the driver may keep a list of all pending offchannel TX operations
9362 * and free up the radio only once they have expired or cancelled.
9363 */
Hai Shalomfdcde762020-04-02 11:19:20 -07009364 for (i = drv->num_send_frame_cookies; i > 0; i--) {
9365 cookie = drv->send_frame_cookies[i - 1];
9366 if (cookie != drv->send_frame_cookie)
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009367 nl80211_frame_wait_cancel(bss, cookie);
9368 }
Hai Shalomfdcde762020-04-02 11:19:20 -07009369 drv->num_send_frame_cookies = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009370}
9371
9372
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009373static int nl80211_put_any_link_id(struct nl_msg *msg,
9374 struct driver_sta_mlo_info *mlo,
9375 int freq)
9376{
9377 int i;
9378 int link_id = -1;
9379 int any_valid_link_id = -1;
9380
9381 if (!mlo->valid_links)
9382 return 0;
9383
9384 /* First try to pick a link that uses the same band */
9385 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
9386 if (!(mlo->valid_links & BIT(i)))
9387 continue;
9388
9389 if (any_valid_link_id == -1)
9390 any_valid_link_id = i;
9391
9392 if (is_same_band(freq, mlo->links[i].freq)) {
9393 link_id = i;
9394 break;
9395 }
9396 }
9397
9398 /* Use any valid link ID if no band match was found */
9399 if (link_id == -1)
9400 link_id = any_valid_link_id;
9401
9402 if (link_id == -1) {
9403 wpa_printf(MSG_INFO,
9404 "nl80211: No valid Link ID found for freq %u", freq);
9405 return 0;
9406 }
9407
9408 wpa_printf(MSG_DEBUG, "nl80211: Add Link ID %d", link_id);
9409 return nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id);
9410}
9411
9412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009413static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
9414 unsigned int duration)
9415{
9416 struct i802_bss *bss = priv;
9417 struct wpa_driver_nl80211_data *drv = bss->drv;
9418 struct nl_msg *msg;
9419 int ret;
9420 u64 cookie;
9421
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009422 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
9423 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009424 nla_put_u32(msg, NL80211_ATTR_DURATION, duration) ||
9425 nl80211_put_any_link_id(msg, &drv->sta_mlo_info, freq)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009426 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009427 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009428 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009429
9430 cookie = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009431 ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009432 if (ret == 0) {
9433 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
9434 "0x%llx for freq=%u MHz duration=%u",
9435 (long long unsigned int) cookie, freq, duration);
9436 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009437 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009438 return 0;
9439 }
9440 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
9441 "(freq=%d duration=%u): %d (%s)",
9442 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009443 return -1;
9444}
9445
9446
9447static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
9448{
9449 struct i802_bss *bss = priv;
9450 struct wpa_driver_nl80211_data *drv = bss->drv;
9451 struct nl_msg *msg;
9452 int ret;
9453
9454 if (!drv->pending_remain_on_chan) {
9455 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
9456 "to cancel");
9457 return -1;
9458 }
9459
9460 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
9461 "0x%llx",
9462 (long long unsigned int) drv->remain_on_chan_cookie);
9463
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009464 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
9465 if (!msg ||
9466 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
9467 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009468 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009469 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009470
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009471 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009472 if (ret == 0)
9473 return 0;
9474 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
9475 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009476 return -1;
9477}
9478
9479
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009480static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009481{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009482 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07009483
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009484 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009485 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07009486 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
9487 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009488 /*
9489 * Do not disable Probe Request reporting that was
9490 * enabled in nl80211_setup_ap().
9491 */
9492 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
9493 "Probe Request reporting nl_preq=%p while "
9494 "in AP mode", bss->nl_preq);
9495 } else if (bss->nl_preq) {
9496 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
9497 "reporting nl_preq=%p", bss->nl_preq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07009498 nl80211_destroy_eloop_handle(&bss->nl_preq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009499 }
9500 return 0;
9501 }
9502
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009503 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009504 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009505 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009506 return 0;
9507 }
9508
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009509 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
9510 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009511 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009512 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
9513 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009514
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009515 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009516 (WLAN_FC_TYPE_MGMT << 2) |
9517 (WLAN_FC_STYPE_PROBE_REQ << 4),
Hai Shalome21d4e82020-04-29 16:34:06 -07009518 NULL, 0, false) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009519 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07009520
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07009521 nl80211_register_eloop_read(&bss->nl_preq,
9522 wpa_driver_nl80211_event_receive,
Roshan Pius3a1667e2018-07-03 15:17:14 -07009523 bss->nl_cb, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009524
9525 return 0;
9526
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009527 out_err:
9528 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009529 return -1;
9530}
9531
9532
9533static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
9534 int ifindex, int disabled)
9535{
9536 struct nl_msg *msg;
9537 struct nlattr *bands, *band;
9538 int ret;
9539
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009540 wpa_printf(MSG_DEBUG,
9541 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
9542 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
9543 "no NL80211_TXRATE_LEGACY constraint");
9544
9545 msg = nl80211_ifindex_msg(drv, ifindex, 0,
9546 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009547 if (!msg)
9548 return -1;
9549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009550 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
9551 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009552 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009553
9554 /*
9555 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
9556 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
9557 * rates. All 5 GHz rates are left enabled.
9558 */
9559 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009560 if (!band ||
9561 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
9562 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
9563 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009564 nla_nest_end(msg, band);
9565
9566 nla_nest_end(msg, bands);
9567
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009568 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009569 if (ret) {
9570 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
9571 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009572 } else
9573 drv->disabled_11b_rates = disabled;
9574
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009575 return ret;
9576
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009577fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009578 nlmsg_free(msg);
9579 return -1;
9580}
9581
9582
Sunil Raviaf399a82024-05-05 20:56:55 +00009583static void nl80211_remove_links(struct i802_bss *bss)
9584{
Sunil Ravi88611412024-06-28 17:34:56 +00009585 struct wpa_driver_nl80211_data *drv = bss->drv;
9586 struct nl_msg *msg;
Sunil Ravi036cec52023-03-29 11:35:17 -07009587 int ret;
9588 u8 link_id;
9589
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009590 if (bss->n_links == 0)
9591 return;
9592
Sunil Ravi88611412024-06-28 17:34:56 +00009593 while (bss->links[0].link_id != NL80211_DRV_LINK_ID_NA) {
9594 struct i802_link *link = &bss->links[0];
9595
9596 wpa_printf(MSG_DEBUG, "nl80211: MLD: remove link_id=%u",
9597 link->link_id);
9598
9599 wpa_driver_nl80211_del_beacon(bss, link);
9600
9601 link_id = link->link_id;
9602
9603 /* First remove the link locally */
9604 if (bss->n_links == 1) {
9605 bss->flink->link_id = NL80211_DRV_LINK_ID_NA;
9606 os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN);
9607 } else {
9608 struct i802_link *other = &bss->links[bss->n_links - 1];
9609
9610 os_memcpy(link, other, sizeof(*link));
9611 other->link_id = NL80211_DRV_LINK_ID_NA;
9612 os_memset(other->addr, 0, ETH_ALEN);
9613
9614 bss->n_links--;
9615 }
9616
9617 /* Remove the link from the kernel */
9618 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_REMOVE_LINK);
9619 if (!msg ||
9620 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) {
9621 nlmsg_free(msg);
9622 wpa_printf(MSG_ERROR,
9623 "nl80211: remove link (%d) failed",
9624 link_id);
9625 return;
9626 }
9627
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009628 ret = send_and_recv_cmd(drv, msg);
Sunil Ravi88611412024-06-28 17:34:56 +00009629 if (ret) {
9630 wpa_printf(MSG_ERROR,
9631 "nl80211: remove link (%d) failed. ret=%d (%s)",
9632 link_id, ret, strerror(-ret));
9633 return;
9634 }
9635 }
Sunil Ravi036cec52023-03-29 11:35:17 -07009636}
9637
9638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009639static int wpa_driver_nl80211_deinit_ap(void *priv)
9640{
9641 struct i802_bss *bss = priv;
9642 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi036cec52023-03-29 11:35:17 -07009643
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009644 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009645 return -1;
Sunil Ravi036cec52023-03-29 11:35:17 -07009646
9647 /* Stop beaconing */
Sunil Ravi88611412024-06-28 17:34:56 +00009648 wpa_driver_nl80211_del_beacon(bss, bss->flink);
Sunil Ravi036cec52023-03-29 11:35:17 -07009649
9650 nl80211_remove_links(bss);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07009651
9652 /*
9653 * If the P2P GO interface was dynamically added, then it is
9654 * possible that the interface change to station is not possible.
9655 */
9656 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
9657 return 0;
9658
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009659 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009660}
9661
9662
Sunil Ravi88611412024-06-28 17:34:56 +00009663static int wpa_driver_nl80211_stop_ap(void *priv)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07009664{
9665 struct i802_bss *bss = priv;
9666 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi036cec52023-03-29 11:35:17 -07009667
Dmitry Shmidtea69e842013-05-13 14:52:28 -07009668 if (!is_ap_interface(drv->nlmode))
9669 return -1;
Sunil Ravi036cec52023-03-29 11:35:17 -07009670
Sunil Ravi88611412024-06-28 17:34:56 +00009671 wpa_driver_nl80211_del_beacon_all(bss);
Sunil Ravi036cec52023-03-29 11:35:17 -07009672
Sunil Ravi88611412024-06-28 17:34:56 +00009673 return 0;
Dmitry Shmidtea69e842013-05-13 14:52:28 -07009674}
9675
9676
Dmitry Shmidt04949592012-07-19 12:16:46 -07009677static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
9678{
9679 struct i802_bss *bss = priv;
9680 struct wpa_driver_nl80211_data *drv = bss->drv;
9681 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
9682 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07009683
9684 /*
9685 * If the P2P Client interface was dynamically added, then it is
9686 * possible that the interface change to station is not possible.
9687 */
9688 if (bss->if_dynamic)
9689 return 0;
9690
Dmitry Shmidt04949592012-07-19 12:16:46 -07009691 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
9692}
9693
9694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009695static void wpa_driver_nl80211_resume(void *priv)
9696{
9697 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009698 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009699
9700 if (i802_set_iface_flags(bss, 1))
9701 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009702
9703 if (is_p2p_net_interface(nlmode))
9704 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009705}
9706
9707
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009708static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
9709{
9710 struct i802_bss *bss = priv;
9711 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07009712 struct nl_msg *msg;
9713 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009714
9715 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
9716 "hysteresis=%d", threshold, hysteresis);
9717
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009718 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
9719 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
9720 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
9721 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
9722 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009723 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009724 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07009725 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009726
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009727 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009728}
9729
9730
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009731static int get_channel_width(struct nl_msg *msg, void *arg)
9732{
9733 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9734 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9735 struct wpa_signal_info *sig_change = arg;
9736
9737 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9738 genlmsg_attrlen(gnlh, 0), NULL);
9739
9740 sig_change->center_frq1 = -1;
9741 sig_change->center_frq2 = -1;
9742 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
9743
9744 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
9745 sig_change->chanwidth = convert2width(
9746 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
9747 if (tb[NL80211_ATTR_CENTER_FREQ1])
9748 sig_change->center_frq1 =
9749 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
9750 if (tb[NL80211_ATTR_CENTER_FREQ2])
9751 sig_change->center_frq2 =
9752 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
9753 }
9754
9755 return NL_SKIP;
9756}
9757
9758
9759static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
9760 struct wpa_signal_info *sig)
9761{
9762 struct nl_msg *msg;
9763
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009764 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009765 return send_and_recv_resp(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009766}
9767
9768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009769static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
9770{
9771 struct i802_bss *bss = priv;
9772 struct wpa_driver_nl80211_data *drv = bss->drv;
9773 int res;
9774
9775 os_memset(si, 0, sizeof(*si));
Sunil Ravi77d572f2023-01-17 23:58:31 +00009776 res = nl80211_get_link_signal(drv, drv->bssid, &si->data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009777 if (res) {
9778 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
9779 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
9780 return res;
Sunil Ravi77d572f2023-01-17 23:58:31 +00009781 si->data.signal = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009782 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009783
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009784 res = nl80211_get_channel_width(drv, si);
9785 if (res != 0)
9786 return res;
9787
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009788 return nl80211_get_link_noise(drv, si);
9789}
9790
9791
Sunil Ravi89eba102022-09-13 21:04:37 -07009792static int get_links_noise(struct nl_msg *msg, void *arg)
9793{
9794 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9795 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9796 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
9797 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
9798 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
9799 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
9800 };
9801 struct wpa_mlo_signal_info *mlo_sig = arg;
9802 int i;
9803
9804 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9805 genlmsg_attrlen(gnlh, 0), NULL);
9806
9807 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
9808 wpa_printf(MSG_DEBUG, "nl80211: Survey data missing");
9809 return NL_SKIP;
9810 }
9811
9812 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
9813 tb[NL80211_ATTR_SURVEY_INFO],
9814 survey_policy)) {
9815 wpa_printf(MSG_DEBUG,
9816 "nl80211: Failed to parse nested attributes");
9817 return NL_SKIP;
9818 }
9819
9820 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
9821 return NL_SKIP;
9822
9823 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
9824 return NL_SKIP;
9825
Sunil Ravi88611412024-06-28 17:34:56 +00009826 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
9827 if (!(mlo_sig->valid_links & BIT(i)))
9828 continue;
9829
Sunil Ravi89eba102022-09-13 21:04:37 -07009830 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
9831 mlo_sig->links[i].frequency)
9832 continue;
9833
9834 mlo_sig->links[i].current_noise =
9835 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
9836 break;
9837 }
9838
9839 return NL_SKIP;
9840}
9841
9842
9843static int nl80211_get_links_noise(struct wpa_driver_nl80211_data *drv,
9844 struct wpa_mlo_signal_info *mlo_sig)
9845{
9846 struct nl_msg *msg;
9847
9848 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009849 return send_and_recv_resp(drv, msg, get_links_noise, mlo_sig);
Sunil Ravi89eba102022-09-13 21:04:37 -07009850}
9851
9852
9853static int get_links_channel_width(struct nl_msg *msg, void *arg)
9854{
9855 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9856 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9857 struct wpa_mlo_signal_info *mlo_sig = arg;
9858 struct nlattr *link;
9859 int rem_links;
9860
9861 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9862 genlmsg_attrlen(gnlh, 0), NULL);
9863
9864 if (!tb[NL80211_ATTR_MLO_LINKS])
9865 return NL_SKIP;
9866
9867 nla_for_each_nested(link, tb[NL80211_ATTR_MLO_LINKS], rem_links) {
9868 struct nlattr *tb2[NL80211_ATTR_MAX + 1];
9869 int link_id;
9870
9871 nla_parse(tb2, NL80211_ATTR_MAX, nla_data(link), nla_len(link),
9872 NULL);
9873
9874 if (!tb2[NL80211_ATTR_MLO_LINK_ID])
9875 continue;
9876
9877 link_id = nla_get_u8(tb2[NL80211_ATTR_MLO_LINK_ID]);
9878 if (link_id >= MAX_NUM_MLD_LINKS)
9879 continue;
9880
9881 if (!tb2[NL80211_ATTR_CHANNEL_WIDTH])
9882 continue;
9883 mlo_sig->links[link_id].chanwidth = convert2width(
9884 nla_get_u32(tb2[NL80211_ATTR_CHANNEL_WIDTH]));
9885 if (tb2[NL80211_ATTR_CENTER_FREQ1])
9886 mlo_sig->links[link_id].center_frq1 =
9887 nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ1]);
9888 if (tb2[NL80211_ATTR_CENTER_FREQ2])
9889 mlo_sig->links[link_id].center_frq2 =
9890 nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ2]);
9891 }
9892
9893 return NL_SKIP;
9894}
9895
9896
9897static int nl80211_get_links_channel_width(struct wpa_driver_nl80211_data *drv,
9898 struct wpa_mlo_signal_info *mlo_sig)
9899{
9900 struct nl_msg *msg;
9901
9902 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009903 return send_and_recv_resp(drv, msg, get_links_channel_width, mlo_sig);
Sunil Ravi89eba102022-09-13 21:04:37 -07009904}
9905
9906
9907static int nl80211_mlo_signal_poll(void *priv,
9908 struct wpa_mlo_signal_info *mlo_si)
9909{
9910 struct i802_bss *bss = priv;
9911 struct wpa_driver_nl80211_data *drv = bss->drv;
9912 int res;
9913 int i;
9914
9915 if (drv->nlmode != NL80211_IFTYPE_STATION ||
9916 !drv->sta_mlo_info.valid_links)
9917 return -1;
9918
9919 os_memset(mlo_si, 0, sizeof(*mlo_si));
9920 mlo_si->valid_links = drv->sta_mlo_info.valid_links;
9921
Sunil Ravi88611412024-06-28 17:34:56 +00009922 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
9923 if (!(mlo_si->valid_links & BIT(i)))
9924 continue;
9925
Sunil Ravi89eba102022-09-13 21:04:37 -07009926 res = nl80211_get_link_signal(drv,
9927 drv->sta_mlo_info.links[i].bssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +00009928 &mlo_si->links[i].data);
Sunil Ravi89eba102022-09-13 21:04:37 -07009929 if (res != 0)
9930 return res;
9931
9932 mlo_si->links[i].center_frq1 = -1;
9933 mlo_si->links[i].center_frq2 = -1;
9934 mlo_si->links[i].chanwidth = CHAN_WIDTH_UNKNOWN;
9935 mlo_si->links[i].current_noise = WPA_INVALID_NOISE;
9936 mlo_si->links[i].frequency = drv->sta_mlo_info.links[i].freq;
9937 }
9938
9939 res = nl80211_get_links_channel_width(drv, mlo_si);
9940 if (res != 0)
9941 return res;
9942
9943 return nl80211_get_links_noise(drv, mlo_si);
9944}
9945
9946
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009947static int nl80211_set_param(void *priv, const char *param)
9948{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009949 struct i802_bss *bss = priv;
9950 struct wpa_driver_nl80211_data *drv = bss->drv;
9951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009952 if (param == NULL)
9953 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009954 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009955
9956#ifdef CONFIG_P2P
9957 if (os_strstr(param, "use_p2p_group_interface=1")) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009958 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
9959 "interface");
9960 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
9961 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
9962 }
9963#endif /* CONFIG_P2P */
9964
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009965 if (os_strstr(param, "use_monitor=1"))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009966 drv->use_monitor = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009967
9968 if (os_strstr(param, "force_connect_cmd=1")) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009969 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009970 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009971 }
9972
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009973 if (os_strstr(param, "force_bss_selection=1"))
9974 drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
9975
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08009976 if (os_strstr(param, "no_offchannel_tx=1")) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08009977 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
9978 drv->test_use_roc_tx = 1;
9979 }
9980
Hai Shalomb755a2a2020-04-23 21:49:02 -07009981 if (os_strstr(param, "control_port=0")) {
Hai Shalomfdcde762020-04-02 11:19:20 -07009982 drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT;
Hai Shalom899fcc72020-10-19 14:38:18 -07009983 drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX |
9984 WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS);
9985 drv->control_port_ap = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07009986 }
9987
9988 if (os_strstr(param, "control_port_ap=1"))
9989 drv->control_port_ap = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07009990
Hai Shalom899fcc72020-10-19 14:38:18 -07009991 if (os_strstr(param, "control_port_ap=0")) {
9992 drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS;
9993 drv->control_port_ap = 0;
9994 }
9995
Hai Shalomfdcde762020-04-02 11:19:20 -07009996 if (os_strstr(param, "full_ap_client_state=0"))
9997 drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
9998
Hai Shalom899fcc72020-10-19 14:38:18 -07009999 if (os_strstr(param, "no_rrm=1")) {
10000 drv->no_rrm = 1;
10001
10002 if (!bss->in_deinit && !is_ap_interface(drv->nlmode) &&
10003 !is_mesh_interface(drv->nlmode)) {
10004 nl80211_mgmt_unsubscribe(bss, "no_rrm=1");
10005 if (nl80211_mgmt_subscribe_non_ap(bss) < 0)
10006 wpa_printf(MSG_DEBUG,
10007 "nl80211: Failed to re-register Action frame processing - ignore for now");
10008 }
10009 }
10010
Sunil Ravi640215c2023-06-28 23:08:09 +000010011 if (os_strstr(param, "secure_ltf=1")) {
10012 drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA |
10013 WPA_DRIVER_FLAGS2_SEC_LTF_AP;
10014 }
10015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010016 return 0;
10017}
10018
10019
Dmitry Shmidte4663042016-04-04 10:07:49 -070010020static void * nl80211_global_init(void *ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010021{
10022 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010023 struct netlink_config *cfg;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010024 struct utsname name;
10025
10026 if (uname(&name) == 0) {
10027 wpa_printf(MSG_DEBUG, "nl80211: Kernel version: %s %s (%s; %s)",
10028 name.sysname, name.release,
10029 name.version, name.machine);
10030 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010031
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010032 global = os_zalloc(sizeof(*global));
10033 if (global == NULL)
10034 return NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010035 global->ctx = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010036 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010037 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010038 global->if_add_ifindex = -1;
10039
10040 cfg = os_zalloc(sizeof(*cfg));
10041 if (cfg == NULL)
10042 goto err;
10043
10044 cfg->ctx = global;
10045 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
10046 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
10047 global->netlink = netlink_init(cfg);
10048 if (global->netlink == NULL) {
10049 os_free(cfg);
10050 goto err;
10051 }
10052
10053 if (wpa_driver_nl80211_init_nl_global(global) < 0)
10054 goto err;
10055
10056 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
10057 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070010058 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
10059 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010060 goto err;
10061 }
10062
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010063 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010064
10065err:
10066 nl80211_global_deinit(global);
10067 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010068}
10069
10070
10071static void nl80211_global_deinit(void *priv)
10072{
10073 struct nl80211_global *global = priv;
10074 if (global == NULL)
10075 return;
10076 if (!dl_list_empty(&global->interfaces)) {
10077 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
10078 "nl80211_global_deinit",
10079 dl_list_len(&global->interfaces));
10080 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010081
10082 if (global->netlink)
10083 netlink_deinit(global->netlink);
10084
10085 nl_destroy_handles(&global->nl);
10086
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070010087 if (global->nl_event)
Roshan Pius3a1667e2018-07-03 15:17:14 -070010088 nl80211_destroy_eloop_handle(&global->nl_event, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010089
10090 nl_cb_put(global->nl_cb);
10091
10092 if (global->ioctl_sock >= 0)
10093 close(global->ioctl_sock);
10094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010095 os_free(global);
10096}
10097
10098
10099static const char * nl80211_get_radio_name(void *priv)
10100{
10101 struct i802_bss *bss = priv;
10102 struct wpa_driver_nl80211_data *drv = bss->drv;
10103 return drv->phyname;
10104}
10105
10106
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010107static int nl80211_pmkid(struct i802_bss *bss, int cmd,
Sunil Ravi77d572f2023-01-17 23:58:31 +000010108 struct wpa_pmkid_params *params, bool skip_pmk)
Jouni Malinen75ecf522011-06-27 15:19:46 -070010109{
10110 struct nl_msg *msg;
Sunil Ravi77d572f2023-01-17 23:58:31 +000010111
10112 if (cmd == NL80211_CMD_SET_PMKSA)
10113 wpa_printf(MSG_DEBUG,
10114 "nl80211: NL80211_CMD_SET_PMKSA with skip_pmk=%s pmk_len=%zu",
10115 skip_pmk ? "true" : "false", params->pmk_len);
Jouni Malinen75ecf522011-06-27 15:19:46 -070010116
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010117 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010118 (params->pmkid &&
10119 nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) ||
10120 (params->bssid &&
10121 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) ||
10122 (params->ssid_len &&
10123 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
10124 (params->fils_cache_id &&
10125 nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2,
10126 params->fils_cache_id)) ||
Hai Shalomfdcde762020-04-02 11:19:20 -070010127 (params->pmk_lifetime &&
10128 nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME,
10129 params->pmk_lifetime)) ||
10130 (params->pmk_reauth_threshold &&
10131 nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD,
10132 params->pmk_reauth_threshold)) ||
Hai Shalom021b0b52019-04-10 11:17:58 -070010133 (cmd != NL80211_CMD_DEL_PMKSA &&
Sunil Ravi77d572f2023-01-17 23:58:31 +000010134 params->pmk_len && !skip_pmk &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010135 nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) {
Hai Shalom74f70d42019-02-11 14:42:39 -080010136 nl80211_nlmsg_clear(msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010137 nlmsg_free(msg);
10138 return -ENOBUFS;
10139 }
Jouni Malinen75ecf522011-06-27 15:19:46 -070010140
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010141 return send_and_recv_cmd(bss->drv, msg);
Jouni Malinen75ecf522011-06-27 15:19:46 -070010142}
10143
10144
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010145static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -070010146{
10147 struct i802_bss *bss = priv;
Sunil Ravi77d572f2023-01-17 23:58:31 +000010148 const size_t PMK_MAX_LEN = 64; /* current cfg80211 limit */
10149 const size_t LEGACY_PMK_MAX_LEN = 48; /* old cfg80211 limit */
10150 bool skip_pmk = params->pmk_len > PMK_MAX_LEN;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010151 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010152
10153 if (params->bssid)
10154 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR,
10155 MAC2STR(params->bssid));
10156 else if (params->fils_cache_id && params->ssid_len) {
10157 wpa_printf(MSG_DEBUG,
10158 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
10159 params->fils_cache_id[0], params->fils_cache_id[1],
10160 wpa_ssid_txt(params->ssid, params->ssid_len));
10161 }
10162
Sunil Ravi77d572f2023-01-17 23:58:31 +000010163 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, skip_pmk);
10164 /*
10165 * Try again by skipping PMK if the first attempt failed with ERANGE
10166 * error, PMK was not skipped, and PMK length is greater than the
10167 * legacy kernel maximum allowed limit.
10168 */
10169 if (ret == -ERANGE && !skip_pmk &&
10170 params->pmk_len > LEGACY_PMK_MAX_LEN)
10171 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, true);
Roshan Pius3a1667e2018-07-03 15:17:14 -070010172 if (ret < 0) {
10173 wpa_printf(MSG_DEBUG,
10174 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
10175 ret, strerror(-ret));
10176 }
10177
10178 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -070010179}
10180
10181
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010182static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params)
Jouni Malinen75ecf522011-06-27 15:19:46 -070010183{
10184 struct i802_bss *bss = priv;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010185 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010186
10187 if (params->bssid)
10188 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
10189 MAC2STR(params->bssid));
10190 else if (params->fils_cache_id && params->ssid_len) {
10191 wpa_printf(MSG_DEBUG,
10192 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
10193 params->fils_cache_id[0], params->fils_cache_id[1],
10194 wpa_ssid_txt(params->ssid, params->ssid_len));
10195 }
10196
Sunil Ravi77d572f2023-01-17 23:58:31 +000010197 ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params, true);
Roshan Pius3a1667e2018-07-03 15:17:14 -070010198 if (ret < 0) {
10199 wpa_printf(MSG_DEBUG,
10200 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
10201 ret, strerror(-ret));
10202 }
10203
10204 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -070010205}
10206
10207
10208static int nl80211_flush_pmkid(void *priv)
10209{
10210 struct i802_bss *bss = priv;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010211 struct nl_msg *msg;
10212
Jouni Malinen75ecf522011-06-27 15:19:46 -070010213 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010214 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA);
10215 if (!msg)
10216 return -ENOBUFS;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010217 return send_and_recv_cmd(bss->drv, msg);
Jouni Malinen75ecf522011-06-27 15:19:46 -070010218}
10219
10220
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010221static void clean_survey_results(struct survey_results *survey_results)
10222{
10223 struct freq_survey *survey, *tmp;
10224
10225 if (dl_list_empty(&survey_results->survey_list))
10226 return;
10227
10228 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
10229 struct freq_survey, list) {
10230 dl_list_del(&survey->list);
10231 os_free(survey);
10232 }
10233}
10234
10235
10236static void add_survey(struct nlattr **sinfo, u32 ifidx,
10237 struct dl_list *survey_list)
10238{
10239 struct freq_survey *survey;
10240
10241 survey = os_zalloc(sizeof(struct freq_survey));
10242 if (!survey)
10243 return;
10244
10245 survey->ifidx = ifidx;
10246 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
10247 survey->filled = 0;
10248
10249 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
10250 survey->nf = (int8_t)
10251 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
10252 survey->filled |= SURVEY_HAS_NF;
10253 }
10254
10255 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
10256 survey->channel_time =
10257 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
10258 survey->filled |= SURVEY_HAS_CHAN_TIME;
10259 }
10260
10261 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
10262 survey->channel_time_busy =
10263 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
10264 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
10265 }
10266
10267 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
10268 survey->channel_time_rx =
10269 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
10270 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
10271 }
10272
10273 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
10274 survey->channel_time_tx =
10275 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
10276 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
10277 }
10278
10279 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)",
10280 survey->freq,
10281 survey->nf,
10282 (unsigned long int) survey->channel_time,
10283 (unsigned long int) survey->channel_time_busy,
10284 (unsigned long int) survey->channel_time_tx,
10285 (unsigned long int) survey->channel_time_rx,
10286 survey->filled);
10287
10288 dl_list_add_tail(survey_list, &survey->list);
10289}
10290
10291
10292static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
10293 unsigned int freq_filter)
10294{
10295 if (!freq_filter)
10296 return 1;
10297
10298 return freq_filter == surveyed_freq;
10299}
10300
10301
10302static int survey_handler(struct nl_msg *msg, void *arg)
10303{
10304 struct nlattr *tb[NL80211_ATTR_MAX + 1];
10305 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10306 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
10307 struct survey_results *survey_results;
10308 u32 surveyed_freq = 0;
10309 u32 ifidx;
10310
10311 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
10312 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
10313 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
10314 };
10315
10316 survey_results = (struct survey_results *) arg;
10317
10318 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10319 genlmsg_attrlen(gnlh, 0), NULL);
10320
Dmitry Shmidt97672262014-02-03 13:02:54 -080010321 if (!tb[NL80211_ATTR_IFINDEX])
10322 return NL_SKIP;
10323
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010324 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
10325
10326 if (!tb[NL80211_ATTR_SURVEY_INFO])
10327 return NL_SKIP;
10328
10329 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
10330 tb[NL80211_ATTR_SURVEY_INFO],
10331 survey_policy))
10332 return NL_SKIP;
10333
10334 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
10335 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
10336 return NL_SKIP;
10337 }
10338
10339 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
10340
10341 if (!check_survey_ok(sinfo, surveyed_freq,
10342 survey_results->freq_filter))
10343 return NL_SKIP;
10344
10345 if (survey_results->freq_filter &&
10346 survey_results->freq_filter != surveyed_freq) {
10347 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
10348 surveyed_freq);
10349 return NL_SKIP;
10350 }
10351
10352 add_survey(sinfo, ifidx, &survey_results->survey_list);
10353
10354 return NL_SKIP;
10355}
10356
10357
10358static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
10359{
10360 struct i802_bss *bss = priv;
10361 struct wpa_driver_nl80211_data *drv = bss->drv;
10362 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010363 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010364 union wpa_event_data data;
10365 struct survey_results *survey_results;
10366
10367 os_memset(&data, 0, sizeof(data));
10368 survey_results = &data.survey_results;
10369
10370 dl_list_init(&survey_results->survey_list);
10371
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010372 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010373 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010374 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010375
10376 if (freq)
10377 data.survey_results.freq_filter = freq;
10378
10379 do {
10380 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010381 err = send_and_recv_resp(drv, msg, survey_handler,
10382 survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010383 } while (err > 0);
10384
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010385 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010386 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010387 else
10388 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010389
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010390 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010391 return err;
10392}
10393
10394
Dmitry Shmidt807291d2015-01-27 13:40:23 -080010395static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
10396 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010397 const u8 *replay_ctr)
10398{
10399 struct i802_bss *bss = priv;
10400 struct wpa_driver_nl80211_data *drv = bss->drv;
10401 struct nlattr *replay_nested;
10402 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010403 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010404
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010405 if (!drv->set_rekey_offload)
10406 return;
10407
10408 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010409 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
10410 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -080010411 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010412 (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010413 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
10414 replay_ctr)) {
10415 nl80211_nlmsg_clear(msg);
10416 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010417 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010418 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010419
10420 nla_nest_end(msg, replay_nested);
10421
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010422 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010423 if (ret == -EOPNOTSUPP) {
10424 wpa_printf(MSG_DEBUG,
10425 "nl80211: Driver does not support rekey offload");
10426 drv->set_rekey_offload = 0;
10427 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010428}
10429
10430
10431static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
10432 const u8 *addr, int qos)
10433{
10434 /* send data frame to poll STA and check whether
10435 * this frame is ACKed */
10436 struct {
10437 struct ieee80211_hdr hdr;
10438 u16 qos_ctl;
10439 } STRUCT_PACKED nulldata;
10440 size_t size;
10441
10442 /* Send data frame to poll STA and check whether this frame is ACKed */
10443
10444 os_memset(&nulldata, 0, sizeof(nulldata));
10445
10446 if (qos) {
10447 nulldata.hdr.frame_control =
10448 IEEE80211_FC(WLAN_FC_TYPE_DATA,
10449 WLAN_FC_STYPE_QOS_NULL);
10450 size = sizeof(nulldata);
10451 } else {
10452 nulldata.hdr.frame_control =
10453 IEEE80211_FC(WLAN_FC_TYPE_DATA,
10454 WLAN_FC_STYPE_NULLFUNC);
10455 size = sizeof(struct ieee80211_hdr);
10456 }
10457
10458 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
10459 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
10460 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
10461 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
10462
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010463 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010464 0, 0, NULL, 0, 0, -1) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010465 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
10466 "send poll frame");
10467}
10468
10469static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
10470 int qos)
10471{
10472 struct i802_bss *bss = priv;
10473 struct wpa_driver_nl80211_data *drv = bss->drv;
10474 struct nl_msg *msg;
Hai Shalom5f92bc92019-04-18 11:54:11 -070010475 u64 cookie;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010476 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010477
10478 if (!drv->poll_command_supported) {
10479 nl80211_send_null_frame(bss, own_addr, addr, qos);
10480 return;
10481 }
10482
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010483 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
10484 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
10485 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010486 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010487 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010488
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010489 ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010490 if (ret < 0) {
10491 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
10492 MACSTR " failed: ret=%d (%s)",
10493 MAC2STR(addr), ret, strerror(-ret));
Hai Shalom5f92bc92019-04-18 11:54:11 -070010494 } else {
10495 wpa_printf(MSG_DEBUG,
10496 "nl80211: Client probe request addr=" MACSTR
10497 " cookie=%llu", MAC2STR(addr),
10498 (long long unsigned int) cookie);
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010499 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010500}
10501
10502
10503static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
10504{
10505 struct nl_msg *msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010506 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010507
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010508 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
10509 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
10510 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
10511 nlmsg_free(msg);
10512 return -ENOBUFS;
10513 }
Roshan Pius3a1667e2018-07-03 15:17:14 -070010514
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010515 ret = send_and_recv_cmd(bss->drv, msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -070010516 if (ret < 0) {
10517 wpa_printf(MSG_DEBUG,
10518 "nl80211: Setting PS state %s failed: %d (%s)",
10519 enabled ? "enabled" : "disabled",
10520 ret, strerror(-ret));
10521 }
10522 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010523}
10524
10525
10526static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
10527 int ctwindow)
10528{
10529 struct i802_bss *bss = priv;
10530
10531 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
10532 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
10533
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010534 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080010535#ifdef ANDROID_P2P
10536 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010537#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010538 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010539#endif /* ANDROID_P2P */
10540 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010541
10542 if (legacy_ps == -1)
10543 return 0;
10544 if (legacy_ps != 0 && legacy_ps != 1)
10545 return -1; /* Not yet supported */
10546
10547 return nl80211_set_power_save(bss, legacy_ps);
10548}
10549
10550
Dmitry Shmidt051af732013-10-22 13:52:46 -070010551static int nl80211_start_radar_detection(void *priv,
10552 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010553{
10554 struct i802_bss *bss = priv;
10555 struct wpa_driver_nl80211_data *drv = bss->drv;
10556 struct nl_msg *msg;
10557 int ret;
10558
Hai Shalom81f62d82019-07-22 12:10:00 -070010559 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)",
10560 freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -070010561 freq->bandwidth, freq->center_freq1, freq->center_freq2);
10562
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010563 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
10564 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
10565 "detection");
10566 return -1;
10567 }
10568
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010569 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
10570 nl80211_put_freq_params(msg, freq) < 0) {
10571 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010572 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010573 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010574
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010575 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010576 if (ret == 0)
10577 return 0;
10578 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
10579 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -070010580 return -1;
10581}
10582
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010583#ifdef CONFIG_TDLS
10584
Hai Shalomc1a21442022-02-04 13:43:00 -080010585static int nl80211_add_peer_capab(struct nl_msg *msg,
10586 enum tdls_peer_capability capa)
10587{
10588 u32 peer_capab = 0;
10589
10590 if (!capa)
10591 return 0;
10592
10593 if (capa & TDLS_PEER_HT)
10594 peer_capab |= NL80211_TDLS_PEER_HT;
10595 if (capa & TDLS_PEER_VHT)
10596 peer_capab |= NL80211_TDLS_PEER_VHT;
10597 if (capa & TDLS_PEER_WMM)
10598 peer_capab |= NL80211_TDLS_PEER_WMM;
10599 if (capa & TDLS_PEER_HE)
10600 peer_capab |= NL80211_TDLS_PEER_HE;
10601
10602 return nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
10603 peer_capab);
10604}
10605
10606
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010607static int
10608nl80211_tdls_set_discovery_resp_link(struct wpa_driver_nl80211_data *drv,
10609 int link_id)
10610{
10611#ifdef CONFIG_DRIVER_NL80211_QCA
10612 struct nl_msg *msg;
10613 struct nlattr *params;
10614
10615 wpa_printf(MSG_DEBUG, "nl80211: TDLS Discovery Response Tx link ID %u",
10616 link_id);
10617
10618 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
10620 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10621 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10622 QCA_NL80211_VENDOR_SUBCMD_TDLS_DISC_RSP_EXT) ||
10623 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10624 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TDLS_DISC_RSP_EXT_TX_LINK,
10625 link_id)) {
10626 wpa_printf(MSG_ERROR,
10627 "%s: err in adding vendor_cmd and vendor_data",
10628 __func__);
10629 nlmsg_free(msg);
10630 return -1;
10631 }
10632 nla_nest_end(msg, params);
10633
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010634 return send_and_recv_cmd(drv, msg);
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010635#else /* CONFIG_DRIVER_NL80211_QCA */
10636 wpa_printf(MSG_ERROR,
10637 "nl80211: Setting TX link for TDLS Discovery Response not supported");
10638 return -1;
10639#endif /* CONFIG_DRIVER_NL80211_QCA */
10640}
10641
10642
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010643static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
10644 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -070010645 u32 peer_capab, int initiator, const u8 *buf,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010646 size_t len, int link_id)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010647{
10648 struct i802_bss *bss = priv;
10649 struct wpa_driver_nl80211_data *drv = bss->drv;
10650 struct nl_msg *msg;
10651
10652 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
10653 return -EOPNOTSUPP;
10654
10655 if (!dst)
10656 return -EINVAL;
10657
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010658 if (link_id >= 0 &&
10659 nl80211_tdls_set_discovery_resp_link(drv, link_id) < 0)
10660 return -EOPNOTSUPP;
10661
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010662 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
10663 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
10664 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
10665 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
Hai Shalomc1a21442022-02-04 13:43:00 -080010666 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code) ||
10667 nl80211_add_peer_capab(msg, peer_capab) ||
10668 (initiator && nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010669 nla_put(msg, NL80211_ATTR_IE, len, buf))
10670 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010671
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010672 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010673
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010674fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010675 nlmsg_free(msg);
10676 return -ENOBUFS;
10677}
10678
10679
10680static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
10681{
10682 struct i802_bss *bss = priv;
10683 struct wpa_driver_nl80211_data *drv = bss->drv;
10684 struct nl_msg *msg;
10685 enum nl80211_tdls_operation nl80211_oper;
Paul Stewart092955c2017-02-06 09:13:09 -080010686 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010687
10688 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
10689 return -EOPNOTSUPP;
10690
10691 switch (oper) {
10692 case TDLS_DISCOVERY_REQ:
10693 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
10694 break;
10695 case TDLS_SETUP:
10696 nl80211_oper = NL80211_TDLS_SETUP;
10697 break;
10698 case TDLS_TEARDOWN:
10699 nl80211_oper = NL80211_TDLS_TEARDOWN;
10700 break;
10701 case TDLS_ENABLE_LINK:
10702 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
10703 break;
10704 case TDLS_DISABLE_LINK:
10705 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
10706 break;
10707 case TDLS_ENABLE:
10708 return 0;
10709 case TDLS_DISABLE:
10710 return 0;
10711 default:
10712 return -EINVAL;
10713 }
10714
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010715 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
10716 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
10717 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
10718 nlmsg_free(msg);
10719 return -ENOBUFS;
10720 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010721
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010722 res = send_and_recv_cmd(drv, msg);
Paul Stewart092955c2017-02-06 09:13:09 -080010723 wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
10724 " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res,
10725 strerror(-res));
10726 return res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010727}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010728
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010729
10730static int
10731nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
10732 const struct hostapd_freq_params *params)
10733{
10734 struct i802_bss *bss = priv;
10735 struct wpa_driver_nl80211_data *drv = bss->drv;
10736 struct nl_msg *msg;
10737 int ret = -ENOBUFS;
10738
10739 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
10740 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
10741 return -EOPNOTSUPP;
10742
10743 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
10744 " oper_class=%u freq=%u",
10745 MAC2STR(addr), oper_class, params->freq);
10746 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
10747 if (!msg ||
10748 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10749 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
10750 (ret = nl80211_put_freq_params(msg, params))) {
10751 nlmsg_free(msg);
10752 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
10753 return ret;
10754 }
10755
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010756 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010757}
10758
10759
10760static int
10761nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
10762{
10763 struct i802_bss *bss = priv;
10764 struct wpa_driver_nl80211_data *drv = bss->drv;
10765 struct nl_msg *msg;
10766
10767 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
10768 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
10769 return -EOPNOTSUPP;
10770
10771 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
10772 MAC2STR(addr));
10773 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
10774 if (!msg ||
10775 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
10776 nlmsg_free(msg);
10777 wpa_printf(MSG_DEBUG,
10778 "nl80211: Could not build TDLS cancel chan switch");
10779 return -ENOBUFS;
10780 }
10781
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010782 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010783}
10784
10785#endif /* CONFIG TDLS */
10786
10787
Hai Shalomfdcde762020-04-02 11:19:20 -070010788static int driver_nl80211_set_key(void *priv,
10789 struct wpa_driver_set_key_params *params)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010790{
10791 struct i802_bss *bss = priv;
Hai Shalomfdcde762020-04-02 11:19:20 -070010792
10793 return wpa_driver_nl80211_set_key(bss, params);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010794}
10795
10796
10797static int driver_nl80211_scan2(void *priv,
10798 struct wpa_driver_scan_params *params)
10799{
10800 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010801#ifdef CONFIG_DRIVER_NL80211_QCA
10802 struct wpa_driver_nl80211_data *drv = bss->drv;
10803
10804 /*
10805 * Do a vendor specific scan if possible. If only_new_results is
10806 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
10807 * cannot be achieved through a vendor scan. The below condition may
10808 * need to be modified if new scan flags are added in the future whose
10809 * functionality can only be achieved through a normal scan.
10810 */
10811 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
10812 return wpa_driver_nl80211_vendor_scan(bss, params);
10813#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010814 return wpa_driver_nl80211_scan(bss, params);
10815}
10816
10817
10818static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
Hai Shalom81f62d82019-07-22 12:10:00 -070010819 u16 reason_code)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010820{
10821 struct i802_bss *bss = priv;
10822 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
10823}
10824
10825
10826static int driver_nl80211_authenticate(void *priv,
10827 struct wpa_driver_auth_params *params)
10828{
10829 struct i802_bss *bss = priv;
10830 return wpa_driver_nl80211_authenticate(bss, params);
10831}
10832
10833
10834static void driver_nl80211_deinit(void *priv)
10835{
10836 struct i802_bss *bss = priv;
10837 wpa_driver_nl80211_deinit(bss);
10838}
10839
10840
10841static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
10842 const char *ifname)
10843{
10844 struct i802_bss *bss = priv;
10845 return wpa_driver_nl80211_if_remove(bss, type, ifname);
10846}
10847
10848
10849static int driver_nl80211_send_mlme(void *priv, const u8 *data,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010850 size_t data_len, int noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010851 unsigned int freq,
Hai Shalomfdcde762020-04-02 11:19:20 -070010852 const u16 *csa_offs, size_t csa_offs_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010853 int no_encrypt, unsigned int wait,
10854 int link_id)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010855{
10856 struct i802_bss *bss = priv;
10857 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -070010858 freq, 0, 0, wait, csa_offs,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010859 csa_offs_len, no_encrypt, link_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010860}
10861
10862
10863static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
10864{
10865 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010866 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010867}
10868
10869
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010870static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010871 const char *ifname, int vlan_id,
10872 int link_id)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010873{
10874 struct i802_bss *bss = priv;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000010875 return i802_set_sta_vlan(bss, addr, ifname, vlan_id, link_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010876}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010877
10878
10879static int driver_nl80211_read_sta_data(void *priv,
10880 struct hostap_sta_driver_data *data,
10881 const u8 *addr)
10882{
10883 struct i802_bss *bss = priv;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -080010884
10885 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080010886 return i802_read_sta_data(bss, data, addr);
10887}
10888
10889
10890static int driver_nl80211_send_action(void *priv, unsigned int freq,
10891 unsigned int wait_time,
10892 const u8 *dst, const u8 *src,
10893 const u8 *bssid,
10894 const u8 *data, size_t data_len,
10895 int no_cck)
10896{
10897 struct i802_bss *bss = priv;
10898 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
10899 bssid, data, data_len, no_cck);
10900}
10901
10902
10903static int driver_nl80211_probe_req_report(void *priv, int report)
10904{
10905 struct i802_bss *bss = priv;
10906 return wpa_driver_nl80211_probe_req_report(bss, report);
10907}
10908
10909
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010910static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
10911 const u8 *ies, size_t ies_len)
10912{
10913 int ret;
10914 struct nl_msg *msg;
10915 struct i802_bss *bss = priv;
10916 struct wpa_driver_nl80211_data *drv = bss->drv;
10917 u16 mdid = WPA_GET_LE16(md);
10918
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010919 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010920 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
10921 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
10922 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
10923 nlmsg_free(msg);
10924 return -ENOBUFS;
10925 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010926
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010927 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010928 if (ret) {
10929 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
10930 "err=%d (%s)", ret, strerror(-ret));
10931 }
10932
10933 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -070010934}
10935
10936
Hai Shalom81f62d82019-07-22 12:10:00 -070010937static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac,
10938 u16 reason_code, const u8 *ie, size_t ie_len)
10939{
10940 int ret;
10941 struct nl_msg *msg;
10942 struct i802_bss *bss = priv;
10943 struct wpa_driver_nl80211_data *drv = bss->drv;
10944
10945 wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR
10946 " reason %u", MAC2STR(peer_mac), reason_code);
10947 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) ||
10948 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) ||
10949 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) ||
10950 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) {
10951 nlmsg_free(msg);
10952 return -ENOBUFS;
10953 }
10954
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010955 ret = send_and_recv_cmd(drv, msg);
Hai Shalom81f62d82019-07-22 12:10:00 -070010956 if (ret) {
10957 wpa_printf(MSG_DEBUG,
10958 "nl80211: update_dh_ie failed err=%d (%s)",
10959 ret, strerror(-ret));
10960 }
10961
10962 return ret;
10963}
10964
10965
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070010966static const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
Dmitry Shmidt34af3062013-07-11 10:46:32 -070010967{
10968 struct i802_bss *bss = priv;
10969 struct wpa_driver_nl80211_data *drv = bss->drv;
10970
10971 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
10972 return NULL;
10973
10974 return bss->addr;
10975}
10976
10977
Dmitry Shmidt56052862013-10-04 10:23:25 -070010978static const char * scan_state_str(enum scan_states scan_state)
10979{
10980 switch (scan_state) {
10981 case NO_SCAN:
10982 return "NO_SCAN";
10983 case SCAN_REQUESTED:
10984 return "SCAN_REQUESTED";
10985 case SCAN_STARTED:
10986 return "SCAN_STARTED";
10987 case SCAN_COMPLETED:
10988 return "SCAN_COMPLETED";
10989 case SCAN_ABORTED:
10990 return "SCAN_ABORTED";
10991 case SCHED_SCAN_STARTED:
10992 return "SCHED_SCAN_STARTED";
10993 case SCHED_SCAN_STOPPED:
10994 return "SCHED_SCAN_STOPPED";
10995 case SCHED_SCAN_RESULTS:
10996 return "SCHED_SCAN_RESULTS";
10997 }
10998
10999 return "??";
11000}
11001
11002
11003static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
11004{
11005 struct i802_bss *bss = priv;
11006 struct wpa_driver_nl80211_data *drv = bss->drv;
11007 int res;
11008 char *pos, *end;
Hai Shalom74f70d42019-02-11 14:42:39 -080011009 struct nl_msg *msg;
11010 char alpha2[3] = { 0, 0, 0 };
Dmitry Shmidt56052862013-10-04 10:23:25 -070011011
11012 pos = buf;
11013 end = buf + buflen;
11014
11015 res = os_snprintf(pos, end - pos,
11016 "ifindex=%d\n"
11017 "ifname=%s\n"
11018 "brname=%s\n"
11019 "addr=" MACSTR "\n"
11020 "freq=%d\n"
Hai Shalomc9e41a12018-07-31 14:41:42 -070011021 "%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -070011022 bss->ifindex,
11023 bss->ifname,
11024 bss->brname,
11025 MAC2STR(bss->addr),
Sunil Ravi036cec52023-03-29 11:35:17 -070011026 bss->flink->freq,
11027 bss->flink->beacon_set ? "beacon_set=1\n" : "",
Dmitry Shmidt56052862013-10-04 10:23:25 -070011028 bss->added_if_into_bridge ?
11029 "added_if_into_bridge=1\n" : "",
Hai Shalomc9e41a12018-07-31 14:41:42 -070011030 bss->already_in_bridge ? "already_in_bridge=1\n" : "",
Dmitry Shmidt56052862013-10-04 10:23:25 -070011031 bss->added_bridge ? "added_bridge=1\n" : "",
11032 bss->in_deinit ? "in_deinit=1\n" : "",
11033 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011034 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -070011035 return pos - buf;
11036 pos += res;
11037
11038 if (bss->wdev_id_set) {
11039 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
11040 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011041 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -070011042 return pos - buf;
11043 pos += res;
11044 }
11045
11046 res = os_snprintf(pos, end - pos,
11047 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011048 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -070011049 "drv_ifindex=%d\n"
11050 "operstate=%d\n"
11051 "scan_state=%s\n"
11052 "auth_bssid=" MACSTR "\n"
11053 "auth_attempt_bssid=" MACSTR "\n"
11054 "bssid=" MACSTR "\n"
11055 "prev_bssid=" MACSTR "\n"
11056 "associated=%d\n"
11057 "assoc_freq=%u\n"
11058 "monitor_sock=%d\n"
11059 "monitor_ifidx=%d\n"
11060 "monitor_refcount=%d\n"
11061 "last_mgmt_freq=%u\n"
11062 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011063 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -070011064 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011065 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -070011066 drv->ifindex,
11067 drv->operstate,
11068 scan_state_str(drv->scan_state),
11069 MAC2STR(drv->auth_bssid),
11070 MAC2STR(drv->auth_attempt_bssid),
11071 MAC2STR(drv->bssid),
11072 MAC2STR(drv->prev_bssid),
11073 drv->associated,
11074 drv->assoc_freq,
11075 drv->monitor_sock,
11076 drv->monitor_ifidx,
11077 drv->monitor_refcount,
11078 drv->last_mgmt_freq,
11079 drv->eapol_tx_sock,
11080 drv->ignore_if_down_event ?
11081 "ignore_if_down_event=1\n" : "",
11082 drv->scan_complete_events ?
11083 "scan_complete_events=1\n" : "",
11084 drv->disabled_11b_rates ?
11085 "disabled_11b_rates=1\n" : "",
11086 drv->pending_remain_on_chan ?
11087 "pending_remain_on_chan=1\n" : "",
11088 drv->in_interface_list ? "in_interface_list=1\n" : "",
11089 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
11090 drv->poll_command_supported ?
11091 "poll_command_supported=1\n" : "",
11092 drv->data_tx_status ? "data_tx_status=1\n" : "",
11093 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
11094 drv->retry_auth ? "retry_auth=1\n" : "",
11095 drv->use_monitor ? "use_monitor=1\n" : "",
11096 drv->ignore_next_local_disconnect ?
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011097 "ignore_next_local_disconnect\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -070011098 drv->ignore_next_local_deauth ?
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011099 "ignore_next_local_deauth\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011100 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -070011101 return pos - buf;
11102 pos += res;
11103
Sunil Ravi89eba102022-09-13 21:04:37 -070011104 if (drv->sta_mlo_info.valid_links) {
11105 int i;
11106 struct driver_sta_mlo_info *mlo = &drv->sta_mlo_info;
11107
11108 res = os_snprintf(pos, end - pos,
Sunil Ravi640215c2023-06-28 23:08:09 +000011109 "ap_mld_addr=" MACSTR "\n"
11110 "default_map=%d\n",
11111 MAC2STR(mlo->ap_mld_addr),
11112 mlo->default_map);
Sunil Ravi89eba102022-09-13 21:04:37 -070011113 if (os_snprintf_error(end - pos, res))
11114 return pos - buf;
11115 pos += res;
11116
Sunil Ravi88611412024-06-28 17:34:56 +000011117 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11118 if (!(mlo->valid_links & BIT(i)))
11119 continue;
11120
Sunil Ravi89eba102022-09-13 21:04:37 -070011121 res = os_snprintf(pos, end - pos,
11122 "link_addr[%u]=" MACSTR "\n"
11123 "link_bssid[%u]=" MACSTR "\n"
11124 "link_freq[%u]=%u\n",
11125 i, MAC2STR(mlo->links[i].addr),
11126 i, MAC2STR(mlo->links[i].bssid),
11127 i, mlo->links[i].freq);
11128 if (os_snprintf_error(end - pos, res))
11129 return pos - buf;
11130 pos += res;
Sunil Ravi640215c2023-06-28 23:08:09 +000011131
11132 if (!mlo->default_map) {
11133 res = os_snprintf(
11134 pos, end - pos,
11135 "uplink_map[%u]=%x\n"
11136 "downlink_map[%u]=%x\n",
11137 i, mlo->links[i].t2lmap.uplink,
11138 i, mlo->links[i].t2lmap.downlink);
11139 if (os_snprintf_error(end - pos, res))
11140 return pos - buf;
11141 pos += res;
11142 }
Sunil Ravi89eba102022-09-13 21:04:37 -070011143 }
11144 }
11145
Dmitry Shmidt56052862013-10-04 10:23:25 -070011146 if (drv->has_capability) {
11147 res = os_snprintf(pos, end - pos,
11148 "capa.key_mgmt=0x%x\n"
11149 "capa.enc=0x%x\n"
11150 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011151 "capa.flags=0x%llx\n"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011152 "capa.flags2=0x%llx\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011153 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -070011154 "capa.max_scan_ssids=%d\n"
11155 "capa.max_sched_scan_ssids=%d\n"
11156 "capa.sched_scan_supported=%d\n"
11157 "capa.max_match_sets=%d\n"
11158 "capa.max_remain_on_chan=%u\n"
11159 "capa.max_stations=%u\n"
11160 "capa.probe_resp_offloads=0x%x\n"
11161 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011162 "capa.num_multichan_concurrent=%u\n"
11163 "capa.mac_addr_rand_sched_scan_supported=%d\n"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011164 "capa.mac_addr_rand_scan_supported=%d\n"
11165 "capa.conc_capab=%u\n"
11166 "capa.max_conc_chan_2_4=%u\n"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011167 "capa.max_conc_chan_5_0=%u\n"
11168 "capa.max_sched_scan_plans=%u\n"
11169 "capa.max_sched_scan_plan_interval=%u\n"
Sunil Ravi77d572f2023-01-17 23:58:31 +000011170 "capa.max_sched_scan_plan_iterations=%u\n"
11171 "capa.mbssid_max_interfaces=%u\n"
11172 "capa.ema_max_periodicity=%u\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -070011173 drv->capa.key_mgmt,
11174 drv->capa.enc,
11175 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011176 (unsigned long long) drv->capa.flags,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011177 (unsigned long long) drv->capa.flags2,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011178 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -070011179 drv->capa.max_scan_ssids,
11180 drv->capa.max_sched_scan_ssids,
11181 drv->capa.sched_scan_supported,
11182 drv->capa.max_match_sets,
11183 drv->capa.max_remain_on_chan,
11184 drv->capa.max_stations,
11185 drv->capa.probe_resp_offloads,
11186 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011187 drv->capa.num_multichan_concurrent,
11188 drv->capa.mac_addr_rand_sched_scan_supported,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011189 drv->capa.mac_addr_rand_scan_supported,
11190 drv->capa.conc_capab,
11191 drv->capa.max_conc_chan_2_4,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011192 drv->capa.max_conc_chan_5_0,
11193 drv->capa.max_sched_scan_plans,
11194 drv->capa.max_sched_scan_plan_interval,
Sunil Ravi77d572f2023-01-17 23:58:31 +000011195 drv->capa.max_sched_scan_plan_iterations,
11196 drv->capa.mbssid_max_interfaces,
11197 drv->capa.ema_max_periodicity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011198 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -070011199 return pos - buf;
11200 pos += res;
11201 }
11202
Hai Shalom74f70d42019-02-11 14:42:39 -080011203 msg = nlmsg_alloc();
11204 if (msg &&
11205 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) &&
11206 nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011207 if (send_and_recv_resp(drv, msg, nl80211_get_country,
11208 alpha2) == 0 &&
Hai Shalom74f70d42019-02-11 14:42:39 -080011209 alpha2[0]) {
11210 res = os_snprintf(pos, end - pos, "country=%s\n",
11211 alpha2);
11212 if (os_snprintf_error(end - pos, res))
11213 return pos - buf;
11214 pos += res;
11215 }
11216 } else {
11217 nlmsg_free(msg);
11218 }
11219
Dmitry Shmidt56052862013-10-04 10:23:25 -070011220 return pos - buf;
11221}
11222
11223
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011224static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
11225{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011226 if ((settings->head &&
11227 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
11228 settings->head_len, settings->head)) ||
11229 (settings->tail &&
11230 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
11231 settings->tail_len, settings->tail)) ||
11232 (settings->beacon_ies &&
11233 nla_put(msg, NL80211_ATTR_IE,
11234 settings->beacon_ies_len, settings->beacon_ies)) ||
11235 (settings->proberesp_ies &&
11236 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
11237 settings->proberesp_ies_len, settings->proberesp_ies)) ||
11238 (settings->assocresp_ies &&
11239 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
11240 settings->assocresp_ies_len, settings->assocresp_ies)) ||
11241 (settings->probe_resp &&
11242 nla_put(msg, NL80211_ATTR_PROBE_RESP,
11243 settings->probe_resp_len, settings->probe_resp)))
11244 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011245
11246 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011247}
11248
11249
11250static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
11251{
11252 struct nl_msg *msg;
11253 struct i802_bss *bss = priv;
11254 struct wpa_driver_nl80211_data *drv = bss->drv;
11255 struct nlattr *beacon_csa;
11256 int ret = -ENOBUFS;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011257 int csa_off_len = 0;
11258 int i;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011259
Hai Shalomc1a21442022-02-04 13:43:00 -080011260 wpa_printf(MSG_DEBUG,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011261 "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d channel=%d sec_channel_offset=%d width=%d cf1=%d cf2=%d puncturing_bitmap=0x%04x link_id=%d%s%s%s)",
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011262 settings->cs_count, settings->block_tx,
Hai Shalomc1a21442022-02-04 13:43:00 -080011263 settings->freq_params.freq,
11264 settings->freq_params.channel,
11265 settings->freq_params.sec_channel_offset,
11266 settings->freq_params.bandwidth,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -080011267 settings->freq_params.center_freq1,
Hai Shalomc1a21442022-02-04 13:43:00 -080011268 settings->freq_params.center_freq2,
Sunil Ravi036cec52023-03-29 11:35:17 -070011269 settings->punct_bitmap,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011270 settings->link_id,
Hai Shalomc1a21442022-02-04 13:43:00 -080011271 settings->freq_params.ht_enabled ? " ht" : "",
11272 settings->freq_params.vht_enabled ? " vht" : "",
11273 settings->freq_params.he_enabled ? " he" : "");
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011274
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011275 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011276 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
11277 return -EOPNOTSUPP;
11278 }
11279
Roshan Pius3a1667e2018-07-03 15:17:14 -070011280 if (drv->nlmode != NL80211_IFTYPE_AP &&
11281 drv->nlmode != NL80211_IFTYPE_P2P_GO &&
11282 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011283 return -EOPNOTSUPP;
11284
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011285 /*
11286 * Remove empty counters, assuming Probe Response and Beacon frame
11287 * counters match. This implementation assumes that there are only two
11288 * counters.
11289 */
11290 if (settings->counter_offset_beacon[0] &&
11291 !settings->counter_offset_beacon[1]) {
11292 csa_off_len = 1;
11293 } else if (settings->counter_offset_beacon[1] &&
11294 !settings->counter_offset_beacon[0]) {
11295 csa_off_len = 1;
11296 settings->counter_offset_beacon[0] =
11297 settings->counter_offset_beacon[1];
11298 settings->counter_offset_presp[0] =
11299 settings->counter_offset_presp[1];
11300 } else if (settings->counter_offset_beacon[1] &&
11301 settings->counter_offset_beacon[0]) {
11302 csa_off_len = 2;
11303 } else {
11304 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
11305 return -EINVAL;
11306 }
11307
11308 /* Check CSA counters validity */
11309 if (drv->capa.max_csa_counters &&
11310 csa_off_len > drv->capa.max_csa_counters) {
11311 wpa_printf(MSG_ERROR,
11312 "nl80211: Too many CSA counters provided");
11313 return -EINVAL;
11314 }
11315
11316 if (!settings->beacon_csa.tail)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011317 return -EINVAL;
11318
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011319 for (i = 0; i < csa_off_len; i++) {
11320 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
11321 u16 csa_c_off_presp = settings->counter_offset_presp[i];
11322
11323 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
11324 (settings->beacon_csa.tail[csa_c_off_bcn] !=
11325 settings->cs_count))
11326 return -EINVAL;
11327
11328 if (settings->beacon_csa.probe_resp &&
11329 ((settings->beacon_csa.probe_resp_len <=
11330 csa_c_off_presp) ||
11331 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
11332 settings->cs_count)))
11333 return -EINVAL;
11334 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011335
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011336 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
11337 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
11338 settings->cs_count) ||
11339 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
11340 (settings->block_tx &&
Sunil Ravi036cec52023-03-29 11:35:17 -070011341 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) ||
11342 (settings->punct_bitmap &&
11343 nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011344 settings->punct_bitmap)) ||
11345 (settings->link_id != NL80211_DRV_LINK_ID_NA &&
11346 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, settings->link_id)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011347 goto error;
11348
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011349 /* beacon_after params */
11350 ret = set_beacon_data(msg, &settings->beacon_after);
11351 if (ret)
11352 goto error;
11353
11354 /* beacon_csa params */
11355 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
11356 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011357 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011358
11359 ret = set_beacon_data(msg, &settings->beacon_csa);
11360 if (ret)
11361 goto error;
11362
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011363 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
11364 csa_off_len * sizeof(u16),
11365 settings->counter_offset_beacon) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011366 (settings->beacon_csa.probe_resp &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011367 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
11368 csa_off_len * sizeof(u16),
11369 settings->counter_offset_presp)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011370 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011371
11372 nla_nest_end(msg, beacon_csa);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011373 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011374 if (ret) {
11375 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
11376 ret, strerror(-ret));
11377 }
11378 return ret;
11379
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011380fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011381 ret = -ENOBUFS;
11382error:
11383 nlmsg_free(msg);
11384 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
11385 return ret;
11386}
11387
11388
Sunil Ravia04bd252022-05-02 22:54:18 -070011389#ifdef CONFIG_IEEE80211AX
11390static int nl80211_switch_color(void *priv, struct cca_settings *settings)
11391{
11392 struct i802_bss *bss = priv;
11393 struct wpa_driver_nl80211_data *drv = bss->drv;
11394 struct nlattr *beacon_cca;
11395 struct nl_msg *msg;
11396 int ret = -ENOBUFS;
11397
11398 wpa_printf(MSG_DEBUG,
11399 "nl80211: Color change request (cca_count=%u color=%d)",
11400 settings->cca_count, settings->cca_color);
11401
11402 if (drv->nlmode != NL80211_IFTYPE_AP)
11403 return -EOPNOTSUPP;
11404
11405 if (!settings->beacon_cca.tail)
11406 return -EINVAL;
11407
11408 if (settings->beacon_cca.tail_len <= settings->counter_offset_beacon ||
11409 settings->beacon_cca.tail[settings->counter_offset_beacon] !=
11410 settings->cca_count)
11411 return -EINVAL;
11412
11413 if (settings->beacon_cca.probe_resp &&
11414 (settings->beacon_cca.probe_resp_len <=
11415 settings->counter_offset_presp ||
11416 settings->beacon_cca.probe_resp[settings->counter_offset_presp] !=
11417 settings->cca_count))
11418 return -EINVAL;
11419
11420 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_COLOR_CHANGE_REQUEST);
11421 if (!msg ||
11422 nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COUNT,
11423 settings->cca_count) ||
11424 nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COLOR,
11425 settings->cca_color))
11426 goto error;
11427
11428 /* beacon_after params */
11429 ret = set_beacon_data(msg, &settings->beacon_after);
11430 if (ret)
11431 goto error;
11432
11433 /* beacon_csa params */
11434 beacon_cca = nla_nest_start(msg, NL80211_ATTR_COLOR_CHANGE_ELEMS);
11435 if (!beacon_cca) {
11436 ret = -ENOBUFS;
11437 goto error;
11438 }
11439
11440 ret = set_beacon_data(msg, &settings->beacon_cca);
11441 if (ret)
11442 goto error;
11443
11444 if (nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_BEACON,
11445 settings->counter_offset_beacon) ||
11446 (settings->beacon_cca.probe_resp &&
11447 nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_PRESP,
11448 settings->counter_offset_presp))) {
11449 ret = -ENOBUFS;
11450 goto error;
11451 }
11452
11453 nla_nest_end(msg, beacon_cca);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011454 ret = send_and_recv_cmd(drv, msg);
Sunil Ravia04bd252022-05-02 22:54:18 -070011455 if (ret) {
11456 wpa_printf(MSG_DEBUG,
11457 "nl80211: switch_color failed err=%d (%s)",
11458 ret, strerror(-ret));
11459 }
11460 return ret;
11461
11462error:
11463 nlmsg_free(msg);
11464 wpa_printf(MSG_DEBUG, "nl80211: Could not build color switch request");
11465 return ret;
11466}
11467#endif /* CONFIG_IEEE80211AX */
11468
11469
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011470static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
11471 u8 user_priority, u16 admitted_time)
11472{
11473 struct i802_bss *bss = priv;
11474 struct wpa_driver_nl80211_data *drv = bss->drv;
11475 struct nl_msg *msg;
11476 int ret;
11477
11478 wpa_printf(MSG_DEBUG,
11479 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
11480 tsid, admitted_time, user_priority);
11481
11482 if (!is_sta_interface(drv->nlmode))
11483 return -ENOTSUP;
11484
11485 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
11486 if (!msg ||
11487 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
11488 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11489 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
11490 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
11491 nlmsg_free(msg);
11492 return -ENOBUFS;
11493 }
11494
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011495 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011496 if (ret)
11497 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
11498 ret, strerror(-ret));
11499 return ret;
11500}
11501
11502
11503static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
11504{
11505 struct i802_bss *bss = priv;
11506 struct wpa_driver_nl80211_data *drv = bss->drv;
11507 struct nl_msg *msg;
11508 int ret;
11509
11510 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
11511
11512 if (!is_sta_interface(drv->nlmode))
11513 return -ENOTSUP;
11514
11515 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
11516 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
11517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
11518 nlmsg_free(msg);
11519 return -ENOBUFS;
11520 }
11521
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011522 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011523 if (ret)
11524 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
11525 ret, strerror(-ret));
11526 return ret;
11527}
11528
11529
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011530#ifdef CONFIG_TESTING_OPTIONS
11531static int cmd_reply_handler(struct nl_msg *msg, void *arg)
11532{
11533 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
11534 struct wpabuf *buf = arg;
11535
11536 if (!buf)
11537 return NL_SKIP;
11538
11539 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
11540 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
11541 return NL_SKIP;
11542 }
11543
11544 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
11545 genlmsg_attrlen(gnlh, 0));
11546
11547 return NL_SKIP;
11548}
11549#endif /* CONFIG_TESTING_OPTIONS */
11550
11551
11552static int vendor_reply_handler(struct nl_msg *msg, void *arg)
11553{
11554 struct nlattr *tb[NL80211_ATTR_MAX + 1];
11555 struct nlattr *nl_vendor_reply, *nl;
11556 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
11557 struct wpabuf *buf = arg;
11558 int rem;
11559
11560 if (!buf)
11561 return NL_SKIP;
11562
11563 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
11564 genlmsg_attrlen(gnlh, 0), NULL);
11565 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
11566
11567 if (!nl_vendor_reply)
11568 return NL_SKIP;
11569
11570 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
11571 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
11572 return NL_SKIP;
11573 }
11574
11575 nla_for_each_nested(nl, nl_vendor_reply, rem) {
11576 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
11577 }
11578
11579 return NL_SKIP;
11580}
11581
11582
Hai Shalom60840252021-02-19 19:02:11 -080011583static bool is_cmd_with_nested_attrs(unsigned int vendor_id,
11584 unsigned int subcmd)
11585{
11586 if (vendor_id != OUI_QCA)
11587 return true;
11588
11589 switch (subcmd) {
11590 case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY:
11591 case QCA_NL80211_VENDOR_SUBCMD_STATS_EXT:
11592 case QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI:
11593 case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY:
11594 case QCA_NL80211_VENDOR_SUBCMD_SPECTRAL_SCAN_GET_STATUS:
11595 case QCA_NL80211_VENDOR_SUBCMD_NAN:
11596 return false;
11597 default:
11598 return true;
11599 }
11600}
11601
11602
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011603static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
11604 unsigned int subcmd, const u8 *data,
Hai Shalom60840252021-02-19 19:02:11 -080011605 size_t data_len, enum nested_attr nested_attr,
11606 struct wpabuf *buf)
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011607{
11608 struct i802_bss *bss = priv;
11609 struct wpa_driver_nl80211_data *drv = bss->drv;
11610 struct nl_msg *msg;
Hai Shalom60840252021-02-19 19:02:11 -080011611 int ret, nla_flag;
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011612
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011613#ifdef CONFIG_TESTING_OPTIONS
11614 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011615 msg = nlmsg_alloc();
11616 if (!msg)
11617 return -ENOMEM;
11618
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011619 nl80211_cmd(drv, msg, 0, subcmd);
11620 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
11621 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011622 goto fail;
Hai Shalomb755a2a2020-04-23 21:49:02 -070011623 /* This test vendor_cmd can be used with nl80211 commands that
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011624 * need the connect nl_sock, so use the variant that takes in
11625 * bss->nl_connect as the handle. */
11626 ret = send_and_recv(drv->global, bss->nl_connect, msg,
11627 cmd_reply_handler, buf, NULL, NULL, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011628 if (ret)
11629 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
11630 ret);
11631 return ret;
11632 }
11633#endif /* CONFIG_TESTING_OPTIONS */
11634
Hai Shalom60840252021-02-19 19:02:11 -080011635 if (nested_attr == NESTED_ATTR_USED)
11636 nla_flag = NLA_F_NESTED;
11637 else if (nested_attr == NESTED_ATTR_UNSPECIFIED &&
11638 is_cmd_with_nested_attrs(vendor_id, subcmd))
11639 nla_flag = NLA_F_NESTED;
11640 else
11641 nla_flag = 0;
11642
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011643 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
11644 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
11645 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
11646 (data &&
Hai Shalom60840252021-02-19 19:02:11 -080011647 nla_put(msg, nla_flag | NL80211_ATTR_VENDOR_DATA,
11648 data_len, data)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011649 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011650
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011651 ret = send_and_recv_resp(drv, msg, vendor_reply_handler, buf);
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011652 if (ret)
11653 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
11654 ret);
11655 return ret;
11656
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011657fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011658 nlmsg_free(msg);
11659 return -ENOBUFS;
11660}
11661
11662
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011663static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
11664 u8 qos_map_set_len)
11665{
11666 struct i802_bss *bss = priv;
11667 struct wpa_driver_nl80211_data *drv = bss->drv;
11668 struct nl_msg *msg;
11669 int ret;
11670
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011671 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
11672 qos_map_set, qos_map_set_len);
11673
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011674 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_QOS_MAP)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011675 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
11676 nlmsg_free(msg);
11677 return -ENOBUFS;
11678 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011679
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011680 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011681 if (ret)
11682 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
11683
11684 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011685}
11686
11687
Hai Shalomfdcde762020-04-02 11:19:20 -070011688static int get_wowlan_handler(struct nl_msg *msg, void *arg)
11689{
11690 struct nlattr *tb[NL80211_ATTR_MAX + 1];
11691 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
11692 int *wowlan_enabled = arg;
11693
11694 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
11695 genlmsg_attrlen(gnlh, 0), NULL);
11696
11697 *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS];
11698
11699 return NL_SKIP;
11700}
11701
11702
11703static int nl80211_get_wowlan(void *priv)
11704{
11705 struct i802_bss *bss = priv;
11706 struct wpa_driver_nl80211_data *drv = bss->drv;
11707 struct nl_msg *msg;
11708 int wowlan_enabled;
11709 int ret;
11710
11711 wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status");
11712
11713 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN);
11714
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011715 ret = send_and_recv_resp(drv, msg, get_wowlan_handler, &wowlan_enabled);
Hai Shalomfdcde762020-04-02 11:19:20 -070011716 if (ret) {
11717 wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed");
11718 return 0;
11719 }
11720
11721 wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s",
11722 wowlan_enabled ? "enabled" : "disabled");
11723
11724 return wowlan_enabled;
11725}
11726
11727
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011728static int nl80211_set_wowlan(void *priv,
11729 const struct wowlan_triggers *triggers)
11730{
11731 struct i802_bss *bss = priv;
11732 struct wpa_driver_nl80211_data *drv = bss->drv;
11733 struct nl_msg *msg;
11734 struct nlattr *wowlan_triggers;
11735 int ret;
11736
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011737 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
11738
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070011739 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011740 !(wowlan_triggers = nla_nest_start(msg,
11741 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
11742 (triggers->any &&
11743 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
11744 (triggers->disconnect &&
11745 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
11746 (triggers->magic_pkt &&
11747 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
11748 (triggers->gtk_rekey_failure &&
11749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
11750 (triggers->eap_identity_req &&
11751 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
11752 (triggers->four_way_handshake &&
11753 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
11754 (triggers->rfkill_release &&
11755 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
11756 nlmsg_free(msg);
11757 return -ENOBUFS;
11758 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011759
11760 nla_nest_end(msg, wowlan_triggers);
11761
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011762 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011763 if (ret)
11764 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
11765
11766 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070011767}
11768
11769
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011770#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011771static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
11772{
11773 struct i802_bss *bss = priv;
11774 struct wpa_driver_nl80211_data *drv = bss->drv;
11775 struct nl_msg *msg;
11776 struct nlattr *params;
11777
11778 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
11779
11780 if (!drv->roaming_vendor_cmd_avail) {
11781 wpa_printf(MSG_DEBUG,
11782 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
11783 return -1;
11784 }
11785
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011786 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11787 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11788 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11789 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
11790 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11791 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
11792 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
11793 QCA_ROAMING_NOT_ALLOWED) ||
11794 (bssid &&
11795 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
11796 nlmsg_free(msg);
11797 return -1;
11798 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011799 nla_nest_end(msg, params);
11800
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011801 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011802}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011803
11804
Roshan Pius3a1667e2018-07-03 15:17:14 -070011805static int nl80211_disable_fils(void *priv, int disable)
11806{
11807 struct i802_bss *bss = priv;
11808 struct wpa_driver_nl80211_data *drv = bss->drv;
11809 struct nl_msg *msg;
11810 struct nlattr *params;
11811
11812 wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable);
11813
11814 if (!drv->set_wifi_conf_vendor_cmd_avail)
11815 return -1;
11816
11817 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11818 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11819 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11820 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
11821 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11822 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS,
11823 disable)) {
11824 nlmsg_free(msg);
11825 return -1;
11826 }
11827 nla_nest_end(msg, params);
11828
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011829 return send_and_recv_cmd(drv, msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -070011830}
11831
11832
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011833/* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
11834#define WPA_SUPPLICANT_CLIENT_ID 1
11835
Hai Shalom899fcc72020-10-19 14:38:18 -070011836static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid,
11837 const u8 *bssid)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011838{
11839 struct i802_bss *bss = priv;
11840 struct wpa_driver_nl80211_data *drv = bss->drv;
11841 struct nl_msg *msg;
11842 struct nlattr *params, *nlbssids, *attr;
11843 unsigned int i;
11844
Hai Shalom899fcc72020-10-19 14:38:18 -070011845 wpa_printf(MSG_DEBUG,
11846 "nl80211: Set temporarily disallowed BSSIDs (num=%u)",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011847 num_bssid);
11848
11849 if (!drv->roam_vendor_cmd_avail)
11850 return -1;
11851
11852 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11853 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11854 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11855 QCA_NL80211_VENDOR_SUBCMD_ROAM) ||
11856 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11857 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
Hai Shalomc3565922019-10-28 11:58:20 -070011858 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011859 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID,
11860 WPA_SUPPLICANT_CLIENT_ID) ||
11861 nla_put_u32(msg,
11862 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
11863 num_bssid))
11864 goto fail;
11865
11866 nlbssids = nla_nest_start(
11867 msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
11868 if (!nlbssids)
11869 goto fail;
11870
11871 for (i = 0; i < num_bssid; i++) {
11872 attr = nla_nest_start(msg, i);
11873 if (!attr)
11874 goto fail;
11875 if (nla_put(msg,
11876 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
11877 ETH_ALEN, &bssid[i * ETH_ALEN]))
11878 goto fail;
11879 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i,
11880 MAC2STR(&bssid[i * ETH_ALEN]));
11881 nla_nest_end(msg, attr);
11882 }
11883 nla_nest_end(msg, nlbssids);
11884 nla_nest_end(msg, params);
11885
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011886 return send_and_recv_cmd(drv, msg);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011887
11888fail:
11889 nlmsg_free(msg);
11890 return -1;
11891}
11892
Hai Shalomc3565922019-10-28 11:58:20 -070011893
11894static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
11895{
11896 struct i802_bss *bss = priv;
11897 struct wpa_driver_nl80211_data *drv = bss->drv;
11898 struct nl_msg *msg;
11899 struct nlattr *params;
11900
11901 if (!drv->add_sta_node_vendor_cmd_avail)
11902 return -EOPNOTSUPP;
11903
11904 wpa_printf(MSG_DEBUG, "nl80211: Add STA node");
11905
11906 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
11907 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11908 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11909 QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) ||
11910 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11911 (addr &&
11912 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN,
11913 addr)) ||
11914 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO,
11915 auth_alg)) {
11916 nlmsg_free(msg);
11917 wpa_printf(MSG_ERROR,
11918 "%s: err in adding vendor_cmd and vendor_data",
11919 __func__);
11920 return -1;
11921 }
11922 nla_nest_end(msg, params);
11923
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011924 return send_and_recv_cmd(drv, msg);
Hai Shalomc3565922019-10-28 11:58:20 -070011925}
11926
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011927#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011928
11929
11930static int nl80211_set_mac_addr(void *priv, const u8 *addr)
11931{
11932 struct i802_bss *bss = priv;
11933 struct wpa_driver_nl80211_data *drv = bss->drv;
11934 int new_addr = addr != NULL;
Andy Kuoaba17c12022-04-14 16:05:31 +080011935#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali8a8f1002020-10-06 22:41:40 +053011936 struct nl_msg *msg;
11937 struct nlattr *params;
11938 int ret;
Andy Kuoaba17c12022-04-14 16:05:31 +080011939#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali8a8f1002020-10-06 22:41:40 +053011940 wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011941
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011942 if (TEST_FAIL())
11943 return -1;
Mir Ali8a8f1002020-10-06 22:41:40 +053011944 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
Andy Kuoaba17c12022-04-14 16:05:31 +080011945#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali8a8f1002020-10-06 22:41:40 +053011946 if (!addr ) {
11947 addr = drv->global->p2p_perm_addr;
11948 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011949
Mir Ali8a8f1002020-10-06 22:41:40 +053011950 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
11951 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) ||
11952 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Hai Shalomc1a21442022-02-04 13:43:00 -080011953 BRCM_VENDOR_SCMD_SET_MAC) ||
Mir Ali8a8f1002020-10-06 22:41:40 +053011954 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11955 nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) {
11956 wpa_printf(MSG_ERROR, "failed to put p2p randmac");
11957 nl80211_nlmsg_clear(msg);
11958 nlmsg_free(msg);
11959 return -ENOBUFS;
11960 }
11961 nla_nest_end(msg, params);
11962
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011963 ret = send_and_recv_cmd(drv, msg);
Mir Ali8a8f1002020-10-06 22:41:40 +053011964 if (ret) {
11965 wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)",
11966 ret, strerror(-ret));
11967 }
11968 memcpy(bss->addr, addr, ETH_ALEN);
11969 return ret;
11970#else
11971 return -ENOTSUP;
Andy Kuoaba17c12022-04-14 16:05:31 +080011972#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali8a8f1002020-10-06 22:41:40 +053011973 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011974 if (!addr)
11975 addr = drv->perm_addr;
11976
11977 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
11978 return -1;
11979
11980 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
11981 {
11982 wpa_printf(MSG_DEBUG,
Mir Ali8a8f1002020-10-06 22:41:40 +053011983 "nl80211: failed to set_mac_addr for %s to " MACSTR,
11984 bss->ifname, MAC2STR(addr));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011985 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
Mir Ali8a8f1002020-10-06 22:41:40 +053011986 1) < 0) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011987 wpa_printf(MSG_DEBUG,
Mir Ali8a8f1002020-10-06 22:41:40 +053011988 "nl80211: Could not restore interface UP after failed set_mac_addr");
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011989 }
11990 return -1;
11991 }
11992
11993 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011994 bss->ifname, MAC2STR(addr));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011995 drv->addr_changed = new_addr;
Sunil Ravi77d572f2023-01-17 23:58:31 +000011996 os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011997 os_memcpy(bss->addr, addr, ETH_ALEN);
11998
Hsiu-Chang Chen289286d2024-01-24 18:00:43 +080011999 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
12000 {
12001 wpa_printf(MSG_DEBUG,
12002 "nl80211: Could not restore interface UP after set_mac_addr");
12003 }
12004
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070012005 return 0;
12006}
12007
12008
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012009#ifdef CONFIG_MESH
12010
12011static int wpa_driver_nl80211_init_mesh(void *priv)
12012{
12013 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
12014 wpa_printf(MSG_INFO,
12015 "nl80211: Failed to set interface into mesh mode");
12016 return -1;
12017 }
12018 return 0;
12019}
12020
12021
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012022static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
12023 size_t mesh_id_len)
12024{
12025 if (mesh_id) {
Hai Shalom74f70d42019-02-11 14:42:39 -080012026 wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s",
12027 wpa_ssid_txt(mesh_id, mesh_id_len));
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012028 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
12029 }
12030
12031 return 0;
12032}
12033
12034
Dmitry Shmidtd13095b2016-08-22 14:02:19 -070012035static int nl80211_put_mesh_config(struct nl_msg *msg,
12036 struct wpa_driver_mesh_bss_params *params)
12037{
12038 struct nlattr *container;
12039
12040 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
12041 if (!container)
12042 return -1;
12043
12044 if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -070012045 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
12046 params->auto_plinks)) ||
Hai Shalomc1a21442022-02-04 13:43:00 -080012047 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) &&
12048 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
12049 params->forwarding)) ||
Dmitry Shmidtd13095b2016-08-22 14:02:19 -070012050 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
12051 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012052 params->max_peer_links)) ||
12053 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) &&
12054 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
12055 params->rssi_threshold)))
Dmitry Shmidtd13095b2016-08-22 14:02:19 -070012056 return -1;
12057
12058 /*
12059 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
12060 * the timer could disconnect stations even in that case.
12061 */
12062 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) &&
12063 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
12064 params->peer_link_timeout)) {
12065 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
12066 return -1;
12067 }
12068
12069 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) &&
12070 nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) {
12071 wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE");
12072 return -1;
12073 }
12074
12075 nla_nest_end(msg, container);
12076
12077 return 0;
12078}
12079
12080
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012081static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012082 struct wpa_driver_mesh_join_params *params)
12083{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012084 struct wpa_driver_nl80211_data *drv = bss->drv;
12085 struct nl_msg *msg;
12086 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080012087 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012088
12089 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
12090 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012091 if (!msg ||
12092 nl80211_put_freq_params(msg, &params->freq) ||
12093 nl80211_put_basic_rates(msg, params->basic_rates) ||
12094 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012095 nl80211_put_beacon_int(msg, params->beacon_int) ||
12096 nl80211_put_dtim_period(msg, params->dtim_period))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012097 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012098
12099 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
12100
Hai Shalom60840252021-02-19 19:02:11 -080012101 if (params->handle_dfs && nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS))
12102 goto fail;
12103
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012104 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
12105 if (!container)
12106 goto fail;
12107
12108 if (params->ies) {
12109 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
12110 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
12111 params->ies))
12112 goto fail;
12113 }
12114 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
12115 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
12116 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
12117 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
12118 goto fail;
12119 }
12120 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
12121 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
12122 goto fail;
12123 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
12124 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
12125 goto fail;
12126 nla_nest_end(msg, container);
12127
Dmitry Shmidtd13095b2016-08-22 14:02:19 -070012128 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
12129 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT;
12130 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS;
12131 if (nl80211_put_mesh_config(msg, &params->conf) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012132 goto fail;
12133
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012134 if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
12135 return -1;
12136 ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL,
12137 NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012138 msg = NULL;
12139 if (ret) {
12140 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
12141 ret, strerror(-ret));
12142 goto fail;
12143 }
12144 ret = 0;
Sunil Ravi036cec52023-03-29 11:35:17 -070012145 drv->assoc_freq = bss->flink->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012146 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
12147
12148fail:
12149 nlmsg_free(msg);
12150 return ret;
12151}
12152
12153
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012154static int
12155wpa_driver_nl80211_join_mesh(void *priv,
12156 struct wpa_driver_mesh_join_params *params)
12157{
12158 struct i802_bss *bss = priv;
12159 int ret, timeout;
12160
12161 timeout = params->conf.peer_link_timeout;
12162
12163 /* Disable kernel inactivity timer */
12164 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
12165 params->conf.peer_link_timeout = 0;
12166
12167 ret = nl80211_join_mesh(bss, params);
12168 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
12169 wpa_printf(MSG_DEBUG,
12170 "nl80211: Mesh join retry for peer_link_timeout");
12171 /*
12172 * Old kernel does not support setting
12173 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
12174 * into future from peer_link_timeout.
12175 */
12176 params->conf.peer_link_timeout = timeout + 60;
12177 ret = nl80211_join_mesh(priv, params);
12178 }
12179
12180 params->conf.peer_link_timeout = timeout;
12181 return ret;
12182}
12183
12184
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012185static int wpa_driver_nl80211_leave_mesh(void *priv)
12186{
12187 struct i802_bss *bss = priv;
12188 struct wpa_driver_nl80211_data *drv = bss->drv;
12189 struct nl_msg *msg;
12190 int ret;
12191
12192 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
12193 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012194 ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL,
12195 NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012196 if (ret) {
12197 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
12198 ret, strerror(-ret));
12199 } else {
12200 wpa_printf(MSG_DEBUG,
12201 "nl80211: mesh leave request send successfully");
Sunil Ravi036cec52023-03-29 11:35:17 -070012202 drv->first_bss->flink->freq = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012203 }
12204
Hai Shalomc1a21442022-02-04 13:43:00 -080012205 if (drv->start_mode_sta &&
12206 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012207 NL80211_IFTYPE_STATION)) {
12208 wpa_printf(MSG_INFO,
12209 "nl80211: Failed to set interface into station mode");
12210 }
12211 return ret;
12212}
12213
Hai Shalom81f62d82019-07-22 12:10:00 -070012214
12215static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth,
12216 size_t len)
12217{
12218 struct i802_bss *bss = priv;
12219 struct wpa_driver_nl80211_data *drv = bss->drv;
12220 struct nl_msg *msg;
12221 int ret;
12222
12223 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK);
12224 if (!msg ||
12225 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12226 nla_put(msg, NL80211_ATTR_FRAME, len, eth)) {
12227 nlmsg_free(msg);
12228 return -ENOBUFS;
12229 }
12230
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012231 ret = send_and_recv_cmd(drv, msg);
Hai Shalom81f62d82019-07-22 12:10:00 -070012232 if (ret) {
12233 wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR
12234 " failed: ret=%d (%s)",
12235 MAC2STR(addr), ret, strerror(-ret));
12236 } else {
12237 wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR
12238 " probed successfully", MAC2STR(addr));
12239 }
12240
12241 return ret;
12242}
12243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012244#endif /* CONFIG_MESH */
12245
12246
12247static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
12248 const u8 *ipaddr, int prefixlen,
12249 const u8 *addr)
12250{
Sunil Ravi88611412024-06-28 17:34:56 +000012251#ifdef CONFIG_LIBNL3_ROUTE
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012252 struct i802_bss *bss = priv;
12253 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi88611412024-06-28 17:34:56 +000012254 struct rtnl_neigh *rn;
12255 struct nl_addr *nl_ipaddr = NULL;
12256 struct nl_addr *nl_lladdr = NULL;
12257 int family, addrsize;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012258 int res;
12259
12260 if (!ipaddr || prefixlen == 0 || !addr)
12261 return -EINVAL;
12262
12263 if (bss->br_ifindex == 0) {
12264 wpa_printf(MSG_DEBUG,
12265 "nl80211: bridge must be set before adding an ip neigh to it");
12266 return -1;
12267 }
12268
12269 if (!drv->rtnl_sk) {
12270 wpa_printf(MSG_DEBUG,
12271 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
12272 return -1;
12273 }
12274
12275 if (version == 4) {
Sunil Ravi88611412024-06-28 17:34:56 +000012276 family = AF_INET;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012277 addrsize = 4;
12278 } else if (version == 6) {
Sunil Ravi88611412024-06-28 17:34:56 +000012279 family = AF_INET6;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012280 addrsize = 16;
12281 } else {
12282 return -EINVAL;
12283 }
12284
Sunil Ravi88611412024-06-28 17:34:56 +000012285 rn = rtnl_neigh_alloc();
12286 if (rn == NULL)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012287 return -ENOMEM;
12288
Sunil Ravi88611412024-06-28 17:34:56 +000012289 /* set the destination ip address for neigh */
12290 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
12291 if (nl_ipaddr == NULL) {
12292 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
12293 res = -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012294 goto errout;
Sunil Ravi88611412024-06-28 17:34:56 +000012295 }
12296 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
12297 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
12298 if (res) {
12299 wpa_printf(MSG_DEBUG,
12300 "nl80211: neigh set destination addr failed");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012301 goto errout;
Sunil Ravi88611412024-06-28 17:34:56 +000012302 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012303
Sunil Ravi88611412024-06-28 17:34:56 +000012304 /* set the corresponding lladdr for neigh */
12305 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
12306 if (nl_lladdr == NULL) {
12307 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
12308 res = -ENOMEM;
12309 goto errout;
12310 }
12311 rtnl_neigh_set_lladdr(rn, nl_lladdr);
12312
12313 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
12314 rtnl_neigh_set_state(rn, NUD_PERMANENT);
12315
12316 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012317 if (res) {
12318 wpa_printf(MSG_DEBUG,
12319 "nl80211: Adding bridge ip neigh failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070012320 nl_geterror(res));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012321 }
12322errout:
Sunil Ravi88611412024-06-28 17:34:56 +000012323 if (nl_lladdr)
12324 nl_addr_put(nl_lladdr);
12325 if (nl_ipaddr)
12326 nl_addr_put(nl_ipaddr);
12327 if (rn)
12328 rtnl_neigh_put(rn);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012329 return res;
Sunil Ravi88611412024-06-28 17:34:56 +000012330#else /* CONFIG_LIBNL3_ROUTE */
12331 return -1;
12332#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012333}
12334
12335
12336static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
12337 const u8 *ipaddr)
12338{
Sunil Ravi88611412024-06-28 17:34:56 +000012339#ifdef CONFIG_LIBNL3_ROUTE
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012340 struct i802_bss *bss = priv;
12341 struct wpa_driver_nl80211_data *drv = bss->drv;
Sunil Ravi88611412024-06-28 17:34:56 +000012342 struct rtnl_neigh *rn;
12343 struct nl_addr *nl_ipaddr;
12344 int family, addrsize;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012345 int res;
12346
12347 if (!ipaddr)
12348 return -EINVAL;
12349
12350 if (version == 4) {
Sunil Ravi88611412024-06-28 17:34:56 +000012351 family = AF_INET;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012352 addrsize = 4;
12353 } else if (version == 6) {
Sunil Ravi88611412024-06-28 17:34:56 +000012354 family = AF_INET6;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012355 addrsize = 16;
12356 } else {
12357 return -EINVAL;
12358 }
12359
12360 if (bss->br_ifindex == 0) {
12361 wpa_printf(MSG_DEBUG,
12362 "nl80211: bridge must be set to delete an ip neigh");
12363 return -1;
12364 }
12365
12366 if (!drv->rtnl_sk) {
12367 wpa_printf(MSG_DEBUG,
12368 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
12369 return -1;
12370 }
12371
Sunil Ravi88611412024-06-28 17:34:56 +000012372 rn = rtnl_neigh_alloc();
12373 if (rn == NULL)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012374 return -ENOMEM;
12375
Sunil Ravi88611412024-06-28 17:34:56 +000012376 /* set the destination ip address for neigh */
12377 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
12378 if (nl_ipaddr == NULL) {
12379 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
12380 res = -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012381 goto errout;
Sunil Ravi88611412024-06-28 17:34:56 +000012382 }
12383 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
12384 if (res) {
12385 wpa_printf(MSG_DEBUG,
12386 "nl80211: neigh set destination addr failed");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012387 goto errout;
Sunil Ravi88611412024-06-28 17:34:56 +000012388 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012389
Sunil Ravi88611412024-06-28 17:34:56 +000012390 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
12391
12392 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012393 if (res) {
12394 wpa_printf(MSG_DEBUG,
12395 "nl80211: Deleting bridge ip neigh failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070012396 nl_geterror(res));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012397 }
12398errout:
Sunil Ravi88611412024-06-28 17:34:56 +000012399 if (nl_ipaddr)
12400 nl_addr_put(nl_ipaddr);
12401 if (rn)
12402 rtnl_neigh_put(rn);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012403 return res;
Sunil Ravi88611412024-06-28 17:34:56 +000012404#else /* CONFIG_LIBNL3_ROUTE */
12405 return -1;
12406#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012407}
12408
12409
12410static int linux_write_system_file(const char *path, unsigned int val)
12411{
12412 char buf[50];
12413 int fd, len;
12414
12415 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
12416 if (os_snprintf_error(sizeof(buf), len))
12417 return -1;
12418
12419 fd = open(path, O_WRONLY);
12420 if (fd < 0)
12421 return -1;
12422
12423 if (write(fd, buf, len) < 0) {
12424 wpa_printf(MSG_DEBUG,
12425 "nl80211: Failed to write Linux system file: %s with the value of %d",
12426 path, val);
12427 close(fd);
12428 return -1;
12429 }
12430 close(fd);
12431
12432 return 0;
12433}
12434
12435
12436static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
12437{
12438 switch (attr) {
12439 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -070012440 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012441 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
12442 return "hairpin_mode";
Sunil Ravi036cec52023-03-29 11:35:17 -070012443 case DRV_BR_PORT_ATTR_MCAST2UCAST:
12444 return "multicast_to_unicast";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012445 }
12446
12447 return NULL;
12448}
12449
12450
12451static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
12452 unsigned int val)
12453{
12454 struct i802_bss *bss = priv;
12455 char path[128];
12456 const char *attr_txt;
12457
12458 attr_txt = drv_br_port_attr_str(attr);
12459 if (attr_txt == NULL)
12460 return -EINVAL;
12461
12462 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
12463 bss->ifname, attr_txt);
12464
12465 if (linux_write_system_file(path, val))
12466 return -1;
12467
12468 return 0;
12469}
12470
12471
12472static const char * drv_br_net_param_str(enum drv_br_net_param param)
12473{
12474 switch (param) {
12475 case DRV_BR_NET_PARAM_GARP_ACCEPT:
12476 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -070012477 default:
12478 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012479 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012480}
12481
12482
12483static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
12484 unsigned int val)
12485{
12486 struct i802_bss *bss = priv;
12487 char path[128];
12488 const char *param_txt;
12489 int ip_version = 4;
12490
Dmitry Shmidt83474442015-04-15 13:47:09 -070012491 if (param == DRV_BR_MULTICAST_SNOOPING) {
12492 os_snprintf(path, sizeof(path),
12493 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
12494 bss->brname);
12495 goto set_val;
12496 }
12497
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012498 param_txt = drv_br_net_param_str(param);
12499 if (param_txt == NULL)
12500 return -EINVAL;
12501
12502 switch (param) {
12503 case DRV_BR_NET_PARAM_GARP_ACCEPT:
12504 ip_version = 4;
12505 break;
12506 default:
12507 return -EINVAL;
12508 }
12509
12510 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
12511 ip_version, bss->brname, param_txt);
12512
Dmitry Shmidt83474442015-04-15 13:47:09 -070012513set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012514 if (linux_write_system_file(path, val))
12515 return -1;
12516
12517 return 0;
12518}
12519
12520
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012521#ifdef CONFIG_DRIVER_NL80211_QCA
12522
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012523static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
12524{
12525 switch (hw_mode) {
12526 case HOSTAPD_MODE_IEEE80211B:
12527 return QCA_ACS_MODE_IEEE80211B;
12528 case HOSTAPD_MODE_IEEE80211G:
12529 return QCA_ACS_MODE_IEEE80211G;
12530 case HOSTAPD_MODE_IEEE80211A:
12531 return QCA_ACS_MODE_IEEE80211A;
12532 case HOSTAPD_MODE_IEEE80211AD:
12533 return QCA_ACS_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -070012534 case HOSTAPD_MODE_IEEE80211ANY:
12535 return QCA_ACS_MODE_IEEE80211ANY;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012536 default:
12537 return -1;
12538 }
12539}
12540
12541
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012542static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list)
12543{
12544 int num_channels = 0, num_freqs;
12545 u8 *ch_list;
12546 enum hostapd_hw_mode hw_mode;
12547 int ret = 0;
12548 int i;
12549
12550 if (!freq_list)
12551 return 0;
12552
12553 num_freqs = int_array_len(freq_list);
12554 ch_list = os_malloc(sizeof(u8) * num_freqs);
12555 if (!ch_list)
12556 return -1;
12557
12558 for (i = 0; i < num_freqs; i++) {
12559 const int freq = freq_list[i];
12560
12561 if (freq == 0)
12562 break;
12563 /* Send 2.4 GHz and 5 GHz channels with
12564 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards
12565 * compatibility.
12566 */
12567 if (!(freq >= 2412 && freq <= 2484) &&
Hai Shalomc1a21442022-02-04 13:43:00 -080012568 !(freq >= 5180 && freq <= 5900) &&
12569 !(freq >= 5945 && freq <= 7115))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012570 continue;
12571 hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]);
12572 if (hw_mode != NUM_HOSTAPD_MODES)
12573 num_channels++;
12574 }
12575
12576 if (num_channels)
12577 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST,
12578 num_channels, ch_list);
12579
12580 os_free(ch_list);
12581 return ret;
12582}
12583
12584
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012585static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
12586{
12587 int i, len, ret;
12588 u32 *freqs;
12589
12590 if (!freq_list)
12591 return 0;
12592 len = int_array_len(freq_list);
12593 freqs = os_malloc(sizeof(u32) * len);
12594 if (!freqs)
12595 return -1;
12596 for (i = 0; i < len; i++)
12597 freqs[i] = freq_list[i];
12598 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
12599 sizeof(u32) * len, freqs);
12600 os_free(freqs);
12601 return ret;
12602}
12603
12604
Hai Shalomc1a21442022-02-04 13:43:00 -080012605static int nl80211_qca_do_acs(struct wpa_driver_nl80211_data *drv,
12606 struct drv_acs_params *params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012607{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012608 struct nl_msg *msg;
12609 struct nlattr *data;
12610 int ret;
12611 int mode;
12612
12613 mode = hw_mode_to_qca_acs(params->hw_mode);
12614 if (mode < 0)
12615 return -1;
12616
12617 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12618 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12619 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12620 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
12621 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12622 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
12623 (params->ht_enabled &&
12624 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
12625 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070012626 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
12627 (params->vht_enabled &&
12628 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
Sunil Ravia04bd252022-05-02 22:54:18 -070012629 (params->eht_enabled &&
12630 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EHT_ENABLED)) ||
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070012631 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
12632 params->ch_width) ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012633 add_acs_ch_list(msg, params->freq_list) ||
Hai Shalomfdcde762020-04-02 11:19:20 -070012634 add_acs_freq_list(msg, params->freq_list) ||
12635 (params->edmg_enabled &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012636 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED)) ||
12637 (params->link_id != NL80211_DRV_LINK_ID_NA &&
12638 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_LINK_ID,
12639 params->link_id))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012640 nlmsg_free(msg);
12641 return -ENOBUFS;
12642 }
12643 nla_nest_end(msg, data);
12644
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070012645 wpa_printf(MSG_DEBUG,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012646 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d EHT: %d BW: %d EDMG: %d, link_id: %d",
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070012647 params->hw_mode, params->ht_enabled, params->ht40_enabled,
Sunil Ravia04bd252022-05-02 22:54:18 -070012648 params->vht_enabled, params->eht_enabled, params->ch_width,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012649 params->edmg_enabled, params->link_id);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070012650
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012651 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012652 if (ret) {
12653 wpa_printf(MSG_DEBUG,
12654 "nl80211: Failed to invoke driver ACS function: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070012655 strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012656 }
12657 return ret;
12658}
12659
12660
Hai Shalom60840252021-02-19 19:02:11 -080012661static int nl80211_set_band(void *priv, u32 band_mask)
Ravi Joshie6ccb162015-07-16 17:45:41 -070012662{
12663 struct i802_bss *bss = priv;
12664 struct wpa_driver_nl80211_data *drv = bss->drv;
12665 struct nl_msg *msg;
12666 struct nlattr *data;
12667 int ret;
Hai Shalom60840252021-02-19 19:02:11 -080012668 enum qca_set_band qca_band_value;
12669 u32 qca_band_mask = QCA_SETBAND_AUTO;
Ravi Joshie6ccb162015-07-16 17:45:41 -070012670
Hai Shalom60840252021-02-19 19:02:11 -080012671 if (!drv->setband_vendor_cmd_avail ||
12672 (band_mask > (WPA_SETBAND_2G | WPA_SETBAND_5G | WPA_SETBAND_6G)))
Ravi Joshie6ccb162015-07-16 17:45:41 -070012673 return -1;
12674
Hai Shalom60840252021-02-19 19:02:11 -080012675 if (band_mask & WPA_SETBAND_5G)
12676 qca_band_mask |= QCA_SETBAND_5G;
12677 if (band_mask & WPA_SETBAND_2G)
12678 qca_band_mask |= QCA_SETBAND_2G;
12679 if (band_mask & WPA_SETBAND_6G)
12680 qca_band_mask |= QCA_SETBAND_6G;
12681
12682 /*
12683 * QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE is a legacy interface hence make
12684 * it suite to its values (AUTO/5G/2G) for backwards compatibility.
12685 */
12686 qca_band_value = ((qca_band_mask & QCA_SETBAND_5G) &&
12687 (qca_band_mask & QCA_SETBAND_2G)) ?
12688 QCA_SETBAND_AUTO :
12689 qca_band_mask & ~QCA_SETBAND_6G;
12690
12691 wpa_printf(MSG_DEBUG,
12692 "nl80211: QCA_BAND_MASK = 0x%x, QCA_BAND_VALUE = %d",
12693 qca_band_mask, qca_band_value);
Ravi Joshie6ccb162015-07-16 17:45:41 -070012694
12695 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12696 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12697 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12698 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
12699 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Hai Shalom60840252021-02-19 19:02:11 -080012700 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE,
12701 qca_band_value) ||
12702 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_MASK,
12703 qca_band_mask)) {
Ravi Joshie6ccb162015-07-16 17:45:41 -070012704 nlmsg_free(msg);
12705 return -ENOBUFS;
12706 }
12707 nla_nest_end(msg, data);
12708
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012709 ret = send_and_recv_cmd(drv, msg);
Ravi Joshie6ccb162015-07-16 17:45:41 -070012710 if (ret) {
12711 wpa_printf(MSG_DEBUG,
12712 "nl80211: Driver setband function failed: %s",
Hai Shalomfdcde762020-04-02 11:19:20 -070012713 strerror(-ret));
Ravi Joshie6ccb162015-07-16 17:45:41 -070012714 }
12715 return ret;
12716}
12717
12718
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012719struct nl80211_pcl {
12720 unsigned int num;
Sunil8cd6f4d2022-06-28 18:40:46 +000012721 struct weighted_pcl *freq_list;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012722};
12723
Sunil8cd6f4d2022-06-28 18:40:46 +000012724static void get_pcl_attr_values(struct weighted_pcl *wpcl, struct nlattr *nl[])
12725{
12726 if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ])
12727 wpcl->freq = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]);
12728 if (nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT])
12729 wpcl->weight = nla_get_u8(nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]);
12730 if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]) {
12731 u32 flags = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]);
12732
12733 wpcl->flag = 0;
12734 if (flags & BIT(0))
12735 wpcl->flag |= WEIGHTED_PCL_GO;
12736 if (flags & BIT(1))
12737 wpcl->flag |= WEIGHTED_PCL_CLI;
12738 if (flags & BIT(2))
12739 wpcl->flag |= WEIGHTED_PCL_MUST_CONSIDER;
12740 if (flags & BIT(3))
12741 wpcl->flag |= WEIGHTED_PCL_EXCLUDE;
12742 } else {
12743 wpcl->flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
12744 }
12745}
12746
12747
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012748static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
12749{
12750 struct nlattr *tb[NL80211_ATTR_MAX + 1];
12751 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
12752 struct nl80211_pcl *param = arg;
12753 struct nlattr *nl_vend, *attr;
12754 enum qca_iface_type iface_type;
12755 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
Sunil8cd6f4d2022-06-28 18:40:46 +000012756 struct nlattr *nl_pcl[QCA_WLAN_VENDOR_ATTR_PCL_MAX + 1];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012757 unsigned int num, max_num;
12758 u32 *freqs;
12759
12760 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
12761 genlmsg_attrlen(gnlh, 0), NULL);
12762
12763 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
12764 if (!nl_vend)
12765 return NL_SKIP;
12766
12767 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
12768 nla_data(nl_vend), nla_len(nl_vend), NULL);
12769
12770 attr = tb_vendor[
12771 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
12772 if (!attr) {
12773 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
12774 param->num = 0;
12775 return NL_SKIP;
12776 }
12777
12778 iface_type = (enum qca_iface_type) nla_get_u32(attr);
12779 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
12780 iface_type);
12781
Sunil8cd6f4d2022-06-28 18:40:46 +000012782 attr = tb_vendor[
12783 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_WEIGHED_PCL];
12784 if (attr) {
12785 int rem;
12786 struct nlattr *wpcl = attr;
12787 unsigned int i;
12788
12789 num = 0;
12790 nla_for_each_nested(attr, wpcl, rem) {
12791 if (num == param->num)
12792 break; /* not enough room for all entries */
12793 if (nla_parse(nl_pcl, QCA_WLAN_VENDOR_ATTR_PCL_MAX,
12794 nla_data(attr), nla_len(attr), NULL)) {
12795 wpa_printf(MSG_ERROR,
12796 "nl80211: Failed to parse PCL info");
12797 param->num = 0;
12798 return NL_SKIP;
12799 }
12800 get_pcl_attr_values(&param->freq_list[num], nl_pcl);
12801 num++;
12802 }
12803 param->num = num;
12804
12805 /* Sort frequencies based on their weight */
12806 for (i = 0; i < num; i++) {
12807 unsigned int j;
12808
12809 for (j = i + 1; j < num; j++) {
12810 if (param->freq_list[i].weight <
12811 param->freq_list[j].weight) {
12812 struct weighted_pcl tmp;
12813
12814 tmp = param->freq_list[i];
12815 param->freq_list[i] =
12816 param->freq_list[j];
12817 param->freq_list[j] = tmp;
12818 }
12819 }
12820 }
12821 } else if (tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]) {
12822 wpa_printf(MSG_DEBUG,
12823 "nl80211: Driver does not provide weighted PCL; use the non-weighted variant");
12824 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
12825 /*
12826 * param->num has the maximum number of entries for which there
12827 * is room in the freq_list provided by the caller.
12828 */
12829 freqs = nla_data(attr);
12830 max_num = nla_len(attr) / sizeof(u32);
12831 if (max_num > param->num)
12832 max_num = param->num;
12833 for (num = 0; num < max_num; num++) {
12834 param->freq_list[num].freq = freqs[num];
12835 param->freq_list[num].flag =
12836 WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
12837 }
12838 param->num = num;
12839 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012840 wpa_printf(MSG_ERROR,
12841 "nl80211: preferred_freq_list couldn't be found");
12842 param->num = 0;
12843 return NL_SKIP;
12844 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012845 return NL_SKIP;
12846}
12847
12848
12849static int nl80211_get_pref_freq_list(void *priv,
12850 enum wpa_driver_if_type if_type,
12851 unsigned int *num,
Sunil8cd6f4d2022-06-28 18:40:46 +000012852 struct weighted_pcl *freq_list)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012853{
12854 struct i802_bss *bss = priv;
12855 struct wpa_driver_nl80211_data *drv = bss->drv;
12856 struct nl_msg *msg;
12857 int ret;
12858 unsigned int i;
12859 struct nlattr *params;
12860 struct nl80211_pcl param;
12861 enum qca_iface_type iface_type;
12862
12863 if (!drv->get_pref_freq_list)
12864 return -1;
12865
12866 switch (if_type) {
12867 case WPA_IF_STATION:
12868 iface_type = QCA_IFACE_TYPE_STA;
12869 break;
12870 case WPA_IF_AP_BSS:
12871 iface_type = QCA_IFACE_TYPE_AP;
12872 break;
12873 case WPA_IF_P2P_GO:
12874 iface_type = QCA_IFACE_TYPE_P2P_GO;
12875 break;
12876 case WPA_IF_P2P_CLIENT:
12877 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
12878 break;
12879 case WPA_IF_IBSS:
12880 iface_type = QCA_IFACE_TYPE_IBSS;
12881 break;
12882 case WPA_IF_TDLS:
12883 iface_type = QCA_IFACE_TYPE_TDLS;
12884 break;
12885 default:
12886 return -1;
12887 }
12888
12889 param.num = *num;
12890 param.freq_list = freq_list;
12891
12892 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12893 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
12894 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12895 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12896 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
12897 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12898 nla_put_u32(msg,
12899 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
12900 iface_type)) {
12901 wpa_printf(MSG_ERROR,
12902 "%s: err in adding vendor_cmd and vendor_data",
12903 __func__);
12904 nlmsg_free(msg);
12905 return -1;
12906 }
12907 nla_nest_end(msg, params);
12908
Sunil8cd6f4d2022-06-28 18:40:46 +000012909 if (freq_list)
12910 os_memset(freq_list, 0, *num * sizeof(struct weighted_pcl));
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012911 ret = send_and_recv_resp(drv, msg, preferred_freq_info_handler, &param);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012912 if (ret) {
12913 wpa_printf(MSG_ERROR,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012914 "%s: err in send_and_recv_resp", __func__);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012915 return ret;
12916 }
12917
12918 *num = param.num;
12919
12920 for (i = 0; i < *num; i++) {
Sunil8cd6f4d2022-06-28 18:40:46 +000012921 wpa_printf(MSG_DEBUG,
12922 "nl80211: preferred_channel_list[%d]=%d[%d]:0x%x",
12923 i, freq_list[i].freq, freq_list[i].weight,
12924 freq_list[i].flag);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012925 }
12926
12927 return 0;
12928}
12929
12930
12931static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
12932{
12933 struct i802_bss *bss = priv;
12934 struct wpa_driver_nl80211_data *drv = bss->drv;
12935 struct nl_msg *msg;
12936 int ret;
12937 struct nlattr *params;
12938
12939 if (!drv->set_prob_oper_freq)
12940 return -1;
12941
12942 wpa_printf(MSG_DEBUG,
12943 "nl80211: Set P2P probable operating freq %u for ifindex %d",
12944 freq, bss->ifindex);
12945
12946 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12947 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12948 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12949 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
12950 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12951 nla_put_u32(msg,
12952 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
12953 QCA_IFACE_TYPE_P2P_CLIENT) ||
12954 nla_put_u32(msg,
12955 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
12956 freq)) {
12957 wpa_printf(MSG_ERROR,
12958 "%s: err in adding vendor_cmd and vendor_data",
12959 __func__);
12960 nlmsg_free(msg);
12961 return -1;
12962 }
12963 nla_nest_end(msg, params);
12964
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012965 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012966 msg = NULL;
12967 if (ret) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012968 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_cmd",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012969 __func__);
12970 return ret;
12971 }
12972 nlmsg_free(msg);
12973 return 0;
12974}
12975
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012976
12977static int nl80211_p2p_lo_start(void *priv, unsigned int freq,
12978 unsigned int period, unsigned int interval,
12979 unsigned int count, const u8 *device_types,
12980 size_t dev_types_len,
12981 const u8 *ies, size_t ies_len)
12982{
12983 struct i802_bss *bss = priv;
12984 struct wpa_driver_nl80211_data *drv = bss->drv;
12985 struct nl_msg *msg;
12986 struct nlattr *container;
12987 int ret;
12988
12989 wpa_printf(MSG_DEBUG,
12990 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
12991 freq, period, interval, count);
12992
12993 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
12994 return -1;
12995
12996 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
12997 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12998 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12999 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START))
13000 goto fail;
13001
13002 container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13003 if (!container)
13004 goto fail;
13005
13006 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL,
13007 freq) ||
13008 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD,
13009 period) ||
13010 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL,
13011 interval) ||
13012 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT,
13013 count) ||
13014 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES,
13015 dev_types_len, device_types) ||
13016 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE,
13017 ies_len, ies))
13018 goto fail;
13019
13020 nla_nest_end(msg, container);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013021 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070013022 msg = NULL;
13023 if (ret) {
13024 wpa_printf(MSG_DEBUG,
13025 "nl80211: Failed to send P2P Listen offload vendor command");
13026 goto fail;
13027 }
13028
13029 return 0;
13030
13031fail:
13032 nlmsg_free(msg);
13033 return -1;
13034}
13035
13036
13037static int nl80211_p2p_lo_stop(void *priv)
13038{
13039 struct i802_bss *bss = priv;
13040 struct wpa_driver_nl80211_data *drv = bss->drv;
13041 struct nl_msg *msg;
13042
13043 wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload");
13044
13045 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
13046 return -1;
13047
13048 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13049 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13050 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13051 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) {
13052 nlmsg_free(msg);
13053 return -1;
13054 }
13055
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013056 return send_and_recv_cmd(drv, msg);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070013057}
13058
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080013059
13060static int nl80211_set_tdls_mode(void *priv, int tdls_external_control)
13061{
13062 struct i802_bss *bss = priv;
13063 struct wpa_driver_nl80211_data *drv = bss->drv;
13064 struct nl_msg *msg;
13065 struct nlattr *params;
13066 int ret;
13067 u32 tdls_mode;
13068
13069 wpa_printf(MSG_DEBUG,
13070 "nl80211: Set TDKS mode: tdls_external_control=%d",
13071 tdls_external_control);
13072
13073 if (tdls_external_control == 1)
13074 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT |
13075 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL;
13076 else
13077 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT;
13078
13079 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13080 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13081 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13082 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS))
13083 goto fail;
13084
13085 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13086 if (!params)
13087 goto fail;
13088
13089 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE,
13090 tdls_mode))
13091 goto fail;
13092
13093 nla_nest_end(msg, params);
13094
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013095 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080013096 msg = NULL;
13097 if (ret) {
13098 wpa_printf(MSG_ERROR,
13099 "nl80211: Set TDLS mode failed: ret=%d (%s)",
13100 ret, strerror(-ret));
13101 goto fail;
13102 }
13103 return 0;
13104fail:
13105 nlmsg_free(msg);
13106 return -1;
13107}
13108
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013109
13110#ifdef CONFIG_MBO
13111
13112static enum mbo_transition_reject_reason
13113nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status)
13114{
13115 switch (status) {
13116 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED:
13117 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS;
13118 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED:
13119 return MBO_TRANSITION_REJECT_REASON_DELAY;
13120 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY:
13121 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY;
13122 case QCA_STATUS_REJECT_LOW_RSSI:
13123 return MBO_TRANSITION_REJECT_REASON_RSSI;
13124 case QCA_STATUS_REJECT_HIGH_INTERFERENCE:
13125 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE;
13126 case QCA_STATUS_REJECT_UNKNOWN:
13127 default:
13128 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
13129 }
13130}
13131
13132
13133static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate,
13134 struct nlattr *tb[], int num)
13135{
13136 enum qca_wlan_btm_candidate_status status;
13137 char buf[50];
13138
13139 os_memcpy(candidate->bssid,
13140 nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]),
13141 ETH_ALEN);
13142
13143 status = nla_get_u32(
13144 tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]);
13145 candidate->is_accept = status == QCA_STATUS_ACCEPT;
13146 candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status);
13147
13148 if (candidate->is_accept)
13149 os_snprintf(buf, sizeof(buf), "Accepted");
13150 else
13151 os_snprintf(buf, sizeof(buf),
13152 "Rejected, Reject_reason: %d",
13153 candidate->reject_reason);
13154 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s",
13155 num, MAC2STR(candidate->bssid), buf);
13156}
13157
13158
13159static int
13160nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg)
13161{
13162 struct wpa_bss_candidate_info *info = arg;
13163 struct candidate_list *candidate = info->candidates;
13164 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
13165 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
13166 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1];
13167 static struct nla_policy policy[
13168 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = {
13169 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = {
13170 .minlen = ETH_ALEN
13171 },
13172 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = {
13173 .type = NLA_U32,
13174 },
13175 };
13176 struct nlattr *attr;
13177 int rem;
13178 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
13179 u8 num;
13180
13181 num = info->num; /* number of candidates sent to driver */
13182 info->num = 0;
13183 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
13184 genlmsg_attrlen(gnlh, 0), NULL);
13185
13186 if (!tb_msg[NL80211_ATTR_VENDOR_DATA] ||
13187 nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
13188 tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) ||
13189 !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO])
13190 return NL_SKIP;
13191
13192 wpa_printf(MSG_DEBUG,
13193 "nl80211: WNM Candidate list received from driver");
13194 nla_for_each_nested(attr,
13195 tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO],
13196 rem) {
13197 if (info->num >= num ||
13198 nla_parse_nested(
13199 tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX,
13200 attr, policy) ||
13201 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] ||
13202 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS])
13203 break;
13204
13205 nl80211_parse_btm_candidate_info(candidate, tb, info->num);
13206
13207 candidate++;
13208 info->num++;
13209 }
13210
13211 return NL_SKIP;
13212}
13213
13214
13215static struct wpa_bss_candidate_info *
13216nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params)
13217{
13218 struct i802_bss *bss = priv;
13219 struct wpa_driver_nl80211_data *drv = bss->drv;
13220 struct nl_msg *msg;
13221 struct nlattr *attr, *attr1, *attr2;
13222 struct wpa_bss_candidate_info *info;
13223 u8 i;
13224 int ret;
13225 u8 *pos;
13226
13227 if (!drv->fetch_bss_trans_status)
13228 return NULL;
13229
13230 info = os_zalloc(sizeof(*info));
13231 if (!info)
13232 return NULL;
13233 /* Allocate memory for number of candidates sent to driver */
13234 info->candidates = os_calloc(params->n_candidates,
13235 sizeof(*info->candidates));
13236 if (!info->candidates) {
13237 os_free(info);
13238 return NULL;
13239 }
13240
13241 /* Copy the number of candidates being sent to driver. This is used in
13242 * nl80211_get_bss_transition_status_handler() to limit the number of
13243 * candidates that can be populated in info->candidates and will be
13244 * later overwritten with the actual number of candidates received from
13245 * the driver.
13246 */
13247 info->num = params->n_candidates;
13248
13249 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13250 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13251 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13252 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS))
13253 goto fail;
13254
13255 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13256 if (!attr)
13257 goto fail;
13258
13259 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON,
13260 params->mbo_transition_reason))
13261 goto fail;
13262
13263 attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO);
13264 if (!attr1)
13265 goto fail;
13266
13267 wpa_printf(MSG_DEBUG,
13268 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
13269 params->mbo_transition_reason, params->n_candidates);
13270 pos = params->bssid;
13271 for (i = 0; i < params->n_candidates; i++) {
13272 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i,
13273 MAC2STR(pos));
13274 attr2 = nla_nest_start(msg, i);
13275 if (!attr2 ||
13276 nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID,
13277 ETH_ALEN, pos))
13278 goto fail;
13279 pos += ETH_ALEN;
13280 nla_nest_end(msg, attr2);
13281 }
13282
13283 nla_nest_end(msg, attr1);
13284 nla_nest_end(msg, attr);
13285
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013286 ret = send_and_recv_resp(drv, msg,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013287 nl80211_get_bss_transition_status_handler,
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013288 info);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013289 msg = NULL;
13290 if (ret) {
13291 wpa_printf(MSG_ERROR,
13292 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
13293 ret, strerror(-ret));
13294 goto fail;
13295 }
13296 return info;
13297
13298fail:
13299 nlmsg_free(msg);
13300 os_free(info->candidates);
13301 os_free(info);
13302 return NULL;
13303}
13304
13305
13306/**
13307 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
13308 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
13309 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
13310 * Returns: 0 on success, -1 on failure
13311 */
13312static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow)
13313{
13314 struct i802_bss *bss = priv;
13315 struct wpa_driver_nl80211_data *drv = bss->drv;
13316 struct nl_msg *msg;
13317 struct nlattr *attr;
13318 int ret = -1;
13319
13320 if (!drv->set_wifi_conf_vendor_cmd_avail)
13321 return -1;
13322
13323 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13324 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13325 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13326 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION))
13327 goto fail;
13328
13329 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13330 if (!attr)
13331 goto fail;
13332
13333 wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d",
13334 ignore_disallow);
13335 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED,
13336 ignore_disallow))
13337 goto fail;
13338
13339 nla_nest_end(msg, attr);
13340
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013341 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013342 msg = NULL;
13343 if (ret) {
13344 wpa_printf(MSG_ERROR,
13345 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
13346 ret, strerror(-ret));
13347 goto fail;
13348 }
13349
13350fail:
13351 nlmsg_free(msg);
13352 return ret;
13353}
13354
13355#endif /* CONFIG_MBO */
13356
Sunil Ravi89eba102022-09-13 21:04:37 -070013357
13358#ifdef CONFIG_PASN
13359
13360static int nl80211_send_pasn_resp(void *priv, struct pasn_auth *params)
13361{
13362 unsigned int i;
13363 struct i802_bss *bss = priv;
13364 struct nl_msg *msg = NULL;
13365 struct nlattr *nlpeers, *attr, *attr1;
13366 struct wpa_driver_nl80211_data *drv = bss->drv;
13367
13368 wpa_dbg(drv->ctx, MSG_DEBUG,
13369 "nl80211: PASN authentication response for %d entries",
13370 params->num_peers);
13371 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR);
13372 if (!msg ||
13373 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13374 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13375 QCA_NL80211_VENDOR_SUBCMD_PASN))
13376 goto fail;
13377
13378 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13379 if (!attr)
13380 goto fail;
13381
13382 nlpeers = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEERS);
13383 if (!nlpeers)
13384 goto fail;
13385
13386 for (i = 0; i < params->num_peers; i++) {
13387 attr1 = nla_nest_start(msg, i);
13388 if (!attr1 ||
13389 nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_SRC_ADDR,
13390 ETH_ALEN, params->peer[i].own_addr) ||
13391 nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_MAC_ADDR,
13392 ETH_ALEN, params->peer[i].peer_addr))
13393 goto fail;
13394
Sunil Ravi77d572f2023-01-17 23:58:31 +000013395 if (params->peer[i].status == 0 &&
13396 nla_put_flag(msg,
13397 QCA_WLAN_VENDOR_ATTR_PASN_PEER_STATUS_SUCCESS))
13398 goto fail;
Sunil Ravi89eba102022-09-13 21:04:37 -070013399
13400 wpa_printf(MSG_DEBUG,
13401 "nl80211: Own address[%u]: " MACSTR
13402 " Peer address[%u]: " MACSTR " Status: %s",
13403 i, MAC2STR(params->peer[i].own_addr), i,
13404 MAC2STR(params->peer[i].peer_addr),
13405 params->peer[i].status ? "Fail" : "Success");
13406 nla_nest_end(msg, attr1);
13407 }
13408
13409 nla_nest_end(msg, nlpeers);
13410 nla_nest_end(msg, attr);
13411
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013412 return send_and_recv_cmd(drv, msg);
Sunil Ravi89eba102022-09-13 21:04:37 -070013413
13414fail:
13415 nlmsg_free(msg);
13416 return -1;
13417}
13418
13419
13420static u32 wpa_ltf_keyseed_len_to_sha_type(size_t len)
13421{
13422 if (len == SHA384_MAC_LEN)
13423 return QCA_WLAN_VENDOR_SHA_384;
13424 if (len == SHA256_MAC_LEN)
13425 return QCA_WLAN_VENDOR_SHA_256;
13426
13427 wpa_printf(MSG_ERROR, "nl80211: Unexpected LTF keyseed len %zu", len);
13428 return (u32) -1;
13429}
13430
13431
13432static int nl80211_set_secure_ranging_ctx(void *priv,
13433 struct secure_ranging_params *params)
13434{
13435 int ret;
13436 u32 suite;
13437 struct nlattr *attr;
13438 struct nl_msg *msg = NULL;
13439 struct i802_bss *bss = priv;
13440 struct wpa_driver_nl80211_data *drv = bss->drv;
13441
13442 /* Configure secure ranging context only to the drivers that support it.
13443 */
13444 if (!drv->secure_ranging_ctx_vendor_cmd_avail)
13445 return 0;
13446
13447 if (!params->peer_addr || !params->own_addr)
13448 return -1;
13449
13450 wpa_dbg(drv->ctx, MSG_DEBUG,
13451 "nl80211: Secure ranging context for " MACSTR,
13452 MAC2STR(params->peer_addr));
13453
13454 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR);
13455 if (!msg ||
13456 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13457 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13458 QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT))
13459 goto fail;
13460
13461 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
13462 if (!attr)
13463 goto fail;
13464
13465 if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_PEER_MAC_ADDR,
13466 ETH_ALEN, params->peer_addr) ||
13467 nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SRC_ADDR,
13468 ETH_ALEN, params->own_addr) ||
13469 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_ACTION,
13470 params->action))
13471 goto fail;
13472
13473 if (params->cipher) {
13474 suite = wpa_cipher_to_cipher_suite(params->cipher);
13475 if (!suite ||
13476 nla_put_u32(msg,
13477 QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_CIPHER,
13478 suite))
13479 goto fail;
13480 }
13481
13482 if (params->tk_len && params->tk) {
13483 if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_TK,
13484 params->tk_len, params->tk))
13485 goto fail;
13486 wpa_hexdump_key(MSG_DEBUG, "nl80211: TK",
13487 params->tk, params->tk_len);
13488 }
13489
13490 if (params->ltf_keyseed_len && params->ltf_keyseed) {
13491 u32 sha_type = wpa_ltf_keyseed_len_to_sha_type(
13492 params->ltf_keyseed_len);
13493
13494 if (sha_type == (u32) -1 ||
13495 nla_put_u32(
13496 msg,
13497 QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SHA_TYPE,
13498 sha_type) ||
13499 nla_put(msg,
13500 QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_LTF_KEYSEED,
13501 params->ltf_keyseed_len, params->ltf_keyseed))
13502 goto fail;
13503 wpa_hexdump_key(MSG_DEBUG, "nl80211: LTF keyseed",
13504 params->ltf_keyseed, params->ltf_keyseed_len);
13505 }
13506 nla_nest_end(msg, attr);
13507
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013508 ret = send_and_recv_cmd(drv, msg);
Sunil Ravi89eba102022-09-13 21:04:37 -070013509 if (ret)
13510 wpa_printf(MSG_DEBUG,
13511 "nl80211: Set secure ranging context failed: ret=%d (%s)",
13512 ret, strerror(-ret));
13513 return ret;
13514fail:
13515 nlmsg_free(msg);
13516 return -1;
13517}
13518
13519#endif /* CONFIG_PASN */
13520
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013521#endif /* CONFIG_DRIVER_NL80211_QCA */
13522
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013523
13524#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
13525static int wpa_driver_do_broadcom_acs(struct wpa_driver_nl80211_data *drv,
13526 struct drv_acs_params *params)
13527{
13528 struct nl_msg *msg;
13529 struct nlattr *data;
13530 int freq_list_len;
13531 int ret = -1;
13532
13533 freq_list_len = int_array_len(params->freq_list);
13534 wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d",
13535 __func__, freq_list_len);
13536
13537 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR);
13538 if (!msg ||
13539 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) ||
13540 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13541 BRCM_VENDOR_SCMD_ACS) ||
13542 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13543 nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode) ||
13544 nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED,
13545 params->ht_enabled) ||
13546 nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED,
13547 params->ht40_enabled) ||
13548 nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED,
13549 params->vht_enabled) ||
13550 nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width) ||
13551 (freq_list_len > 0 &&
13552 nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST,
13553 sizeof(int) * freq_list_len, params->freq_list)))
13554 goto fail;
13555 nla_nest_end(msg, data);
13556
13557 wpa_printf(MSG_DEBUG,
13558 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d",
13559 params->hw_mode, params->ht_enabled, params->ht40_enabled,
13560 params->vht_enabled, params->ch_width);
13561
13562 ret = send_and_recv_cmd(drv, msg);
13563 if (ret) {
13564 wpa_printf(MSG_ERROR,
13565 "nl80211: BRCM Failed to invoke driver ACS function: %s",
13566 strerror(errno));
13567 }
13568
13569 msg = NULL;
13570fail:
13571 nlmsg_free(msg);
13572 return ret;
13573}
13574#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
13575
13576
Hai Shalomc1a21442022-02-04 13:43:00 -080013577static int nl80211_do_acs(void *priv, struct drv_acs_params *params)
13578{
Andy Kuoaba17c12022-04-14 16:05:31 +080013579#if defined(CONFIG_DRIVER_NL80211_QCA) || defined(CONFIG_DRIVER_NL80211_BRCM) \
13580 || defined(CONFIG_DRIVER_NL80211_SYNA)
Hai Shalomc1a21442022-02-04 13:43:00 -080013581 struct i802_bss *bss = priv;
13582 struct wpa_driver_nl80211_data *drv = bss->drv;
Andy Kuoaba17c12022-04-14 16:05:31 +080013583#endif /* CONFIG_DRIVER_NL80211_QCA || CONFIG_DRIVER_NL80211_BRCM \
13584 || defined(CONFIG_DRIVER_NL80211_SYNA) */
Hai Shalomc1a21442022-02-04 13:43:00 -080013585
13586#ifdef CONFIG_DRIVER_NL80211_QCA
13587 if (drv->qca_do_acs)
13588 return nl80211_qca_do_acs(drv, params);
13589#endif /* CONFIG_DRIVER_NL80211_QCA */
13590
Andy Kuoaba17c12022-04-14 16:05:31 +080013591#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Hai Shalomc1a21442022-02-04 13:43:00 -080013592 if (drv->brcm_do_acs)
13593 return wpa_driver_do_broadcom_acs(drv, params);
Andy Kuoaba17c12022-04-14 16:05:31 +080013594#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalomc1a21442022-02-04 13:43:00 -080013595
13596 return -1;
13597}
13598
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013599
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013600static int nl80211_write_to_file(const char *name, unsigned int val)
13601{
13602 int fd, len;
13603 char tmp[128];
Hai Shalomc3565922019-10-28 11:58:20 -070013604 int ret = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013605
13606 fd = open(name, O_RDWR);
13607 if (fd < 0) {
Hai Shalomc3565922019-10-28 11:58:20 -070013608 int level;
13609 /*
13610 * Flags may not exist on older kernels, or while we're tearing
13611 * down a disappearing device.
13612 */
13613 if (errno == ENOENT) {
13614 ret = 0;
13615 level = MSG_DEBUG;
13616 } else {
13617 ret = -1;
13618 level = MSG_ERROR;
13619 }
13620 wpa_printf(level, "nl80211: Failed to open %s: %s",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013621 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070013622 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013623 }
13624
13625 len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
13626 len = write(fd, tmp, len);
Hai Shalomc3565922019-10-28 11:58:20 -070013627 if (len < 0) {
13628 ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013629 wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
13630 name, strerror(errno));
Hai Shalomc3565922019-10-28 11:58:20 -070013631 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013632 close(fd);
13633
Hai Shalomc3565922019-10-28 11:58:20 -070013634 return ret;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013635}
13636
13637
13638static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags)
13639{
13640 struct i802_bss *bss = priv;
13641 char path[128];
13642 int ret;
13643
Hai Shalom60840252021-02-19 19:02:11 -080013644 /* P2P-Device has no netdev that can (or should) be configured here */
13645 if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE)
13646 return 0;
13647
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013648 wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x",
13649 filter_flags);
13650
13651 /* Configure filtering of unicast frame encrypted using GTK */
13652 ret = os_snprintf(path, sizeof(path),
13653 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
13654 bss->ifname);
13655 if (os_snprintf_error(sizeof(path), ret))
13656 return -1;
13657
13658 ret = nl80211_write_to_file(path,
13659 !!(filter_flags &
13660 WPA_DATA_FRAME_FILTER_FLAG_GTK));
13661 if (ret) {
13662 wpa_printf(MSG_ERROR,
13663 "nl80211: Failed to set IPv4 unicast in multicast filter");
13664 return ret;
13665 }
13666
13667 os_snprintf(path, sizeof(path),
13668 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
13669 bss->ifname);
13670 ret = nl80211_write_to_file(path,
13671 !!(filter_flags &
13672 WPA_DATA_FRAME_FILTER_FLAG_GTK));
13673
13674 if (ret) {
13675 wpa_printf(MSG_ERROR,
13676 "nl80211: Failed to set IPv6 unicast in multicast filter");
13677 return ret;
13678 }
13679
13680 /* Configure filtering of unicast frame encrypted using GTK */
13681 os_snprintf(path, sizeof(path),
13682 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
13683 bss->ifname);
13684 ret = nl80211_write_to_file(path,
13685 !!(filter_flags &
13686 WPA_DATA_FRAME_FILTER_FLAG_ARP));
13687 if (ret) {
13688 wpa_printf(MSG_ERROR,
13689 "nl80211: Failed set gratuitous ARP filter");
13690 return ret;
13691 }
13692
13693 /* Configure filtering of IPv6 NA frames */
13694 os_snprintf(path, sizeof(path),
13695 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
13696 bss->ifname);
13697 ret = nl80211_write_to_file(path,
13698 !!(filter_flags &
13699 WPA_DATA_FRAME_FILTER_FLAG_NA));
13700 if (ret) {
13701 wpa_printf(MSG_ERROR,
13702 "nl80211: Failed to set unsolicited NA filter");
13703 return ret;
13704 }
13705
13706 return 0;
13707}
13708
13709
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070013710static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type,
13711 const u8 **ext_capa, const u8 **ext_capa_mask,
13712 unsigned int *ext_capa_len)
13713{
13714 struct i802_bss *bss = priv;
13715 struct wpa_driver_nl80211_data *drv = bss->drv;
13716 enum nl80211_iftype nlmode;
13717 unsigned int i;
13718
13719 if (!ext_capa || !ext_capa_mask || !ext_capa_len)
13720 return -1;
13721
13722 nlmode = wpa_driver_nl80211_if_type(type);
13723
13724 /* By default, use the per-radio values */
13725 *ext_capa = drv->extended_capa;
13726 *ext_capa_mask = drv->extended_capa_mask;
13727 *ext_capa_len = drv->extended_capa_len;
13728
13729 /* Replace the default value if a per-interface type value exists */
Sunil Ravi2a14cf12023-11-21 00:54:38 +000013730 for (i = 0; i < drv->num_iface_capa; i++) {
13731 if (nlmode == drv->iface_capa[i].iftype) {
13732 *ext_capa = drv->iface_capa[i].ext_capa;
13733 *ext_capa_mask = drv->iface_capa[i].ext_capa_mask;
13734 *ext_capa_len = drv->iface_capa[i].ext_capa_len;
13735 break;
13736 }
13737 }
13738
13739 return 0;
13740}
13741
13742
13743static int nl80211_get_mld_capab(void *priv, enum wpa_driver_if_type type,
13744 u16 *eml_capa, u16 *mld_capa_and_ops)
13745{
13746 struct i802_bss *bss = priv;
13747 struct wpa_driver_nl80211_data *drv = bss->drv;
13748 enum nl80211_iftype nlmode;
13749 unsigned int i;
13750
13751 if (!eml_capa || !mld_capa_and_ops)
13752 return -1;
13753
13754 nlmode = wpa_driver_nl80211_if_type(type);
13755
13756 /* By default, set to zero */
13757 *eml_capa = 0;
13758 *mld_capa_and_ops = 0;
13759
13760 /* Replace the default value if a per-interface type value exists */
13761 for (i = 0; i < drv->num_iface_capa; i++) {
13762 if (nlmode == drv->iface_capa[i].iftype) {
13763 *eml_capa = drv->iface_capa[i].eml_capa;
13764 *mld_capa_and_ops =
13765 drv->iface_capa[i].mld_capa_and_ops;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070013766 break;
13767 }
13768 }
13769
13770 return 0;
13771}
13772
13773
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013774static int nl80211_update_connection_params(
13775 void *priv, struct wpa_driver_associate_params *params,
13776 enum wpa_drv_update_connect_params_mask mask)
13777{
13778 struct i802_bss *bss = priv;
13779 struct wpa_driver_nl80211_data *drv = bss->drv;
13780 struct nl_msg *msg;
13781 int ret = -1;
13782 enum nl80211_auth_type type;
13783
Hai Shalomc3565922019-10-28 11:58:20 -070013784 /* Update Connection Params is intended for drivers that implement
13785 * internal SME and expect these updated connection params from
13786 * wpa_supplicant. Do not send this request for the drivers using
13787 * SME from wpa_supplicant.
13788 */
13789 if (drv->capa.flags & WPA_DRIVER_FLAGS_SME)
13790 return 0;
13791
Vinayak Yadawade62409f2022-01-20 12:32:07 +053013792 /* Handle any connection param update here which might receive kernel handling in future */
Winnie Chen4138eec2022-11-10 16:32:53 +080013793#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawade62409f2022-01-20 12:32:07 +053013794 if (mask & WPA_DRV_UPDATE_TD_POLICY) {
13795 ret = nl80211_set_td_policy(priv, params->td_policy);
13796 if (ret) {
13797 wpa_dbg(drv->ctx, MSG_DEBUG,
13798 "nl80211: Update connect params command failed: ret=%d (%s)",
13799 ret, strerror(-ret));
13800 }
13801 return ret;
13802 }
Winnie Chen4138eec2022-11-10 16:32:53 +080013803#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawade62409f2022-01-20 12:32:07 +053013804
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013805 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS);
13806 if (!msg)
13807 goto fail;
13808
13809 wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)",
13810 drv->ifindex);
13811
13812 if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) {
13813 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
13814 params->wpa_ie))
13815 goto fail;
13816 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie,
13817 params->wpa_ie_len);
13818 }
13819
13820 if (mask & WPA_DRV_UPDATE_AUTH_TYPE) {
13821 type = get_nl_auth_type(params->auth_alg);
13822 if (type == NL80211_AUTHTYPE_MAX ||
13823 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
13824 goto fail;
13825 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
13826 }
13827
13828 if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) &&
13829 nl80211_put_fils_connect_params(drv, params, msg))
13830 goto fail;
13831
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013832 ret = send_and_recv_cmd(drv, msg);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013833 msg = NULL;
13834 if (ret)
13835 wpa_dbg(drv->ctx, MSG_DEBUG,
13836 "nl80211: Update connect params command failed: ret=%d (%s)",
13837 ret, strerror(-ret));
13838
13839fail:
13840 nlmsg_free(msg);
13841 return ret;
13842}
13843
13844
Roshan Pius3a1667e2018-07-03 15:17:14 -070013845static int nl80211_send_external_auth_status(void *priv,
13846 struct external_auth *params)
13847{
13848 struct i802_bss *bss = priv;
13849 struct wpa_driver_nl80211_data *drv = bss->drv;
13850 struct nl_msg *msg = NULL;
13851 int ret = -1;
13852
Hai Shalom5f92bc92019-04-18 11:54:11 -070013853 /* External auth command/status is intended for drivers that implement
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080013854 * internal SME but want to offload authentication processing (e.g.,
13855 * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers
Hai Shalom5f92bc92019-04-18 11:54:11 -070013856 * which do not support AP SME or use wpa_supplicant/hostapd SME.
13857 */
Hai Shalom81f62d82019-07-22 12:10:00 -070013858 if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070013859 (drv->capa.flags & WPA_DRIVER_FLAGS_SME))
13860 return -1;
13861
Roshan Pius3a1667e2018-07-03 15:17:14 -070013862 wpa_dbg(drv->ctx, MSG_DEBUG,
13863 "nl80211: External auth status: %u", params->status);
13864
13865 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH);
13866 if (!msg ||
13867 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) ||
Hai Shalom5f92bc92019-04-18 11:54:11 -070013868 (params->ssid && params->ssid_len &&
13869 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
13870 (params->pmkid &&
13871 nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) ||
13872 (params->bssid &&
13873 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)))
Roshan Pius3a1667e2018-07-03 15:17:14 -070013874 goto fail;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013875 ret = send_and_recv_cmd(drv, msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -070013876 msg = NULL;
13877 if (ret) {
13878 wpa_printf(MSG_DEBUG,
13879 "nl80211: External Auth status update failed: ret=%d (%s)",
13880 ret, strerror(-ret));
13881 goto fail;
13882 }
13883fail:
13884 nlmsg_free(msg);
13885 return ret;
13886}
13887
13888
Hai Shalom74f70d42019-02-11 14:42:39 -080013889static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname,
13890 int val)
13891{
13892 struct i802_bss *bss = priv;
13893 struct wpa_driver_nl80211_data *drv = bss->drv;
13894 struct nl_msg *msg;
13895 int ret = -ENOBUFS;
13896
13897 wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)",
13898 val ? "Enable" : "Disable", bridge_ifname);
13899
13900 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
13901 if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val))
13902 goto fail;
13903
13904 if (bridge_ifname[0] && bss->added_if_into_bridge && !val) {
13905 if (linux_br_del_if(drv->global->ioctl_sock,
13906 bridge_ifname, bss->ifname)) {
13907 wpa_printf(MSG_ERROR,
13908 "nl80211: Failed to remove interface %s from bridge %s",
13909 bss->ifname, bridge_ifname);
13910 return -1;
13911 }
13912 bss->added_if_into_bridge = 0;
13913 }
13914
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013915 ret = send_and_recv_cmd(drv, msg);
Hai Shalom74f70d42019-02-11 14:42:39 -080013916 msg = NULL;
Hai Shalom60840252021-02-19 19:02:11 -080013917 if (ret && val && nl80211_get_4addr(bss) == 1) {
13918 wpa_printf(MSG_DEBUG,
13919 "nl80211: 4addr mode was already enabled");
13920 ret = 0;
13921 }
Hai Shalom74f70d42019-02-11 14:42:39 -080013922 if (!ret) {
13923 if (bridge_ifname[0] && val &&
13924 i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0)
13925 return -1;
13926 return 0;
13927 }
13928
13929fail:
13930 nlmsg_free(msg);
13931 wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr");
13932
13933 return ret;
13934}
13935
13936
Hai Shalome21d4e82020-04-29 16:34:06 -070013937#ifdef CONFIG_DPP
13938static int nl80211_dpp_listen(void *priv, bool enable)
13939{
13940 struct i802_bss *bss = priv;
13941 struct wpa_driver_nl80211_data *drv = bss->drv;
13942 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
13943 struct nl_sock *handle;
13944
13945 if (!drv->multicast_registrations || !bss->nl_mgmt)
13946 return 0; /* cannot do more than hope broadcast RX works */
13947
13948 wpa_printf(MSG_DEBUG,
13949 "nl80211: Update DPP Public Action frame registration (%s multicast RX)",
13950 enable ? "enable" : "disable");
13951 handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID);
13952 return nl80211_register_frame(bss, handle, type,
13953 (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6,
13954 enable);
13955}
13956#endif /* CONFIG_DPP */
13957
Winnie Chen4138eec2022-11-10 16:32:53 +080013958#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawade62409f2022-01-20 12:32:07 +053013959static int nl80211_set_td_policy(void *priv, u32 td_policy)
13960{
13961 struct i802_bss *bss = priv;
13962 struct wpa_driver_nl80211_data *drv = bss->drv;
13963 struct nl_msg *msg;
13964 int ret;
13965 struct nlattr *params;
13966
13967 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
13968 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) ||
13969 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_SET_TD_POLICY) ||
13970 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13971 (nla_put_u32(msg, BRCM_ATTR_DRIVER_TD_POLICY, td_policy))) {
13972 nl80211_nlmsg_clear(msg);
13973 nlmsg_free(msg);
13974 return -ENOBUFS;
13975 }
13976 nla_nest_end(msg, params);
13977 wpa_printf(MSG_DEBUG, "nl80211: Transition Disable Policy %d\n", td_policy);
13978
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013979 ret = send_and_recv_cmd(drv, msg);
Vinayak Yadawade62409f2022-01-20 12:32:07 +053013980 if (ret) {
13981 wpa_printf(MSG_DEBUG, "nl80211: Transition Disable setting failed: ret=%d (%s)",
13982 ret, strerror(-ret));
13983 }
13984
13985 return ret;
13986}
Winnie Chen4138eec2022-11-10 16:32:53 +080013987#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalome21d4e82020-04-29 16:34:06 -070013988
Sunil Ravi88611412024-06-28 17:34:56 +000013989static int nl80211_link_add(void *priv, u8 link_id, const u8 *addr)
Sunil Ravi036cec52023-03-29 11:35:17 -070013990{
13991 struct i802_bss *bss = priv;
13992 struct wpa_driver_nl80211_data *drv = bss->drv;
13993 struct nl_msg *msg;
Sunil Ravi88611412024-06-28 17:34:56 +000013994 unsigned int idx, i;
Sunil Ravi036cec52023-03-29 11:35:17 -070013995 int ret;
13996
13997 wpa_printf(MSG_DEBUG, "nl80211: MLD: add link_id=%u, addr=" MACSTR,
13998 link_id, MAC2STR(addr));
13999
14000 if (drv->nlmode != NL80211_IFTYPE_AP) {
14001 wpa_printf(MSG_DEBUG,
14002 "nl80211: MLD: cannot add link to iftype=%u",
14003 drv->nlmode);
14004 return -EINVAL;
14005 }
14006
Sunil Ravi88611412024-06-28 17:34:56 +000014007 if (bss->n_links >= MAX_NUM_MLD_LINKS) {
14008 wpa_printf(MSG_DEBUG, "nl80211: MLD: already have n_links=%zu",
14009 bss->n_links);
Sunil Ravi036cec52023-03-29 11:35:17 -070014010 return -EINVAL;
14011 }
14012
Sunil Ravi88611412024-06-28 17:34:56 +000014013 for (i = 0; i < bss->n_links; i++) {
14014 if (bss->links[i].link_id == link_id &&
14015 bss->links[i].beacon_set) {
14016 wpa_printf(MSG_DEBUG,
14017 "nl80211: MLD: link already set");
14018 return -EINVAL;
14019 }
Sunil Ravi036cec52023-03-29 11:35:17 -070014020 }
14021
Sunil Ravi88611412024-06-28 17:34:56 +000014022 /* try using the first link entry, assuming it is not beaconing yet */
14023 if (bss->n_links == 1 &&
14024 bss->flink->link_id == NL80211_DRV_LINK_ID_NA) {
Sunil Ravi036cec52023-03-29 11:35:17 -070014025 if (bss->flink->beacon_set) {
14026 wpa_printf(MSG_DEBUG, "nl80211: BSS already beaconing");
14027 return -EINVAL;
14028 }
Sunil Ravi88611412024-06-28 17:34:56 +000014029
14030 idx = 0;
14031 } else {
14032 idx = bss->n_links;
Sunil Ravi036cec52023-03-29 11:35:17 -070014033 }
14034
14035 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ADD_LINK);
14036 if (!msg ||
14037 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id) ||
14038 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
14039 nlmsg_free(msg);
14040 return -ENOBUFS;
14041 }
14042
Sunil Ravib0ac25f2024-07-12 01:42:03 +000014043 ret = send_and_recv_cmd(drv, msg);
Sunil Ravi036cec52023-03-29 11:35:17 -070014044 if (ret) {
14045 wpa_printf(MSG_DEBUG, "nl80211: add link failed. ret=%d (%s)",
14046 ret, strerror(-ret));
14047 return ret;
14048 }
14049
Sunil Ravi88611412024-06-28 17:34:56 +000014050 bss->links[idx].link_id = link_id;
14051 os_memcpy(bss->links[idx].addr, addr, ETH_ALEN);
Sunil Ravi036cec52023-03-29 11:35:17 -070014052
Sunil Ravi88611412024-06-28 17:34:56 +000014053 bss->n_links = idx + 1;
Sunil Ravi036cec52023-03-29 11:35:17 -070014054
Sunil Ravi88611412024-06-28 17:34:56 +000014055 wpa_printf(MSG_DEBUG, "nl80211: MLD: n_links=%zu", bss->n_links);
Sunil Ravi036cec52023-03-29 11:35:17 -070014056 return 0;
14057}
14058
14059
Hai Shalomc1a21442022-02-04 13:43:00 -080014060#ifdef CONFIG_TESTING_OPTIONS
14061
14062static int testing_nl80211_register_frame(void *priv, u16 type,
14063 const u8 *match, size_t match_len,
14064 bool multicast)
14065{
14066 struct i802_bss *bss = priv;
14067 struct nl_sock *handle;
14068
14069 if (!bss->nl_mgmt)
14070 return -1;
14071 handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID);
14072 return nl80211_register_frame(bss, handle, type, match, match_len,
14073 multicast);
14074}
14075
14076
14077static int testing_nl80211_radio_disable(void *priv, int disabled)
14078{
14079 struct i802_bss *bss = priv;
14080 struct wpa_driver_nl80211_data *drv = bss->drv;
14081
14082 /* For now, this is supported only partially in station mode with
14083 * SME-in-wpa_supplicant case where the NL80211_ATTR_LOCAL_STATE_CHANGE
14084 * attribute can be used to avoid sending out the Deauthentication frame
14085 * to the currently associated AP. */
14086
14087 if (!disabled)
14088 return 0;
14089
14090 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
14091 return -1;
14092
14093 if (!drv->associated)
14094 return 0;
14095
14096 return wpa_driver_nl80211_mlme(drv, drv->bssid,
14097 NL80211_CMD_DEAUTHENTICATE,
14098 WLAN_REASON_PREV_AUTH_NOT_VALID, 1,
14099 drv->first_bss);
14100}
14101
14102#endif /* CONFIG_TESTING_OPTIONS */
14103
14104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014105const struct wpa_driver_ops wpa_driver_nl80211_ops = {
14106 .name = "nl80211",
14107 .desc = "Linux nl80211/cfg80211",
14108 .get_bssid = wpa_driver_nl80211_get_bssid,
14109 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014110 .set_key = driver_nl80211_set_key,
14111 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014112 .sched_scan = wpa_driver_nl80211_sched_scan,
14113 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Sunil Ravi88611412024-06-28 17:34:56 +000014114 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080014115 .abort_scan = wpa_driver_nl80211_abort_scan,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014116 .deauthenticate = driver_nl80211_deauthenticate,
14117 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014118 .associate = wpa_driver_nl80211_associate,
14119 .global_init = nl80211_global_init,
14120 .global_deinit = nl80211_global_deinit,
14121 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014122 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014123 .get_capa = wpa_driver_nl80211_get_capa,
14124 .set_operstate = wpa_driver_nl80211_set_operstate,
14125 .set_supp_port = wpa_driver_nl80211_set_supp_port,
14126 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -080014127 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014128 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -070014129 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014130 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014131 .if_remove = driver_nl80211_if_remove,
14132 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014133 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014134 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014135 .sta_remove = driver_nl80211_sta_remove,
Hai Shalomfdcde762020-04-02 11:19:20 -070014136 .tx_control_port = nl80211_tx_control_port,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014137 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
14138 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Hai Shalom81f62d82019-07-22 12:10:00 -070014139 .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014140 .hapd_init = i802_init,
14141 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -070014142 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014143 .get_seqnum = i802_get_seqnum,
14144 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014145 .get_inact_sec = i802_get_inact_sec,
14146 .sta_clear_stats = i802_sta_clear_stats,
14147 .set_rts = i802_set_rts,
14148 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014149 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014150 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014151 .sta_deauth = i802_sta_deauth,
14152 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014153 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014154 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014155 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014156 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
14157 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
14158 .cancel_remain_on_channel =
14159 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080014160 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014161 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -070014162 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014163 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014164 .signal_monitor = nl80211_signal_monitor,
14165 .signal_poll = nl80211_signal_poll,
Sunil Ravi89eba102022-09-13 21:04:37 -070014166 .mlo_signal_poll = nl80211_mlo_signal_poll,
Hai Shalom74f70d42019-02-11 14:42:39 -080014167 .channel_info = nl80211_channel_info,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014168 .set_param = nl80211_set_param,
14169 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -070014170 .add_pmkid = nl80211_add_pmkid,
14171 .remove_pmkid = nl80211_remove_pmkid,
14172 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014173 .set_rekey_info = nl80211_set_rekey_info,
14174 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014175 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -070014176 .start_dfs_cac = nl80211_start_radar_detection,
14177 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014178#ifdef CONFIG_TDLS
14179 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
14180 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014181 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
14182 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014183#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -070014184 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Hai Shalom81f62d82019-07-22 12:10:00 -070014185 .update_dh_ie = nl80211_update_dh_ie,
Dmitry Shmidt34af3062013-07-11 10:46:32 -070014186 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014187 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -070014188 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080014189 .switch_channel = nl80211_switch_channel,
Sunil Ravia04bd252022-05-02 22:54:18 -070014190#ifdef CONFIG_IEEE80211AX
14191 .switch_color = nl80211_switch_color,
14192#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014193#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070014194 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014195 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -070014196 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080014197#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070014198#ifdef ANDROID
Dmitry Shmidt41712582015-06-29 11:02:15 -070014199#ifndef ANDROID_LIB_STUB
Dmitry Shmidt738a26e2011-07-07 14:22:14 -070014200 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt41712582015-06-29 11:02:15 -070014201#endif /* !ANDROID_LIB_STUB */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080014202#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080014203 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080014204 .set_qos_map = nl80211_set_qos_map,
Hai Shalomfdcde762020-04-02 11:19:20 -070014205 .get_wowlan = nl80211_get_wowlan,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -070014206 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070014207 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014208#ifdef CONFIG_MESH
14209 .init_mesh = wpa_driver_nl80211_init_mesh,
14210 .join_mesh = wpa_driver_nl80211_join_mesh,
14211 .leave_mesh = wpa_driver_nl80211_leave_mesh,
Hai Shalom81f62d82019-07-22 12:10:00 -070014212 .probe_mesh_link = nl80211_probe_mesh_link,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014213#endif /* CONFIG_MESH */
14214 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
14215 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
14216 .br_port_set_attr = wpa_driver_br_port_set_attr,
14217 .br_set_net_param = wpa_driver_br_set_net_param,
14218 .add_tx_ts = nl80211_add_ts,
14219 .del_tx_ts = nl80211_del_ts,
Dmitry Shmidte4663042016-04-04 10:07:49 -070014220 .get_ifindex = nl80211_get_ifindex,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014221#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070014222 .roaming = nl80211_roaming,
Roshan Pius3a1667e2018-07-03 15:17:14 -070014223 .disable_fils = nl80211_disable_fils,
Ravi Joshie6ccb162015-07-16 17:45:41 -070014224 .set_band = nl80211_set_band,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014225 .get_pref_freq_list = nl80211_get_pref_freq_list,
14226 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070014227 .p2p_lo_start = nl80211_p2p_lo_start,
14228 .p2p_lo_stop = nl80211_p2p_lo_stop,
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070014229 .set_default_scan_ies = nl80211_set_default_scan_ies,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080014230 .set_tdls_mode = nl80211_set_tdls_mode,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070014231#ifdef CONFIG_MBO
14232 .get_bss_transition_status = nl80211_get_bss_transition_status,
14233 .ignore_assoc_disallow = nl80211_ignore_assoc_disallow,
14234#endif /* CONFIG_MBO */
Hai Shalom899fcc72020-10-19 14:38:18 -070014235 .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow,
Hai Shalomc3565922019-10-28 11:58:20 -070014236 .add_sta_node = nl80211_add_sta_node,
Sunil Ravi89eba102022-09-13 21:04:37 -070014237#ifdef CONFIG_PASN
14238 .send_pasn_resp = nl80211_send_pasn_resp,
14239 .set_secure_ranging_ctx = nl80211_set_secure_ranging_ctx,
14240#endif /* CONFIG_PASN */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014241#endif /* CONFIG_DRIVER_NL80211_QCA */
Hai Shalomc1a21442022-02-04 13:43:00 -080014242 .do_acs = nl80211_do_acs,
Dmitry Shmidt849734c2016-05-27 09:59:01 -070014243 .configure_data_frame_filters = nl80211_configure_data_frame_filters,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070014244 .get_ext_capab = nl80211_get_ext_capab,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000014245 .get_mld_capab = nl80211_get_mld_capab,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070014246 .update_connect_params = nl80211_update_connection_params,
Roshan Pius3a1667e2018-07-03 15:17:14 -070014247 .send_external_auth_status = nl80211_send_external_auth_status,
Hai Shalom74f70d42019-02-11 14:42:39 -080014248 .set_4addr_mode = nl80211_set_4addr_mode,
Hai Shalome21d4e82020-04-29 16:34:06 -070014249#ifdef CONFIG_DPP
14250 .dpp_listen = nl80211_dpp_listen,
14251#endif /* CONFIG_DPP */
Sunil Ravi89eba102022-09-13 21:04:37 -070014252 .get_sta_mlo_info = nl80211_get_sta_mlo_info,
Sunil Ravi036cec52023-03-29 11:35:17 -070014253 .link_add = nl80211_link_add,
Hai Shalomc1a21442022-02-04 13:43:00 -080014254#ifdef CONFIG_TESTING_OPTIONS
14255 .register_frame = testing_nl80211_register_frame,
14256 .radio_disable = testing_nl80211_radio_disable,
14257#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014258};