Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver interaction with Linux nl80211/cfg80211 |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * 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 Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9 | * This software may be distributed under the terms of the BSD license. |
| 10 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "includes.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include <sys/types.h> |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 15 | #include <sys/utsname.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 16 | #include <fcntl.h> |
| 17 | #include <net/if.h> |
| 18 | #include <netlink/genl/genl.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include <netlink/genl/ctrl.h> |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 20 | #include <netlink/genl/family.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include <linux/rtnetlink.h> |
| 22 | #include <netpacket/packet.h> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 23 | #include <linux/errqueue.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.h" |
| 26 | #include "eloop.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 27 | #include "common/qca-vendor.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 28 | #include "common/qca-vendor-attr.h" |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 29 | #include "common/brcm_vendor.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 31 | #include "common/ieee802_11_common.h" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 32 | #include "common/wpa_common.h" |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 33 | #include "crypto/sha256.h" |
| 34 | #include "crypto/sha384.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 36 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "linux_ioctl.h" |
| 38 | #include "radiotap.h" |
| 39 | #include "radiotap_iter.h" |
| 40 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 41 | #include "driver_nl80211.h" |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 42 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 43 | #include "common/brcm_vendor.h" |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 44 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 45 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 46 | #ifndef NETLINK_CAP_ACK |
| 47 | #define NETLINK_CAP_ACK 10 |
| 48 | #endif /* NETLINK_CAP_ACK */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 49 | /* support for extack if compilation headers are too old */ |
| 50 | #ifndef NETLINK_EXT_ACK |
| 51 | #define NETLINK_EXT_ACK 11 |
| 52 | enum nlmsgerr_attrs { |
| 53 | NLMSGERR_ATTR_UNUSED, |
| 54 | NLMSGERR_ATTR_MSG, |
| 55 | NLMSGERR_ATTR_OFFS, |
| 56 | NLMSGERR_ATTR_COOKIE, |
| 57 | |
| 58 | __NLMSGERR_ATTR_MAX, |
| 59 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 60 | }; |
| 61 | #endif |
| 62 | #ifndef NLM_F_CAPPED |
| 63 | #define NLM_F_CAPPED 0x100 |
| 64 | #endif |
| 65 | #ifndef NLM_F_ACK_TLVS |
| 66 | #define NLM_F_ACK_TLVS 0x200 |
| 67 | #endif |
| 68 | #ifndef SOL_NETLINK |
| 69 | #define SOL_NETLINK 270 |
| 70 | #endif |
| 71 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 72 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 73 | #ifdef ANDROID |
| 74 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 75 | #undef nl_socket_set_nonblocking |
| 76 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 77 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 78 | #endif /* ANDROID */ |
| 79 | |
| 80 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 81 | static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 82 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 83 | struct nl_sock *handle; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 84 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 85 | handle = nl_socket_alloc_cb(cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 86 | if (handle == NULL) { |
| 87 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 88 | "callbacks (%s)", dbg); |
| 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | if (genl_connect(handle)) { |
| 93 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 94 | "netlink (%s)", dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 95 | nl_socket_free(handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | return handle; |
| 100 | } |
| 101 | |
| 102 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 103 | static void nl_destroy_handles(struct nl_sock **handle) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 104 | { |
| 105 | if (*handle == NULL) |
| 106 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 107 | nl_socket_free(*handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 108 | *handle = NULL; |
| 109 | } |
| 110 | |
| 111 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 112 | #if __WORDSIZE == 64 |
| 113 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 114 | #else |
| 115 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 116 | #endif |
| 117 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 118 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 119 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 120 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 121 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 122 | /* |
| 123 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 124 | * by default. It is possible to hit that limit in some cases where |
| 125 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 126 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 127 | * this less likely to occur. |
| 128 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 129 | int err; |
| 130 | |
| 131 | err = nl_socket_set_buffer_size(*handle, 262144, 0); |
| 132 | if (err < 0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 133 | wpa_printf(MSG_DEBUG, |
| 134 | "nl80211: Could not set nl_socket RX buffer size: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 135 | nl_geterror(err)); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 136 | /* continue anyway with the default (smaller) buffer */ |
| 137 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 138 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 139 | nl_socket_set_nonblocking(*handle); |
| 140 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 141 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 142 | if (!persist) |
| 143 | *handle = (void *) (((intptr_t) *handle) ^ |
| 144 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 148 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 149 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 150 | if (!persist) |
| 151 | *handle = (void *) (((intptr_t) *handle) ^ |
| 152 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 153 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 154 | nl_destroy_handles(handle); |
| 155 | } |
| 156 | |
| 157 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 158 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 159 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 160 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 161 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 162 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 163 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 164 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 165 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 166 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 167 | const u8 *set_addr, int first, |
| 168 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 169 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 170 | unsigned int freq, unsigned int wait, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 171 | const u8 *buf, size_t buf_len, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 172 | int save_cookie, int no_cck, int no_ack, |
| 173 | int offchanok, const u16 *csa_offs, |
| 174 | size_t csa_offs_len, int link_id); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 175 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 176 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 177 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 178 | #define IFIDX_ANY -1 |
| 179 | |
| 180 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 181 | int ifidx_reason); |
| 182 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 183 | int ifidx_reason); |
| 184 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 185 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 186 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 187 | static int nl80211_set_channel(struct i802_bss *bss, |
| 188 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 190 | int ifindex, int disabled); |
| 191 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 192 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 193 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 194 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 195 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 196 | static int nl80211_set_param(void *priv, const char *param); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 197 | static void nl80211_remove_links(struct i802_bss *bss); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 198 | #ifdef CONFIG_MESH |
| 199 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 200 | struct wpa_driver_mesh_bss_params *params); |
| 201 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 202 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 203 | u16 reason); |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 204 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 205 | static int nl80211_set_td_policy(void *priv, u32 td_policy); |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 206 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 207 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 208 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 209 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 210 | { |
| 211 | switch (width) { |
| 212 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 213 | return CHAN_WIDTH_20_NOHT; |
| 214 | case NL80211_CHAN_WIDTH_20: |
| 215 | return CHAN_WIDTH_20; |
| 216 | case NL80211_CHAN_WIDTH_40: |
| 217 | return CHAN_WIDTH_40; |
| 218 | case NL80211_CHAN_WIDTH_80: |
| 219 | return CHAN_WIDTH_80; |
| 220 | case NL80211_CHAN_WIDTH_80P80: |
| 221 | return CHAN_WIDTH_80P80; |
| 222 | case NL80211_CHAN_WIDTH_160: |
| 223 | return CHAN_WIDTH_160; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 224 | case NL80211_CHAN_WIDTH_320: |
| 225 | return CHAN_WIDTH_320; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 226 | default: |
| 227 | return CHAN_WIDTH_UNKNOWN; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 228 | } |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 232 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 233 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 234 | return nlmode == NL80211_IFTYPE_AP || |
| 235 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 239 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 240 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 241 | return nlmode == NL80211_IFTYPE_STATION || |
| 242 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 246 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 247 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 248 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 249 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 250 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 251 | |
| 252 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 253 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 254 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 255 | { |
| 256 | struct i802_bss *bss; |
| 257 | |
| 258 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 259 | if (bss->ifindex == ifindex) |
| 260 | return bss; |
| 261 | } |
| 262 | |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 267 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 268 | { |
| 269 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 274 | { |
| 275 | if (drv->associated) |
| 276 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 277 | drv->associated = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 278 | os_memset(&drv->sta_mlo_info, 0, sizeof(drv->sta_mlo_info)); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 279 | os_memset(drv->bssid, 0, ETH_ALEN); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 280 | drv->first_bss->flink->freq = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 281 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 282 | os_free(drv->pending_roam_data); |
| 283 | drv->pending_roam_data = NULL; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 284 | os_free(drv->pending_t2lm_data); |
| 285 | drv->pending_t2lm_data = NULL; |
| 286 | os_free(drv->pending_link_reconfig_data); |
| 287 | drv->pending_link_reconfig_data = NULL; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 288 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 289 | |
| 290 | drv->auth_mld = false; |
| 291 | drv->auth_mld_link_id = -1; |
| 292 | os_memset(drv->auth_ap_mld_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | /* nl80211 code */ |
| 297 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 298 | { |
| 299 | int *err = arg; |
| 300 | *err = 0; |
| 301 | return NL_STOP; |
| 302 | } |
| 303 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 304 | |
| 305 | struct nl80211_ack_ext_arg { |
| 306 | int *err; |
| 307 | void *ext_data; |
| 308 | }; |
| 309 | |
| 310 | |
| 311 | static int ack_handler_cookie(struct nl_msg *msg, void *arg) |
| 312 | { |
| 313 | struct nl80211_ack_ext_arg *ext_arg = arg; |
| 314 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
| 315 | u64 *cookie = ext_arg->ext_data; |
| 316 | struct nlattr *attrs; |
| 317 | size_t ack_len, attr_len; |
| 318 | |
| 319 | *ext_arg->err = 0; |
| 320 | ack_len = sizeof(struct nlmsghdr) + sizeof(int) + |
| 321 | sizeof(struct nlmsghdr); |
| 322 | attrs = (struct nlattr *) |
| 323 | ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) + |
| 324 | sizeof(int)); |
| 325 | if (nlmsg_hdr(msg)->nlmsg_len <= ack_len) |
| 326 | return NL_STOP; |
| 327 | |
| 328 | attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len; |
| 329 | |
| 330 | if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 331 | return NL_STOP; |
| 332 | |
| 333 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL); |
| 334 | if (tb[NLMSGERR_ATTR_COOKIE]) |
| 335 | *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]); |
| 336 | |
| 337 | return NL_STOP; |
| 338 | } |
| 339 | |
| 340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 341 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 342 | { |
| 343 | int *ret = arg; |
| 344 | *ret = 0; |
| 345 | return NL_SKIP; |
| 346 | } |
| 347 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 348 | struct nl80211_ack_err_args { |
| 349 | int err; |
| 350 | struct nl_msg *orig_msg; |
| 351 | struct nl80211_err_info *err_info; |
| 352 | }; |
| 353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 355 | void *arg) |
| 356 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 357 | struct nl80211_ack_err_args *err_args = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 358 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 359 | struct nlmsghdr *orig_nlh = nlmsg_hdr(err_args->orig_msg); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 360 | int len = nlh->nlmsg_len; |
| 361 | struct nlattr *attrs; |
| 362 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 363 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 364 | struct nlattr *mlo_links, *link_attr; |
| 365 | u32 offset; |
| 366 | int rem; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 367 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 368 | err_args->err = err->error; |
| 369 | if (err_args->err_info) |
| 370 | err_args->err_info->link_id = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 371 | |
| 372 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 373 | return NL_SKIP; |
| 374 | |
| 375 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 376 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 377 | |
| 378 | if (len <= ack_len) |
| 379 | return NL_STOP; |
| 380 | |
| 381 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 382 | len -= ack_len; |
| 383 | |
| 384 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 385 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 386 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 387 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 388 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 389 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 390 | } |
| 391 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 392 | if (!err_args->err_info) |
| 393 | return NL_SKIP; |
| 394 | |
| 395 | /* Check if it was a per-link error report */ |
| 396 | |
| 397 | if (!tb[NLMSGERR_ATTR_OFFS] || |
| 398 | os_memcmp(orig_nlh, &err->msg, sizeof(err->msg)) != 0) |
| 399 | return NL_SKIP; |
| 400 | |
| 401 | offset = nla_get_u32(tb[NLMSGERR_ATTR_OFFS]); |
| 402 | |
| 403 | mlo_links = nlmsg_find_attr(orig_nlh, GENL_HDRLEN, |
| 404 | NL80211_ATTR_MLO_LINKS); |
| 405 | if (!mlo_links) |
| 406 | return NL_SKIP; |
| 407 | |
| 408 | nla_for_each_nested(link_attr, mlo_links, rem) { |
| 409 | struct nlattr *link_id; |
| 410 | size_t link_offset = (u8 *) link_attr - (u8 *) orig_nlh; |
| 411 | |
| 412 | if (offset < link_offset || |
| 413 | offset >= link_offset + link_attr->nla_len) |
| 414 | continue; |
| 415 | |
| 416 | link_id = nla_find(nla_data(link_attr), nla_len(link_attr), |
| 417 | NL80211_ATTR_MLO_LINK_ID); |
| 418 | if (link_id) { |
| 419 | err_args->err_info->link_id = nla_get_u8(link_id); |
| 420 | wpa_printf(MSG_DEBUG, |
| 421 | "nl80211: kernel reports error for link: %d", |
| 422 | err_args->err_info->link_id); |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 427 | return NL_SKIP; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 432 | { |
| 433 | return NL_OK; |
| 434 | } |
| 435 | |
| 436 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 437 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 438 | { |
| 439 | /* |
| 440 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 441 | * heap memory for unnecessarily long time. |
| 442 | */ |
| 443 | if (msg) { |
| 444 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 445 | void *data = nlmsg_data(hdr); |
| 446 | /* |
| 447 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 448 | * only libnl were to maintain a stable API.. Neither will work |
| 449 | * with all released versions, so just calculate the length |
| 450 | * here. |
| 451 | */ |
| 452 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 453 | |
| 454 | os_memset(data, 0, len); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 459 | static int send_event_marker(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 460 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 461 | struct nl_sock *handle; |
| 462 | struct nl_msg *msg; |
| 463 | struct nlmsghdr *hdr; |
| 464 | int res = 0; |
| 465 | int err = -NLE_NOMEM; |
| 466 | |
| 467 | msg = nlmsg_alloc(); |
| 468 | if (!msg) |
| 469 | goto out; |
| 470 | |
| 471 | /* We only care about the returned sequence number for matching. */ |
| 472 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) |
| 473 | goto out; |
| 474 | |
| 475 | handle = (void *) (((intptr_t) drv->global->nl_event) ^ |
| 476 | ELOOP_SOCKET_INVALID); |
| 477 | |
| 478 | err = nl_send_auto_complete(handle, msg); |
| 479 | if (err < 0) |
| 480 | goto out; |
| 481 | |
| 482 | hdr = nlmsg_hdr(msg); |
| 483 | res = hdr->nlmsg_seq; |
| 484 | |
| 485 | out: |
| 486 | nlmsg_free(msg); |
| 487 | if (err) |
| 488 | wpa_printf(MSG_INFO, "nl80211: %s failed: %s", |
| 489 | __func__, nl_geterror(err)); |
| 490 | return res; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | int send_and_recv(struct nl80211_global *global, |
| 495 | struct nl_sock *nl_handle, struct nl_msg *msg, |
| 496 | int (*valid_handler)(struct nl_msg *, void *), |
| 497 | void *valid_data, |
| 498 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 499 | void *ack_data, |
| 500 | struct nl80211_err_info *err_info) |
| 501 | { |
| 502 | struct nl_cb *cb, *s_nl_cb; |
| 503 | struct nl80211_ack_err_args err; |
| 504 | int opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 505 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 506 | if (!msg) |
| 507 | return -ENOMEM; |
| 508 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 509 | err.err = -ENOMEM; |
| 510 | |
| 511 | s_nl_cb = nl_socket_get_cb(nl_handle); |
| 512 | cb = nl_cb_clone(s_nl_cb); |
| 513 | nl_cb_put(s_nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 514 | if (!cb) |
| 515 | goto out; |
| 516 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 517 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 518 | opt = 1; |
| 519 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 520 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 521 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 522 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 523 | opt = 1; |
| 524 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 525 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 526 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 527 | err.err = nl_send_auto_complete(nl_handle, msg); |
| 528 | if (err.err < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 529 | wpa_printf(MSG_INFO, |
| 530 | "nl80211: nl_send_auto_complete() failed: %s", |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 531 | nl_geterror(err.err)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 532 | /* Need to convert libnl error code to an errno value. For now, |
| 533 | * just hardcode this to EBADF; the real error reason is shown |
| 534 | * in that error print above. */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 535 | err.err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 536 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 537 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 538 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 539 | err.err = 1; |
| 540 | err.orig_msg = msg; |
| 541 | err.err_info = err_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 542 | |
| 543 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 544 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 545 | if (ack_handler_custom) { |
| 546 | struct nl80211_ack_ext_arg *ext_arg = ack_data; |
| 547 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 548 | ext_arg->err = &err.err; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 549 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, |
| 550 | ack_handler_custom, ack_data); |
| 551 | } else { |
| 552 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 553 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 554 | |
| 555 | if (valid_handler) |
| 556 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 557 | valid_handler, valid_data); |
| 558 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 559 | while (err.err > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 560 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 561 | |
| 562 | if (res == -NLE_DUMP_INTR) { |
| 563 | /* Most likely one of the nl80211 dump routines hit a |
| 564 | * case where internal results changed while the dump |
| 565 | * was being sent. The most common known case for this |
| 566 | * is scan results fetching while associated were every |
| 567 | * received Beacon frame from the AP may end up |
| 568 | * incrementing bss_generation. This |
| 569 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 570 | * other cases (of which there are no known common ones) |
| 571 | * will stop and return an error. */ |
| 572 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 573 | nl_geterror(res)); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 574 | err.err = -EAGAIN; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 575 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 576 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 577 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 578 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 581 | out: |
| 582 | nl_cb_put(cb); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 583 | /* Always clear the message as it can potentially contain keys */ |
| 584 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 585 | nlmsg_free(msg); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 586 | return err.err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 590 | static int nl80211_put_control_port(struct wpa_driver_nl80211_data *drv, |
| 591 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 592 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 593 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT) || |
| 594 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 595 | ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && |
| 596 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || |
| 597 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH)))) |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 598 | return -1; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 599 | return 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 603 | struct family_data { |
| 604 | const char *group; |
| 605 | int id; |
| 606 | }; |
| 607 | |
| 608 | |
| 609 | static int family_handler(struct nl_msg *msg, void *arg) |
| 610 | { |
| 611 | struct family_data *res = arg; |
| 612 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 613 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 614 | struct nlattr *mcgrp; |
| 615 | int i; |
| 616 | |
| 617 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 618 | genlmsg_attrlen(gnlh, 0), NULL); |
| 619 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 620 | return NL_SKIP; |
| 621 | |
| 622 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 623 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 624 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 625 | nla_len(mcgrp), NULL); |
| 626 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 627 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 628 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 629 | res->group, |
| 630 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 631 | continue; |
| 632 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 633 | break; |
| 634 | }; |
| 635 | |
| 636 | return NL_SKIP; |
| 637 | } |
| 638 | |
| 639 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 640 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 641 | const char *family, const char *group) |
| 642 | { |
| 643 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 644 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 645 | struct family_data res = { group, -ENOENT }; |
| 646 | |
| 647 | msg = nlmsg_alloc(); |
| 648 | if (!msg) |
| 649 | return -ENOMEM; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 650 | if (!genlmsg_put(msg, 0, 0, global->nlctrl_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 651 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 652 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 653 | nlmsg_free(msg); |
| 654 | return -1; |
| 655 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 656 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 657 | ret = send_and_recv(global, global->nl, msg, family_handler, &res, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 658 | NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 659 | if (ret == 0) |
| 660 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 665 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 666 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 667 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 668 | if (TEST_FAIL()) |
| 669 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 670 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 671 | 0, flags, cmd, 0); |
| 672 | } |
| 673 | |
| 674 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 675 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 676 | { |
| 677 | if (bss->wdev_id_set) |
| 678 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 679 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 684 | { |
| 685 | struct nl_msg *msg; |
| 686 | |
| 687 | msg = nlmsg_alloc(); |
| 688 | if (!msg) |
| 689 | return NULL; |
| 690 | |
| 691 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 692 | nl80211_set_iface_id(msg, bss) < 0) { |
| 693 | nlmsg_free(msg); |
| 694 | return NULL; |
| 695 | } |
| 696 | |
| 697 | return msg; |
| 698 | } |
| 699 | |
| 700 | |
| 701 | static struct nl_msg * |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 702 | nl80211_ifindex_msg_build(struct wpa_driver_nl80211_data *drv, |
| 703 | struct nl_msg *msg, int ifindex, int flags, |
| 704 | uint8_t cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 705 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 706 | if (!msg) |
| 707 | return NULL; |
| 708 | |
| 709 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 710 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 711 | nlmsg_free(msg); |
| 712 | return NULL; |
| 713 | } |
| 714 | |
| 715 | return msg; |
| 716 | } |
| 717 | |
| 718 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 719 | static struct nl_msg * |
| 720 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 721 | int flags, uint8_t cmd) |
| 722 | { |
| 723 | return nl80211_ifindex_msg_build(drv, nlmsg_alloc(), ifindex, flags, |
| 724 | cmd); |
| 725 | } |
| 726 | |
| 727 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 728 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 729 | uint8_t cmd) |
| 730 | { |
| 731 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 736 | { |
| 737 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 738 | } |
| 739 | |
| 740 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 741 | struct wiphy_idx_data { |
| 742 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 743 | enum nl80211_iftype nlmode; |
| 744 | u8 *macaddr; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 745 | u8 use_4addr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 746 | }; |
| 747 | |
| 748 | |
| 749 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 750 | { |
| 751 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 752 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 753 | struct wiphy_idx_data *info = arg; |
| 754 | |
| 755 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 756 | genlmsg_attrlen(gnlh, 0), NULL); |
| 757 | |
| 758 | if (tb[NL80211_ATTR_WIPHY]) |
| 759 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 760 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 761 | if (tb[NL80211_ATTR_IFTYPE]) |
| 762 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 763 | |
| 764 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 765 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 766 | ETH_ALEN); |
| 767 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 768 | if (tb[NL80211_ATTR_4ADDR]) |
| 769 | info->use_4addr = nla_get_u8(tb[NL80211_ATTR_4ADDR]); |
| 770 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 771 | return NL_SKIP; |
| 772 | } |
| 773 | |
| 774 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 775 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 776 | { |
| 777 | struct nl_msg *msg; |
| 778 | struct wiphy_idx_data data = { |
| 779 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 780 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 781 | }; |
| 782 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 783 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 784 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 785 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 786 | if (send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 787 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 788 | return -1; |
| 789 | } |
| 790 | |
| 791 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 792 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 793 | { |
| 794 | struct nl_msg *msg; |
| 795 | struct wiphy_idx_data data = { |
| 796 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 797 | .macaddr = NULL, |
| 798 | }; |
| 799 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 800 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 801 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 802 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 803 | if (send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data) == 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 804 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 805 | return NL80211_IFTYPE_UNSPECIFIED; |
| 806 | } |
| 807 | |
| 808 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 809 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 810 | { |
| 811 | struct nl_msg *msg; |
| 812 | struct wiphy_idx_data data = { |
| 813 | .macaddr = bss->addr, |
| 814 | }; |
| 815 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 816 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 817 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 818 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 819 | return send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 820 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 821 | |
| 822 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 823 | static int nl80211_get_4addr(struct i802_bss *bss) |
| 824 | { |
| 825 | struct nl_msg *msg; |
| 826 | struct wiphy_idx_data data = { |
| 827 | .use_4addr = 0, |
| 828 | }; |
| 829 | |
| 830 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)) || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 831 | send_and_recv_resp(bss->drv, msg, netdev_info_handler, &data)) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 832 | return -1; |
| 833 | return data.use_4addr; |
| 834 | } |
| 835 | |
| 836 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 837 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 838 | struct nl80211_wiphy_data *w) |
| 839 | { |
| 840 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 841 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 842 | |
| 843 | msg = nlmsg_alloc(); |
| 844 | if (!msg) |
| 845 | return -1; |
| 846 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 847 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 848 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 849 | nlmsg_free(msg); |
| 850 | return -1; |
| 851 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 852 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 853 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 854 | NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 855 | if (ret) { |
| 856 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 857 | "failed: ret=%d (%s)", |
| 858 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 859 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 860 | return ret; |
| 861 | } |
| 862 | |
| 863 | |
| 864 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 865 | { |
| 866 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 867 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 868 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 869 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 870 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 871 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 872 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 873 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 874 | __func__, res); |
| 875 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | |
| 879 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 880 | { |
| 881 | struct nl80211_wiphy_data *w = arg; |
| 882 | struct wpa_driver_nl80211_data *drv; |
| 883 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 884 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 885 | union wpa_event_data event; |
| 886 | |
| 887 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 888 | genlmsg_attrlen(gnlh, 0), NULL); |
| 889 | |
| 890 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 891 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 892 | gnlh->cmd); |
| 893 | return NL_SKIP; |
| 894 | } |
| 895 | |
| 896 | if (!tb[NL80211_ATTR_FRAME]) |
| 897 | return NL_SKIP; |
| 898 | |
| 899 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 900 | wiphy_list) { |
| 901 | os_memset(&event, 0, sizeof(event)); |
| 902 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 903 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 904 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 905 | } |
| 906 | |
| 907 | return NL_SKIP; |
| 908 | } |
| 909 | |
| 910 | |
| 911 | static struct nl80211_wiphy_data * |
| 912 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 913 | { |
| 914 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 915 | struct nl80211_wiphy_data *w; |
| 916 | int wiphy_idx, found = 0; |
| 917 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 918 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 919 | |
| 920 | if (bss->wiphy_data != NULL) |
| 921 | return bss->wiphy_data; |
| 922 | |
| 923 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 924 | |
| 925 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 926 | if (w->wiphy_idx == wiphy_idx) |
| 927 | goto add; |
| 928 | } |
| 929 | |
| 930 | /* alloc new one */ |
| 931 | w = os_zalloc(sizeof(*w)); |
| 932 | if (w == NULL) |
| 933 | return NULL; |
| 934 | w->wiphy_idx = wiphy_idx; |
| 935 | dl_list_init(&w->bsss); |
| 936 | dl_list_init(&w->drvs); |
| 937 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 938 | /* Beacon frames not supported in IEEE 802.11ad */ |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 939 | if (ieee80211_freq_to_chan(bss->flink->freq, &channel) != |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 940 | HOSTAPD_MODE_IEEE80211AD) { |
| 941 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 942 | if (!w->nl_cb) { |
| 943 | os_free(w); |
| 944 | return NULL; |
| 945 | } |
| 946 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 947 | no_seq_check, NULL); |
| 948 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 949 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 950 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 951 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 952 | "wiphy beacons"); |
| 953 | if (w->nl_beacons == NULL) { |
| 954 | os_free(w); |
| 955 | return NULL; |
| 956 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 957 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 958 | if (nl80211_register_beacons(bss->drv, w)) { |
| 959 | nl_destroy_handles(&w->nl_beacons); |
| 960 | os_free(w); |
| 961 | return NULL; |
| 962 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 963 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 964 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 965 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 966 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 967 | |
| 968 | dl_list_add(&nl80211_wiphys, &w->list); |
| 969 | |
| 970 | add: |
| 971 | /* drv entry for this bss already there? */ |
| 972 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 973 | if (tmp_bss->drv == bss->drv) { |
| 974 | found = 1; |
| 975 | break; |
| 976 | } |
| 977 | } |
| 978 | /* if not add it */ |
| 979 | if (!found) |
| 980 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 981 | |
| 982 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 983 | bss->wiphy_data = w; |
| 984 | return w; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 989 | { |
| 990 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 991 | struct i802_bss *tmp_bss; |
| 992 | int found = 0; |
| 993 | |
| 994 | if (w == NULL) |
| 995 | return; |
| 996 | bss->wiphy_data = NULL; |
| 997 | dl_list_del(&bss->wiphy_list); |
| 998 | |
| 999 | /* still any for this drv present? */ |
| 1000 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 1001 | if (tmp_bss->drv == bss->drv) { |
| 1002 | found = 1; |
| 1003 | break; |
| 1004 | } |
| 1005 | } |
| 1006 | /* if not remove it */ |
| 1007 | if (!found) |
| 1008 | dl_list_del(&bss->drv->wiphy_list); |
| 1009 | |
| 1010 | if (!dl_list_empty(&w->bsss)) |
| 1011 | return; |
| 1012 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1013 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1014 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1015 | |
| 1016 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1017 | dl_list_del(&w->list); |
| 1018 | os_free(w); |
| 1019 | } |
| 1020 | |
| 1021 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1022 | static unsigned int nl80211_get_ifindex(void *priv) |
| 1023 | { |
| 1024 | struct i802_bss *bss = priv; |
| 1025 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1026 | |
| 1027 | return drv->ifindex; |
| 1028 | } |
| 1029 | |
| 1030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 1032 | { |
| 1033 | struct i802_bss *bss = priv; |
| 1034 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1035 | if (!drv->associated) |
| 1036 | return -1; |
| 1037 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 1043 | { |
| 1044 | struct i802_bss *bss = priv; |
| 1045 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1046 | if (!drv->associated) |
| 1047 | return -1; |
| 1048 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 1049 | return drv->ssid_len; |
| 1050 | } |
| 1051 | |
| 1052 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1053 | static int get_mlo_info(struct nl_msg *msg, void *arg) |
| 1054 | { |
| 1055 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1056 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1057 | struct nlattr *link_attr, *link_data[NL80211_ATTR_MAX + 1]; |
| 1058 | static struct nla_policy link_policy[NL80211_ATTR_MAX + 1] = { |
| 1059 | [NL80211_ATTR_MLO_LINK_ID] = { .type = NLA_U8 }, |
| 1060 | [NL80211_ATTR_MAC] = { .minlen = ETH_ALEN, .maxlen = ETH_ALEN }, |
| 1061 | }; |
| 1062 | struct driver_sta_mlo_info *info = arg; |
| 1063 | int rem; |
| 1064 | |
| 1065 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1066 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1067 | |
| 1068 | if (!tb[NL80211_ATTR_MLO_LINKS]) |
| 1069 | return NL_SKIP; |
| 1070 | |
| 1071 | info->valid_links = 0; |
| 1072 | nla_for_each_nested(link_attr, tb[NL80211_ATTR_MLO_LINKS], rem) { |
| 1073 | u8 link_id; |
| 1074 | |
| 1075 | if (nla_parse_nested(link_data, NL80211_ATTR_MAX, |
| 1076 | link_attr, link_policy) != 0) |
| 1077 | continue; |
| 1078 | |
| 1079 | if (!link_data[NL80211_ATTR_MLO_LINK_ID] || |
| 1080 | !link_data[NL80211_ATTR_MAC]) |
| 1081 | continue; |
| 1082 | |
| 1083 | link_id = nla_get_u8(link_data[NL80211_ATTR_MLO_LINK_ID]); |
| 1084 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 1085 | continue; |
| 1086 | info->valid_links |= BIT(link_id); |
| 1087 | os_memcpy(info->links[link_id].addr, |
| 1088 | nla_data(link_data[NL80211_ATTR_MAC]), ETH_ALEN); |
| 1089 | if (link_data[NL80211_ATTR_WIPHY_FREQ]) |
| 1090 | info->links[link_id].freq = |
| 1091 | nla_get_u32(link_data[NL80211_ATTR_WIPHY_FREQ]); |
| 1092 | } |
| 1093 | |
| 1094 | return NL_SKIP; |
| 1095 | } |
| 1096 | |
| 1097 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1098 | static int nl80211_get_sta_mlo_info(void *priv, |
| 1099 | struct driver_sta_mlo_info *mlo_info) |
| 1100 | { |
| 1101 | struct i802_bss *bss = priv; |
| 1102 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1103 | |
| 1104 | if (!drv->associated) |
| 1105 | return -1; |
| 1106 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1107 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1108 | struct nl_msg *msg; |
| 1109 | |
| 1110 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1111 | if (send_and_recv_resp(drv, msg, get_mlo_info, |
| 1112 | &drv->sta_mlo_info)) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1113 | return -1; |
| 1114 | } |
| 1115 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1116 | os_memcpy(mlo_info, &drv->sta_mlo_info, sizeof(*mlo_info)); |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1121 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1122 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1123 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1124 | { |
| 1125 | union wpa_event_data event; |
| 1126 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1127 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1128 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 1129 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 1130 | drv->first_bss->ifname); |
| 1131 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1132 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1133 | if (!drv->if_removed) |
| 1134 | return; |
| 1135 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 1136 | drv->first_bss->ifname); |
| 1137 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1140 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1141 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1142 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1143 | sizeof(event.interface_status.ifname)); |
| 1144 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1145 | if (drv) |
| 1146 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1147 | else |
| 1148 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1149 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1154 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1155 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1156 | { |
| 1157 | union wpa_event_data event; |
| 1158 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1159 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1160 | if (drv->if_removed) { |
| 1161 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1162 | ifname); |
| 1163 | return; |
| 1164 | } |
| 1165 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1166 | ifname); |
| 1167 | drv->if_removed = 1; |
| 1168 | } else { |
| 1169 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1170 | ifname); |
| 1171 | } |
| 1172 | |
| 1173 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1174 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1175 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1176 | sizeof(event.interface_status.ifname)); |
| 1177 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1178 | if (drv) |
| 1179 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1180 | else |
| 1181 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1182 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1187 | u8 *buf, size_t len) |
| 1188 | { |
| 1189 | int attrlen, rta_len; |
| 1190 | struct rtattr *attr; |
| 1191 | |
| 1192 | attrlen = len; |
| 1193 | attr = (struct rtattr *) buf; |
| 1194 | |
| 1195 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1196 | while (RTA_OK(attr, attrlen)) { |
| 1197 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1198 | if (os_strcmp(((char *) attr) + rta_len, |
| 1199 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | return 1; |
| 1201 | else |
| 1202 | break; |
| 1203 | } |
| 1204 | attr = RTA_NEXT(attr, attrlen); |
| 1205 | } |
| 1206 | |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1212 | int ifindex, u8 *buf, size_t len) |
| 1213 | { |
| 1214 | if (drv->ifindex == ifindex) |
| 1215 | return 1; |
| 1216 | |
| 1217 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1218 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1219 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1220 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1221 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 1222 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1223 | return 1; |
| 1224 | } |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1230 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1231 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 1232 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1233 | { |
| 1234 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1235 | int res; |
| 1236 | |
| 1237 | if (init_failed) |
| 1238 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1239 | dl_list_for_each(drv, &global->interfaces, |
| 1240 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1241 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1242 | if (res < 0) { |
| 1243 | wpa_printf(MSG_DEBUG, |
| 1244 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1245 | if (init_failed) |
| 1246 | *init_failed = 1; |
| 1247 | return drv; |
| 1248 | } |
| 1249 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1250 | return drv; |
| 1251 | } |
| 1252 | return NULL; |
| 1253 | } |
| 1254 | |
| 1255 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1256 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1257 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1258 | { |
| 1259 | struct i802_bss *bss; |
| 1260 | u8 addr[ETH_ALEN]; |
| 1261 | |
| 1262 | bss = get_bss_ifindex(drv, ifindex); |
| 1263 | if (bss && |
| 1264 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1265 | bss->ifname, addr) < 0) { |
| 1266 | wpa_printf(MSG_DEBUG, |
| 1267 | "nl80211: %s: failed to re-read MAC address", |
| 1268 | bss->ifname); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1269 | } else if (bss && !ether_addr_equal(addr, bss->addr)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1270 | wpa_printf(MSG_DEBUG, |
| 1271 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1272 | MACSTR " to " MACSTR, |
| 1273 | ifindex, bss->ifname, |
| 1274 | MAC2STR(bss->addr), MAC2STR(addr)); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1275 | os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1276 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1277 | if (notify) |
| 1278 | wpa_supplicant_event(drv->ctx, |
| 1279 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1284 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1285 | struct ifinfomsg *ifi, |
| 1286 | u8 *buf, size_t len) |
| 1287 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1288 | struct nl80211_global *global = ctx; |
| 1289 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1290 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1291 | struct rtattr *attr; |
| 1292 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1293 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1294 | char ifname[IFNAMSIZ + 1]; |
| 1295 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1296 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1297 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1298 | extra[0] = '\0'; |
| 1299 | pos = extra; |
| 1300 | end = pos + sizeof(extra); |
| 1301 | ifname[0] = '\0'; |
| 1302 | |
| 1303 | attrlen = len; |
| 1304 | attr = (struct rtattr *) buf; |
| 1305 | while (RTA_OK(attr, attrlen)) { |
| 1306 | switch (attr->rta_type) { |
| 1307 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1308 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1309 | break; |
| 1310 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1311 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1312 | break; |
| 1313 | case IFLA_MASTER: |
| 1314 | brid = nla_get_u32((struct nlattr *) attr); |
| 1315 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1316 | break; |
| 1317 | case IFLA_WIRELESS: |
| 1318 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1319 | break; |
| 1320 | case IFLA_OPERSTATE: |
| 1321 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1322 | nla_get_u32((struct nlattr *) attr)); |
| 1323 | break; |
| 1324 | case IFLA_LINKMODE: |
| 1325 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1326 | nla_get_u32((struct nlattr *) attr)); |
| 1327 | break; |
| 1328 | } |
| 1329 | attr = RTA_NEXT(attr, attrlen); |
| 1330 | } |
| 1331 | extra[sizeof(extra) - 1] = '\0'; |
| 1332 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1333 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1334 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1335 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1336 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1337 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1338 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1339 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1340 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1341 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1342 | if (!drv) |
| 1343 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1344 | if (init_failed) |
| 1345 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1346 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1347 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1348 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1349 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1350 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1351 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1352 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1353 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1354 | /* Re-read MAC address as it may have changed */ |
| 1355 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1356 | return; |
| 1357 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1358 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1359 | namebuf, ifname); |
| 1360 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1361 | wpa_printf(MSG_DEBUG, |
| 1362 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1363 | drv->first_bss->ifname); |
| 1364 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1365 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1366 | "event generated by mode change"); |
| 1367 | drv->ignore_if_down_event = 0; |
| 1368 | } else { |
| 1369 | drv->if_disabled = 1; |
| 1370 | wpa_supplicant_event(drv->ctx, |
| 1371 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1372 | |
| 1373 | /* |
| 1374 | * Try to get drv again, since it may be removed as |
| 1375 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1376 | * dynamic interfaces |
| 1377 | */ |
| 1378 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1379 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1380 | if (!drv) |
| 1381 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1382 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1386 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1387 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1388 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1389 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1390 | "event since interface %s is down", |
| 1391 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1392 | return; |
| 1393 | } |
| 1394 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1395 | namebuf, ifname); |
| 1396 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1397 | wpa_printf(MSG_DEBUG, |
| 1398 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1399 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1400 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1401 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1402 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1403 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1404 | } else if (drv->if_removed) { |
| 1405 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1406 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1407 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1408 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1409 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1410 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1411 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1412 | drv->if_disabled = 0; |
| 1413 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1414 | NULL); |
| 1415 | } |
Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1416 | } else if (ifi->ifi_flags & IFF_UP) { |
| 1417 | /* Re-read MAC address as it may have changed */ |
| 1418 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /* |
| 1422 | * Some drivers send the association event before the operup event--in |
| 1423 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1424 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1425 | * IEEE 802.1X authentication |
| 1426 | */ |
| 1427 | if (drv->operstate == 1 && |
| 1428 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1429 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1430 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1431 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1432 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1435 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1436 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1437 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1438 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1439 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1440 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1441 | struct i802_bss *bss; |
| 1442 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1443 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1444 | if (!if_indextoname(brid, namebuf)) { |
| 1445 | wpa_printf(MSG_DEBUG, |
| 1446 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1447 | brid); |
| 1448 | return; |
| 1449 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1450 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1451 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1452 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1453 | |
| 1454 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1455 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1456 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1457 | break; |
| 1458 | } |
| 1459 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1465 | struct ifinfomsg *ifi, |
| 1466 | u8 *buf, size_t len) |
| 1467 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1468 | struct nl80211_global *global = ctx; |
| 1469 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1470 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1471 | struct rtattr *attr; |
| 1472 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1473 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1474 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1475 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1476 | extra[0] = '\0'; |
| 1477 | pos = extra; |
| 1478 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1479 | ifname[0] = '\0'; |
| 1480 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1481 | attrlen = len; |
| 1482 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1483 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1484 | switch (attr->rta_type) { |
| 1485 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1486 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1487 | break; |
| 1488 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1489 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1490 | break; |
| 1491 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1492 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1493 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1494 | break; |
| 1495 | case IFLA_OPERSTATE: |
| 1496 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1497 | nla_get_u32((struct nlattr *) attr)); |
| 1498 | break; |
| 1499 | case IFLA_LINKMODE: |
| 1500 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1501 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1502 | break; |
| 1503 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1504 | attr = RTA_NEXT(attr, attrlen); |
| 1505 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1506 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1507 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1508 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1509 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1510 | ifi->ifi_flags, |
| 1511 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1512 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1513 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1514 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1515 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1516 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1517 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1518 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1519 | /* device has been removed from bridge */ |
| 1520 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1521 | |
| 1522 | if (!if_indextoname(brid, namebuf)) { |
| 1523 | wpa_printf(MSG_DEBUG, |
| 1524 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1525 | brid); |
| 1526 | } else { |
| 1527 | wpa_printf(MSG_DEBUG, |
| 1528 | "nl80211: Remove ifindex %u for bridge %s", |
| 1529 | brid, namebuf); |
| 1530 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1531 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1532 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1533 | |
| 1534 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1535 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1536 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1540 | struct nl80211_get_assoc_freq_arg { |
| 1541 | struct wpa_driver_nl80211_data *drv; |
| 1542 | unsigned int assoc_freq; |
| 1543 | unsigned int ibss_freq; |
| 1544 | u8 assoc_bssid[ETH_ALEN]; |
| 1545 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1546 | u8 assoc_ssid_len; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1547 | u8 bssid[MAX_NUM_MLD_LINKS][ETH_ALEN]; |
| 1548 | unsigned int freq[MAX_NUM_MLD_LINKS]; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1549 | }; |
| 1550 | |
| 1551 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1552 | { |
| 1553 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1554 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1555 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1556 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1557 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1558 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1559 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1560 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1561 | [NL80211_BSS_MLO_LINK_ID] = { .type = NLA_U8 }, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1562 | }; |
| 1563 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1564 | enum nl80211_bss_status status; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1565 | struct wpa_driver_nl80211_data *drv = ctx->drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1566 | |
| 1567 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1568 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1569 | if (!tb[NL80211_ATTR_BSS] || |
| 1570 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1571 | bss_policy) || |
| 1572 | !bss[NL80211_BSS_STATUS]) |
| 1573 | return NL_SKIP; |
| 1574 | |
| 1575 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1576 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1577 | bss[NL80211_BSS_FREQUENCY]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1578 | int link_id = -1; |
| 1579 | u32 freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1580 | |
| 1581 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1582 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1583 | |
| 1584 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1585 | ctx->freq[link_id] = freq; |
| 1586 | wpa_printf(MSG_DEBUG, |
| 1587 | "nl80211: MLO link %d associated on %u MHz", |
| 1588 | link_id, ctx->freq[link_id]); |
| 1589 | } |
| 1590 | |
| 1591 | if (!drv->sta_mlo_info.valid_links || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1592 | drv->sta_mlo_info.assoc_link_id == link_id) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1593 | ctx->assoc_freq = freq; |
| 1594 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1595 | ctx->assoc_freq); |
| 1596 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1597 | } |
| 1598 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1599 | bss[NL80211_BSS_FREQUENCY]) { |
| 1600 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1601 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1602 | ctx->ibss_freq); |
| 1603 | } |
| 1604 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1605 | bss[NL80211_BSS_BSSID]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1606 | int link_id = -1; |
| 1607 | const u8 *bssid = nla_data(bss[NL80211_BSS_BSSID]); |
| 1608 | |
| 1609 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1610 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1611 | |
| 1612 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1613 | os_memcpy(ctx->bssid[link_id], bssid, ETH_ALEN); |
| 1614 | wpa_printf(MSG_DEBUG, |
| 1615 | "nl80211: MLO link %d associated with " |
| 1616 | MACSTR, link_id, MAC2STR(bssid)); |
| 1617 | } |
| 1618 | |
| 1619 | if (!drv->sta_mlo_info.valid_links || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1620 | drv->sta_mlo_info.assoc_link_id == link_id) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1621 | os_memcpy(ctx->assoc_bssid, bssid, ETH_ALEN); |
| 1622 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1623 | MACSTR, MAC2STR(bssid)); |
| 1624 | } |
| 1625 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1629 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1630 | const u8 *ie, *ssid; |
| 1631 | size_t ie_len; |
| 1632 | |
| 1633 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1634 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1635 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1636 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1637 | ctx->assoc_ssid_len = ssid[1]; |
| 1638 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | return NL_SKIP; |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1647 | { |
| 1648 | struct nl_msg *msg; |
| 1649 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1650 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1651 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1652 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1653 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1654 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1655 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1656 | arg.drv = drv; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1657 | ret = send_and_recv_resp(drv, msg, nl80211_get_assoc_freq_handler, |
| 1658 | &arg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1659 | if (ret == -EAGAIN) { |
| 1660 | count++; |
| 1661 | if (count >= 10) { |
| 1662 | wpa_printf(MSG_INFO, |
| 1663 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1664 | } else { |
| 1665 | wpa_printf(MSG_DEBUG, |
| 1666 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1667 | goto try_again; |
| 1668 | } |
| 1669 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1670 | if (ret == 0) { |
| 1671 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1672 | return arg.assoc_ssid_len; |
| 1673 | } |
| 1674 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1675 | ret, strerror(-ret)); |
| 1676 | return ret; |
| 1677 | } |
| 1678 | |
| 1679 | |
| 1680 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1681 | { |
| 1682 | struct nl_msg *msg; |
| 1683 | int ret; |
| 1684 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1685 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1686 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1687 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1688 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1689 | os_memset(&arg, 0, sizeof(arg)); |
| 1690 | arg.drv = drv; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1691 | ret = send_and_recv_resp(drv, msg, nl80211_get_assoc_freq_handler, |
| 1692 | &arg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1693 | if (ret == -EAGAIN) { |
| 1694 | count++; |
| 1695 | if (count >= 10) { |
| 1696 | wpa_printf(MSG_INFO, |
| 1697 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1698 | } else { |
| 1699 | wpa_printf(MSG_DEBUG, |
| 1700 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1701 | goto try_again; |
| 1702 | } |
| 1703 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1704 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1705 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1706 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1707 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1708 | "associated BSS from scan results: %u MHz", freq); |
| 1709 | if (freq) |
| 1710 | drv->assoc_freq = freq; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1711 | |
| 1712 | if (drv->sta_mlo_info.valid_links) { |
| 1713 | int i; |
| 1714 | |
| 1715 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) |
| 1716 | drv->sta_mlo_info.links[i].freq = arg.freq[i]; |
| 1717 | } |
| 1718 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1719 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1720 | } |
| 1721 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1722 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1723 | return drv->assoc_freq; |
| 1724 | } |
| 1725 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1726 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1727 | { |
| 1728 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1729 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1730 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1731 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1732 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1733 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1734 | }; |
| 1735 | struct wpa_signal_info *sig_change = arg; |
| 1736 | |
| 1737 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1738 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1739 | |
| 1740 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1741 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1742 | return NL_SKIP; |
| 1743 | } |
| 1744 | |
| 1745 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1746 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1747 | survey_policy)) { |
| 1748 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1749 | "attributes!"); |
| 1750 | return NL_SKIP; |
| 1751 | } |
| 1752 | |
| 1753 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1754 | return NL_SKIP; |
| 1755 | |
| 1756 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1757 | sig_change->frequency) |
| 1758 | return NL_SKIP; |
| 1759 | |
| 1760 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1761 | return NL_SKIP; |
| 1762 | |
| 1763 | sig_change->current_noise = |
| 1764 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1765 | |
| 1766 | return NL_SKIP; |
| 1767 | } |
| 1768 | |
| 1769 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1770 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1771 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1772 | { |
| 1773 | struct nl_msg *msg; |
| 1774 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1775 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1776 | sig_change->frequency = drv->assoc_freq; |
| 1777 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1778 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1779 | return send_and_recv_resp(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1783 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1784 | { |
| 1785 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1786 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1787 | struct wpa_channel_info *chan_info = arg; |
| 1788 | |
| 1789 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1790 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1791 | |
| 1792 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1793 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1794 | |
| 1795 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1796 | chan_info->frequency = |
| 1797 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1798 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1799 | chan_info->chanwidth = convert2width( |
| 1800 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1801 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1802 | enum nl80211_channel_type ct = |
| 1803 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1804 | |
| 1805 | switch (ct) { |
| 1806 | case NL80211_CHAN_HT40MINUS: |
| 1807 | chan_info->sec_channel = -1; |
| 1808 | break; |
| 1809 | case NL80211_CHAN_HT40PLUS: |
| 1810 | chan_info->sec_channel = 1; |
| 1811 | break; |
| 1812 | default: |
| 1813 | chan_info->sec_channel = 0; |
| 1814 | break; |
| 1815 | } |
| 1816 | } |
| 1817 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1818 | chan_info->center_frq1 = |
| 1819 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1820 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1821 | chan_info->center_frq2 = |
| 1822 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1823 | |
| 1824 | if (chan_info->center_frq2) { |
| 1825 | u8 seg1_idx = 0; |
| 1826 | |
| 1827 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1828 | NUM_HOSTAPD_MODES) |
| 1829 | chan_info->seg1_idx = seg1_idx; |
| 1830 | } |
| 1831 | |
| 1832 | return NL_SKIP; |
| 1833 | } |
| 1834 | |
| 1835 | |
| 1836 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1837 | { |
| 1838 | struct i802_bss *bss = priv; |
| 1839 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1840 | struct nl_msg *msg; |
| 1841 | |
| 1842 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1843 | return send_and_recv_resp(drv, msg, get_channel_info, ci); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1847 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1848 | void *handle) |
| 1849 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1850 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1851 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1852 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1853 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1854 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1855 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1856 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1857 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1858 | __func__, res); |
| 1859 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | /** |
| 1864 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1865 | * @priv: driver_nl80211 private data |
| 1866 | * @alpha2_arg: country to which to switch to |
| 1867 | * Returns: 0 on success, -1 on failure |
| 1868 | * |
| 1869 | * This asks nl80211 to set the regulatory domain for given |
| 1870 | * country ISO / IEC alpha2. |
| 1871 | */ |
| 1872 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1873 | { |
| 1874 | struct i802_bss *bss = priv; |
| 1875 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1876 | char alpha2[3]; |
| 1877 | struct nl_msg *msg; |
| 1878 | |
| 1879 | msg = nlmsg_alloc(); |
| 1880 | if (!msg) |
| 1881 | return -ENOMEM; |
| 1882 | |
| 1883 | alpha2[0] = alpha2_arg[0]; |
| 1884 | alpha2[1] = alpha2_arg[1]; |
| 1885 | alpha2[2] = '\0'; |
| 1886 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1887 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1888 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1889 | nlmsg_free(msg); |
| 1890 | return -EINVAL; |
| 1891 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1892 | if (send_and_recv_cmd(drv, msg)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1893 | return -EINVAL; |
| 1894 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1898 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1899 | { |
| 1900 | char *alpha2 = arg; |
| 1901 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1902 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1903 | |
| 1904 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1905 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1906 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1907 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1908 | return NL_SKIP; |
| 1909 | } |
| 1910 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1911 | return NL_SKIP; |
| 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1916 | { |
| 1917 | struct i802_bss *bss = priv; |
| 1918 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1919 | struct nl_msg *msg; |
| 1920 | int ret; |
| 1921 | |
| 1922 | msg = nlmsg_alloc(); |
| 1923 | if (!msg) |
| 1924 | return -ENOMEM; |
| 1925 | |
| 1926 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1927 | |
| 1928 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SELF_MANAGED_REGULATORY) { |
| 1929 | /* put wiphy idx to get the interface specific country code |
| 1930 | * instead of the global one. */ |
| 1931 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx)) { |
| 1932 | nlmsg_free(msg); |
| 1933 | return -1; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1937 | alpha2[0] = '\0'; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1938 | ret = send_and_recv_resp(drv, msg, nl80211_get_country, alpha2); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1939 | if (!alpha2[0]) |
| 1940 | ret = -1; |
| 1941 | |
| 1942 | return ret; |
| 1943 | } |
| 1944 | |
| 1945 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1946 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1947 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1948 | struct nl_cache *cache = NULL; |
| 1949 | struct genl_family *family = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1950 | int ret; |
| 1951 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1952 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1953 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1954 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1955 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1956 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1959 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1960 | if (global->nl == NULL) |
| 1961 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1962 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1963 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1964 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1965 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1966 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1967 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1970 | global->nlctrl_id = genl_ctrl_resolve(global->nl, "nlctrl"); |
| 1971 | if (global->nlctrl_id < 0) { |
| 1972 | wpa_printf(MSG_ERROR, |
| 1973 | "nl80211: 'nlctrl' generic netlink not found"); |
| 1974 | goto err; |
| 1975 | } |
| 1976 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1977 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1978 | if (global->nl_event == NULL) |
| 1979 | goto err; |
| 1980 | |
| 1981 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1983 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1984 | if (ret < 0) { |
| 1985 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1986 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1987 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1988 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1991 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1992 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1993 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1994 | if (ret < 0) { |
| 1995 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1996 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1997 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1998 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2001 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2002 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2003 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2004 | if (ret < 0) { |
| 2005 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 2006 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2007 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2008 | /* Continue without regulatory events */ |
| 2009 | } |
| 2010 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2011 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 2012 | if (ret >= 0) |
| 2013 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 2014 | if (ret < 0) { |
| 2015 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 2016 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2017 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2018 | /* Continue without vendor events */ |
| 2019 | } |
| 2020 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2021 | /* Resolve maxattr for kernel support checks */ |
| 2022 | ret = genl_ctrl_alloc_cache(global->nl, &cache); |
| 2023 | if (ret < 0) { |
| 2024 | wpa_printf(MSG_DEBUG, |
| 2025 | "nl80211: Could not allocate genl cache: %d (%s)", |
| 2026 | ret, nl_geterror(ret)); |
| 2027 | goto err; |
| 2028 | } |
| 2029 | |
| 2030 | family = genl_ctrl_search(cache, global->nl80211_id); |
| 2031 | if (!family) { |
| 2032 | wpa_printf(MSG_DEBUG, |
| 2033 | "nl80211: Could not get nl80211 family from cache: %d (%s)", |
| 2034 | ret, nl_geterror(ret)); |
| 2035 | goto err; |
| 2036 | } |
| 2037 | |
| 2038 | global->nl80211_maxattr = genl_family_get_maxattr(family); |
| 2039 | wpa_printf(MSG_DEBUG, "nl80211: Maximum supported attribute ID: %u", |
| 2040 | global->nl80211_maxattr); |
| 2041 | genl_family_put(family); |
| 2042 | nl_cache_free(cache); |
| 2043 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2044 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2045 | no_seq_check, NULL); |
| 2046 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2047 | process_global_event, global); |
| 2048 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2049 | nl80211_register_eloop_read(&global->nl_event, |
| 2050 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2051 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2052 | |
| 2053 | return 0; |
| 2054 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2055 | err: |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2056 | genl_family_put(family); |
| 2057 | nl_cache_free(cache); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2058 | nl_destroy_handles(&global->nl_event); |
| 2059 | nl_destroy_handles(&global->nl); |
| 2060 | nl_cb_put(global->nl_cb); |
| 2061 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2062 | return -1; |
| 2063 | } |
| 2064 | |
| 2065 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2066 | static void nl80211_check_global(struct nl80211_global *global) |
| 2067 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2068 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2069 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 2070 | int ret; |
| 2071 | unsigned int i; |
| 2072 | |
| 2073 | /* |
| 2074 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 2075 | * and all registration having been cleared. |
| 2076 | */ |
| 2077 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 2078 | ELOOP_SOCKET_INVALID); |
| 2079 | |
| 2080 | for (i = 0; groups[i]; i++) { |
| 2081 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 2082 | if (ret >= 0) |
| 2083 | ret = nl_socket_add_membership(handle, ret); |
| 2084 | if (ret < 0) { |
| 2085 | wpa_printf(MSG_INFO, |
| 2086 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2087 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 2094 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2095 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2096 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2097 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2098 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2099 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2100 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 2101 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2102 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2103 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2104 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | |
| 2108 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 2109 | { |
| 2110 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2111 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2112 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2113 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 2114 | "after rfkill unblock"); |
| 2115 | return; |
| 2116 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2117 | |
| 2118 | if (is_p2p_net_interface(drv->nlmode)) |
| 2119 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 2120 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2121 | /* |
| 2122 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 2123 | * Device interface as enabled. |
| 2124 | */ |
| 2125 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2126 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2130 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 2131 | void *eloop_ctx, |
| 2132 | void *handle) |
| 2133 | { |
| 2134 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 2135 | u8 data[2048]; |
| 2136 | struct msghdr msg; |
| 2137 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2138 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2139 | struct cmsghdr *cmsg; |
| 2140 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 2141 | union wpa_event_data event; |
| 2142 | |
| 2143 | memset(&msg, 0, sizeof(msg)); |
| 2144 | msg.msg_iov = &entry; |
| 2145 | msg.msg_iovlen = 1; |
| 2146 | entry.iov_base = data; |
| 2147 | entry.iov_len = sizeof(data); |
| 2148 | msg.msg_control = &control; |
| 2149 | msg.msg_controllen = sizeof(control); |
| 2150 | |
| 2151 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 2152 | /* if error or not fitting 802.3 header, return */ |
| 2153 | if (res < 14) |
| 2154 | return; |
| 2155 | |
| 2156 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 2157 | { |
| 2158 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 2159 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 2160 | int *ack; |
| 2161 | |
| 2162 | found_wifi = 1; |
| 2163 | ack = (void *)CMSG_DATA(cmsg); |
| 2164 | acked = *ack; |
| 2165 | } |
| 2166 | |
| 2167 | if (cmsg->cmsg_level == SOL_PACKET && |
| 2168 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 2169 | struct sock_extended_err *err = |
| 2170 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 2171 | |
| 2172 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 2173 | found_ee = 1; |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | if (!found_ee || !found_wifi) |
| 2178 | return; |
| 2179 | |
| 2180 | memset(&event, 0, sizeof(event)); |
| 2181 | event.eapol_tx_status.dst = data; |
| 2182 | event.eapol_tx_status.data = data + 14; |
| 2183 | event.eapol_tx_status.data_len = res - 14; |
| 2184 | event.eapol_tx_status.ack = acked; |
| 2185 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 2186 | } |
| 2187 | |
| 2188 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2189 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2190 | { |
| 2191 | if (bss->nl_connect) { |
| 2192 | wpa_printf(MSG_DEBUG, |
| 2193 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2194 | bss->nl_connect); |
| 2195 | return -1; |
| 2196 | } |
| 2197 | |
| 2198 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2199 | if (!bss->nl_connect) |
| 2200 | return -1; |
| 2201 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2202 | wpa_driver_nl80211_event_receive, |
| 2203 | bss->nl_cb, 1); |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
| 2207 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2208 | static int nl80211_init_bss(struct i802_bss *bss) |
| 2209 | { |
| 2210 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 2211 | if (!bss->nl_cb) |
| 2212 | return -1; |
| 2213 | |
| 2214 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2215 | no_seq_check, NULL); |
| 2216 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2217 | process_bss_event, bss); |
| 2218 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2219 | nl80211_init_connect_handle(bss); |
| 2220 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2221 | return 0; |
| 2222 | } |
| 2223 | |
| 2224 | |
| 2225 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 2226 | { |
| 2227 | nl_cb_put(bss->nl_cb); |
| 2228 | bss->nl_cb = NULL; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (bss->nl_connect) |
| 2231 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2235 | static void |
| 2236 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 2237 | { |
| 2238 | struct rfkill_config *rcfg; |
| 2239 | |
| 2240 | if (drv->rfkill) |
| 2241 | return; |
| 2242 | |
| 2243 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 2244 | if (!rcfg) |
| 2245 | return; |
| 2246 | |
| 2247 | rcfg->ctx = drv; |
| 2248 | |
| 2249 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 2250 | * not associated with a netdev, so use the name of some other interface |
| 2251 | * sharing the same wiphy as the P2P Device interface. |
| 2252 | * |
| 2253 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 2254 | * created and is created only once another wpa_s interface was added. |
| 2255 | */ |
| 2256 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 2257 | struct nl80211_global *global = drv->global; |
| 2258 | struct wpa_driver_nl80211_data *tmp1; |
| 2259 | |
| 2260 | dl_list_for_each(tmp1, &global->interfaces, |
| 2261 | struct wpa_driver_nl80211_data, list) { |
| 2262 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 2263 | !tmp1->rfkill) |
| 2264 | continue; |
| 2265 | |
| 2266 | wpa_printf(MSG_DEBUG, |
| 2267 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 2268 | tmp1->first_bss->ifname); |
| 2269 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 2270 | sizeof(rcfg->ifname)); |
| 2271 | break; |
| 2272 | } |
| 2273 | } else { |
| 2274 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 2275 | sizeof(rcfg->ifname)); |
| 2276 | } |
| 2277 | |
| 2278 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 2279 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 2280 | drv->rfkill = rfkill_init(rcfg); |
| 2281 | if (!drv->rfkill) { |
| 2282 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 2283 | os_free(rcfg); |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2288 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 2289 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2290 | const u8 *set_addr, |
| 2291 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2292 | { |
| 2293 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2294 | struct i802_bss *bss; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2295 | char path[128], buf[200], *pos; |
| 2296 | ssize_t len; |
| 2297 | int ret; |
| 2298 | |
| 2299 | ret = os_snprintf(path, sizeof(path), "/sys/class/net/%s/device/driver", |
| 2300 | ifname); |
| 2301 | if (!os_snprintf_error(sizeof(path), ret)) { |
| 2302 | len = readlink(path, buf, sizeof(buf)); |
| 2303 | if (len > 0 && (size_t) len < sizeof(buf)) { |
| 2304 | buf[len] = '\0'; |
| 2305 | pos = strrchr(buf, '/'); |
| 2306 | if (pos) |
| 2307 | pos++; |
| 2308 | else |
| 2309 | pos = buf; |
| 2310 | wpa_printf(MSG_DEBUG, |
| 2311 | "nl80211: Initialize interface %s (driver: %s)", |
| 2312 | ifname, pos); |
| 2313 | } |
| 2314 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2315 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2316 | if (global_priv == NULL) |
| 2317 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2318 | drv = os_zalloc(sizeof(*drv)); |
| 2319 | if (drv == NULL) |
| 2320 | return NULL; |
| 2321 | drv->global = global_priv; |
| 2322 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2323 | drv->hostapd = !!hostapd; |
| 2324 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2325 | |
| 2326 | /* |
| 2327 | * There is no driver capability flag for this, so assume it is |
| 2328 | * supported and disable this on first attempt to use if the driver |
| 2329 | * rejects the command due to missing support. |
| 2330 | */ |
| 2331 | drv->set_rekey_offload = 1; |
| 2332 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2333 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2334 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2335 | |
| 2336 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2337 | if (!drv->first_bss) { |
| 2338 | os_free(drv); |
| 2339 | return NULL; |
| 2340 | } |
| 2341 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2342 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2343 | bss->ctx = ctx; |
| 2344 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2345 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2346 | drv->monitor_ifidx = -1; |
| 2347 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2348 | drv->eapol_tx_sock = -1; |
| 2349 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2350 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2351 | if (nl80211_init_bss(bss)) |
| 2352 | goto failed; |
| 2353 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2354 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2355 | goto failed; |
| 2356 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2357 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) { |
| 2358 | drv->control_port_ap = 1; |
| 2359 | goto skip_wifi_status; |
| 2360 | } |
| 2361 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2362 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2363 | if (drv->eapol_tx_sock < 0) |
| 2364 | goto failed; |
| 2365 | |
| 2366 | if (drv->data_tx_status) { |
| 2367 | int enabled = 1; |
| 2368 | |
| 2369 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2370 | &enabled, sizeof(enabled)) < 0) { |
| 2371 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2372 | "nl80211: wifi status sockopt failed: %s", |
| 2373 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2374 | drv->data_tx_status = 0; |
| 2375 | if (!drv->use_monitor) |
| 2376 | drv->capa.flags &= |
| 2377 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2378 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2379 | eloop_register_read_sock( |
| 2380 | drv->eapol_tx_sock, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2381 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2382 | drv, NULL); |
| 2383 | } |
| 2384 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2385 | skip_wifi_status: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2386 | |
| 2387 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2388 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2389 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2390 | drv->in_interface_list = 1; |
| 2391 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2392 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2393 | /* |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2394 | * Use link ID 0 for the single "link" of a non-MLD. |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2395 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2396 | bss->valid_links = 0; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2397 | bss->flink = &bss->links[0]; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2398 | os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN); |
| 2399 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2400 | return bss; |
| 2401 | |
| 2402 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2403 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2404 | return NULL; |
| 2405 | } |
| 2406 | |
| 2407 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2408 | /** |
| 2409 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2410 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2411 | * e.g., wpa_supplicant_event() |
| 2412 | * @ifname: interface name, e.g., wlan0 |
| 2413 | * @global_priv: private driver global data from global_init() |
| 2414 | * Returns: Pointer to private data, %NULL on failure |
| 2415 | */ |
| 2416 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2417 | void *global_priv) |
| 2418 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2419 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2420 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2424 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2425 | struct nl_sock *nl_handle, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2426 | u16 type, const u8 *match, size_t match_len, |
| 2427 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2428 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2429 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2430 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2431 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2432 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2434 | buf[0] = '\0'; |
| 2435 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2436 | wpa_printf(MSG_DEBUG, |
| 2437 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", |
| 2438 | type, fc2str(type), nl_handle, buf, multicast); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2439 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2440 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2441 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2442 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2443 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2444 | nlmsg_free(msg); |
| 2445 | return -1; |
| 2446 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2447 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2448 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2449 | NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2450 | if (ret) { |
| 2451 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2452 | "failed (type=%u): ret=%d (%s)", |
| 2453 | type, ret, strerror(-ret)); |
| 2454 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2455 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2456 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2457 | return ret; |
| 2458 | } |
| 2459 | |
| 2460 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2461 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2462 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2463 | if (bss->nl_mgmt) { |
| 2464 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2465 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2466 | return -1; |
| 2467 | } |
| 2468 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2469 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2470 | if (bss->nl_mgmt == NULL) |
| 2471 | return -1; |
| 2472 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2473 | return 0; |
| 2474 | } |
| 2475 | |
| 2476 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2477 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2478 | { |
| 2479 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2480 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2481 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2485 | static int nl80211_register_action_frame2(struct i802_bss *bss, |
| 2486 | const u8 *match, size_t match_len, |
| 2487 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2488 | { |
| 2489 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2490 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2491 | type, match, match_len, multicast); |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | static int nl80211_register_action_frame(struct i802_bss *bss, |
| 2496 | const u8 *match, size_t match_len) |
| 2497 | { |
| 2498 | return nl80211_register_action_frame2(bss, match, match_len, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2502 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2504 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2505 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2506 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2507 | |
| 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 Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2513 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2514 | /* register for any AUTH message */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2515 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2516 | } 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 Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2520 | (u8 *) "\x03\x00", 2, false); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2523 | #ifdef CONFIG_PASN |
| 2524 | /* register for PASN Authentication frames */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2525 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2526 | (u8 *) "\x07\x00", 2, false)) |
| 2527 | ret = -1; |
| 2528 | #endif /* CONFIG_PASN */ |
| 2529 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2530 | #ifdef CONFIG_INTERWORKING |
| 2531 | /* QoS Map Configure */ |
| 2532 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2533 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2534 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2535 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2536 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2537 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2538 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2539 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2540 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2541 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2542 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2543 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2544 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2545 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2546 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2547 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2548 | /* 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 Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2560 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2561 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2562 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2563 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2564 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2565 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2566 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2567 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2568 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2569 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2570 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2571 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2572 | #endif /* CONFIG_P2P */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2573 | #ifdef CONFIG_NAN_USD |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2574 | #define NAN_PUB_ACTION ((u8 *) "\x04\x09\x50\x6f\x9a\x13") |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2575 | /* NAN SDF Public Action */ |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2576 | if (nl80211_register_action_frame2(bss, NAN_PUB_ACTION, 6, true) < 0) { |
| 2577 | /* fallback to non-multicast */ |
| 2578 | if (nl80211_register_action_frame2(bss, NAN_PUB_ACTION, 6, |
| 2579 | false) < 0) |
| 2580 | ret = -1; |
| 2581 | } |
| 2582 | #undef NAN_PUB_ACTION |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2583 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2584 | #ifdef CONFIG_DPP |
| 2585 | /* DPP Public Action */ |
| 2586 | if (nl80211_register_action_frame(bss, |
| 2587 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2588 | 6) < 0) |
| 2589 | ret = -1; |
| 2590 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2591 | #ifdef CONFIG_OCV |
| 2592 | /* SA Query Request */ |
| 2593 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2594 | ret = -1; |
| 2595 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2596 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2597 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2598 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2599 | #ifdef CONFIG_TDLS |
| 2600 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2601 | /* TDLS Discovery Response */ |
| 2602 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2603 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2604 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2605 | } |
| 2606 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2607 | #ifdef CONFIG_FST |
| 2608 | /* FST Action frames */ |
| 2609 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2610 | ret = -1; |
| 2611 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2612 | |
| 2613 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2614 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2615 | ret = -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2616 | else if (!drv->has_driver_key_mgmt) { |
| 2617 | int i; |
| 2618 | |
| 2619 | /* Update supported AKMs only if the driver doesn't advertize |
| 2620 | * any AKM capabilities. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2621 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2622 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2623 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2624 | /* Update per interface supported AKMs */ |
| 2625 | for (i = 0; i < WPA_IF_MAX; i++) |
| 2626 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; |
| 2627 | } |
| 2628 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2629 | /* WNM - BSS Transition Management Request */ |
| 2630 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2631 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2632 | /* WNM-Sleep Mode Response */ |
| 2633 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2634 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2635 | #ifdef CONFIG_WNM |
| 2636 | /* WNM - Collocated Interference Request */ |
| 2637 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2638 | ret = -1; |
| 2639 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2640 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2641 | #ifdef CONFIG_HS20 |
| 2642 | /* WNM-Notification */ |
| 2643 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2644 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2645 | #endif /* CONFIG_HS20 */ |
| 2646 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2647 | /* WMM-AC ADDTS Response */ |
| 2648 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2649 | ret = -1; |
| 2650 | |
| 2651 | /* WMM-AC DELTS */ |
| 2652 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2653 | ret = -1; |
| 2654 | |
| 2655 | /* Radio Measurement - Neighbor Report Response */ |
| 2656 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2657 | ret = -1; |
| 2658 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2659 | /* Radio Measurement - Radio Measurement Request */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2660 | if (!drv->no_rrm && |
| 2661 | nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2662 | ret = -1; |
| 2663 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2664 | /* Radio Measurement - Link Measurement Request */ |
| 2665 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2666 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2667 | ret = -1; |
| 2668 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2669 | /* Robust AV SCS Response */ |
| 2670 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x01", 2) < 0) |
| 2671 | ret = -1; |
| 2672 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2673 | /* Robust AV MSCS Response */ |
| 2674 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0) |
| 2675 | ret = -1; |
| 2676 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2677 | /* Protected QoS Management Action frame */ |
| 2678 | if (nl80211_register_action_frame(bss, (u8 *) "\x7e\x50\x6f\x9a\x1a", |
| 2679 | 5) < 0) |
| 2680 | ret = -1; |
| 2681 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2682 | nl80211_mgmt_handle_register_eloop(bss); |
| 2683 | |
| 2684 | return ret; |
| 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2689 | { |
| 2690 | int ret = 0; |
| 2691 | |
| 2692 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2693 | return -1; |
| 2694 | |
| 2695 | wpa_printf(MSG_DEBUG, |
| 2696 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2697 | bss->nl_mgmt); |
| 2698 | |
| 2699 | /* Auth frames for mesh SAE */ |
| 2700 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2701 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2702 | (WLAN_FC_STYPE_AUTH << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2703 | NULL, 0, false) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2704 | ret = -1; |
| 2705 | |
| 2706 | /* Mesh peering open */ |
| 2707 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2708 | ret = -1; |
| 2709 | /* Mesh peering confirm */ |
| 2710 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2711 | ret = -1; |
| 2712 | /* Mesh peering close */ |
| 2713 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2714 | ret = -1; |
| 2715 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2716 | nl80211_mgmt_handle_register_eloop(bss); |
| 2717 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2718 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2722 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2723 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2724 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2725 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2726 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2727 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2728 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2729 | NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2730 | if (ret) { |
| 2731 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2732 | "failed: ret=%d (%s)", |
| 2733 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2734 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2735 | return ret; |
| 2736 | } |
| 2737 | |
| 2738 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2739 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2740 | { |
| 2741 | int ret = 0; |
| 2742 | |
| 2743 | /* Public Action frames */ |
| 2744 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2745 | ret = -1; |
| 2746 | /* RRM Measurement Report */ |
| 2747 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2748 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2749 | /* RRM Link Measurement Report */ |
| 2750 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2751 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2752 | /* RRM Neighbor Report Request */ |
| 2753 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2754 | ret = -1; |
| 2755 | /* FT Action frames */ |
| 2756 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2757 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2758 | /* SA Query */ |
| 2759 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2760 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2761 | /* Protected Dual of Public Action */ |
| 2762 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2763 | ret = -1; |
| 2764 | /* WNM */ |
| 2765 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2766 | ret = -1; |
| 2767 | /* WMM */ |
| 2768 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2769 | ret = -1; |
| 2770 | #ifdef CONFIG_FST |
| 2771 | /* FST Action frames */ |
| 2772 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2773 | ret = -1; |
| 2774 | #endif /* CONFIG_FST */ |
| 2775 | /* Vendor-specific */ |
| 2776 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2777 | ret = -1; |
| 2778 | |
| 2779 | return ret; |
| 2780 | } |
| 2781 | |
| 2782 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2783 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2784 | { |
| 2785 | static const int stypes[] = { |
| 2786 | WLAN_FC_STYPE_AUTH, |
| 2787 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2788 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2789 | WLAN_FC_STYPE_DISASSOC, |
| 2790 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2791 | WLAN_FC_STYPE_PROBE_REQ, |
| 2792 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2793 | * it, but it wouldn't really be the right thing anyway as |
| 2794 | * it isn't per interface ... maybe just dump the scan |
| 2795 | * results periodically for OLBC? |
| 2796 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2797 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2798 | }; |
| 2799 | unsigned int i; |
| 2800 | |
| 2801 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2802 | return -1; |
| 2803 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2804 | "handle %p", bss->nl_mgmt); |
| 2805 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2806 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2807 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2808 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2809 | (stypes[i] << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2810 | NULL, 0, false) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2811 | goto out_err; |
| 2812 | } |
| 2813 | } |
| 2814 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2815 | if (nl80211_action_subscribe_ap(bss)) |
| 2816 | goto out_err; |
| 2817 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2818 | if (nl80211_register_spurious_class3(bss)) |
| 2819 | goto out_err; |
| 2820 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2821 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2822 | return 0; |
| 2823 | |
| 2824 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2825 | nl_destroy_handles(&bss->nl_mgmt); |
| 2826 | return -1; |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2831 | { |
| 2832 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2833 | return -1; |
| 2834 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2835 | "handle %p (device SME)", bss->nl_mgmt); |
| 2836 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2837 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2838 | goto out_err; |
| 2839 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2840 | if (bss->drv->device_ap_sme) { |
| 2841 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2842 | |
| 2843 | /* Register for all Authentication frames */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2844 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, |
| 2845 | false) < 0) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2846 | wpa_printf(MSG_DEBUG, |
| 2847 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2848 | } |
| 2849 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2850 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2851 | return 0; |
| 2852 | |
| 2853 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2854 | nl_destroy_handles(&bss->nl_mgmt); |
| 2855 | return -1; |
| 2856 | } |
| 2857 | |
| 2858 | |
| 2859 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2860 | { |
| 2861 | if (bss->nl_mgmt == NULL) |
| 2862 | return; |
| 2863 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2864 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2865 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2866 | |
| 2867 | nl80211_put_wiphy_data_ap(bss); |
| 2868 | } |
| 2869 | |
| 2870 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2871 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2872 | { |
| 2873 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2874 | } |
| 2875 | |
| 2876 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2877 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2878 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2879 | struct nl_msg *msg; |
| 2880 | int ret; |
| 2881 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2882 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2883 | ret = send_and_recv_cmd(bss->drv, msg); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2884 | |
| 2885 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2886 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2887 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | |
| 2891 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2892 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2893 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2894 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2895 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2896 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2897 | NL80211_CMD_STOP_P2P_DEVICE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2898 | ret = send_and_recv_cmd(bss->drv, msg); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2899 | |
| 2900 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2901 | start ? "Start" : "Stop", |
| 2902 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2903 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2904 | return ret; |
| 2905 | } |
| 2906 | |
| 2907 | |
| 2908 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2909 | { |
| 2910 | enum nl80211_iftype nlmode; |
| 2911 | |
| 2912 | nlmode = nl80211_get_ifmode(bss); |
| 2913 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2914 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2915 | bss->ifname, up); |
| 2916 | } |
| 2917 | |
| 2918 | /* P2P Device has start/stop which is equivalent */ |
| 2919 | return nl80211_set_p2pdev(bss, up); |
| 2920 | } |
| 2921 | |
| 2922 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2923 | #ifdef CONFIG_TESTING_OPTIONS |
| 2924 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2925 | { |
| 2926 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2927 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2928 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2929 | |
| 2930 | |
| 2931 | wpa_printf(MSG_DEBUG, |
| 2932 | "nl80211: QCA vendor test command response received"); |
| 2933 | |
| 2934 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2935 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2936 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2937 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2938 | return NL_SKIP; |
| 2939 | } |
| 2940 | |
| 2941 | wpa_hexdump(MSG_DEBUG, |
| 2942 | "nl80211: Received QCA vendor test command response", |
| 2943 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2944 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2945 | |
| 2946 | return NL_SKIP; |
| 2947 | } |
| 2948 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2949 | |
| 2950 | |
| 2951 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2952 | { |
| 2953 | #ifdef CONFIG_TESTING_OPTIONS |
| 2954 | struct nl_msg *msg; |
| 2955 | struct nlattr *params; |
| 2956 | int ret; |
| 2957 | |
| 2958 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2959 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2960 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2961 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2962 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2963 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2964 | nlmsg_free(msg); |
| 2965 | return; |
| 2966 | } |
| 2967 | nla_nest_end(msg, params); |
| 2968 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2969 | ret = send_and_recv_resp(drv, msg, qca_vendor_test_cmd_handler, drv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2970 | wpa_printf(MSG_DEBUG, |
| 2971 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2972 | ret, strerror(-ret)); |
| 2973 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2974 | } |
| 2975 | |
| 2976 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2978 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2979 | const u8 *set_addr, int first, |
| 2980 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2981 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2982 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2983 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2984 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2985 | |
| 2986 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2987 | bss->ifindex = drv->ifindex; |
| 2988 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2989 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2990 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2991 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2992 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2993 | drv->global->if_add_wdevid_set = 0; |
| 2994 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2995 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2996 | bss->static_ap = 1; |
| 2997 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2998 | if (first && |
| 2999 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 3000 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 3001 | drv->start_iface_up = 1; |
| 3002 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3003 | if (wpa_driver_nl80211_capa(drv)) |
| 3004 | return -1; |
| 3005 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3006 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 3007 | return -1; |
| 3008 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3009 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 3010 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3011 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3012 | if (set_addr && |
| 3013 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 3014 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3015 | set_addr))) |
| 3016 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3017 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3018 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_STATION) |
| 3019 | drv->start_mode_sta = 1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3020 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 3021 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3022 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3023 | else if (bss->if_dynamic || |
| 3024 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3025 | nlmode = nl80211_get_ifmode(bss); |
| 3026 | else |
| 3027 | nlmode = NL80211_IFTYPE_STATION; |
| 3028 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3029 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3030 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3031 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3032 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3033 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3034 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3035 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3036 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3037 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 3038 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3039 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 3040 | int ret = i802_set_iface_flags(bss, 1); |
| 3041 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3042 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 3043 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3044 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3045 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3046 | |
| 3047 | if (is_p2p_net_interface(nlmode)) |
| 3048 | nl80211_disable_11b_rates(bss->drv, |
| 3049 | bss->drv->ifindex, 1); |
| 3050 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3051 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3052 | return ret; |
| 3053 | } else { |
| 3054 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 3055 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3056 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 3057 | drv->if_disabled = 1; |
| 3058 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3059 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3062 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3063 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 3064 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3065 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3066 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 3067 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3068 | bss->addr)) |
| 3069 | return -1; |
| 3070 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 3071 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3072 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3073 | if (send_rfkill_event) { |
| 3074 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 3075 | drv, drv->ctx); |
| 3076 | } |
| 3077 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3078 | if (drv->vendor_cmd_test_avail) |
| 3079 | qca_vendor_test(drv); |
| 3080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3081 | return 0; |
| 3082 | } |
| 3083 | |
| 3084 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3085 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3086 | int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3087 | { |
| 3088 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3089 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3090 | struct i802_link *link = nl80211_get_link(bss, link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3091 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3092 | if (!link->beacon_set) |
| 3093 | return 0; |
| 3094 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3095 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3096 | bss->ifindex); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3097 | link->beacon_set = 0; |
| 3098 | link->freq = 0; |
| 3099 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3100 | nl80211_put_wiphy_data_ap(bss); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3101 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_BEACON); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3102 | if (!msg) |
| 3103 | return -ENOBUFS; |
| 3104 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3105 | if (link_id != NL80211_DRV_LINK_ID_NA) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3106 | wpa_printf(MSG_DEBUG, |
| 3107 | "nl80211: MLD: stop beaconing on link=%u", |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3108 | link_id); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3109 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3110 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3111 | nlmsg_free(msg); |
| 3112 | return -ENOBUFS; |
| 3113 | } |
| 3114 | } |
| 3115 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3116 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3120 | static void wpa_driver_nl80211_del_beacon_all(struct i802_bss *bss) |
| 3121 | { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3122 | int link_id; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3123 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3124 | for_each_link_default(bss->valid_links, link_id, NL80211_DRV_LINK_ID_NA) |
| 3125 | wpa_driver_nl80211_del_beacon(bss, link_id); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3129 | /** |
| 3130 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3131 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3132 | * |
| 3133 | * Shut down driver interface and processing of driver events. Free |
| 3134 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 3135 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3136 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3137 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3138 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3139 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3140 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3141 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 3142 | bss->ifname, drv->disabled_11b_rates); |
| 3143 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3144 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3145 | if (drv->data_tx_status) |
| 3146 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 3147 | if (drv->eapol_tx_sock >= 0) |
| 3148 | close(drv->eapol_tx_sock); |
| 3149 | |
| 3150 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3151 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3152 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3153 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 3154 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3155 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3156 | "interface %s from bridge %s: %s", |
| 3157 | bss->ifname, bss->brname, strerror(errno)); |
| 3158 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3159 | |
| 3160 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3161 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3162 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3163 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3164 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 3165 | 0) < 0) |
| 3166 | wpa_printf(MSG_INFO, |
| 3167 | "nl80211: Could not set bridge %s down", |
| 3168 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3169 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3170 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3171 | "bridge %s: %s", |
| 3172 | bss->brname, strerror(errno)); |
| 3173 | } |
| 3174 | |
| 3175 | nl80211_remove_monitor_interface(drv); |
| 3176 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3177 | if (is_ap_interface(drv->nlmode)) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3178 | wpa_driver_nl80211_del_beacon_all(bss); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3179 | nl80211_remove_links(bss); |
| 3180 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3181 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3182 | if (drv->eapol_sock >= 0) { |
| 3183 | eloop_unregister_read_sock(drv->eapol_sock); |
| 3184 | close(drv->eapol_sock); |
| 3185 | } |
| 3186 | |
| 3187 | if (drv->if_indices != drv->default_if_indices) |
| 3188 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3190 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3191 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3192 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3193 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 3194 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3195 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3196 | rfkill_deinit(drv->rfkill); |
| 3197 | |
| 3198 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3199 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3200 | if (!drv->start_iface_up) |
| 3201 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3202 | |
| 3203 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3204 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 3205 | 0) < 0) { |
| 3206 | wpa_printf(MSG_DEBUG, |
| 3207 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 3208 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3209 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3210 | drv->perm_addr) < 0) { |
| 3211 | wpa_printf(MSG_DEBUG, |
| 3212 | "nl80211: Could not restore permanent MAC address"); |
| 3213 | } |
| 3214 | } |
| 3215 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3216 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3217 | if (drv->start_mode_sta) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3218 | wpa_driver_nl80211_set_mode(bss, |
| 3219 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3220 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3221 | } else { |
| 3222 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 3223 | nl80211_del_p2pdev(bss); |
| 3224 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3225 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3226 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3227 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3228 | os_free(drv->filter_ssids); |
| 3229 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3230 | os_free(drv->auth_ie); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3231 | os_free(drv->auth_data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3232 | |
| 3233 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3234 | dl_list_del(&drv->list); |
| 3235 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3236 | os_free(drv->extended_capa); |
| 3237 | os_free(drv->extended_capa_mask); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3238 | for (i = 0; i < drv->num_iface_capa; i++) { |
| 3239 | os_free(drv->iface_capa[i].ext_capa); |
| 3240 | os_free(drv->iface_capa[i].ext_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3241 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3242 | os_free(drv->first_bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3243 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 3244 | os_free(drv->pending_roam_data); |
| 3245 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3246 | os_free(drv); |
| 3247 | } |
| 3248 | |
| 3249 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3250 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 3251 | { |
| 3252 | switch (alg) { |
| 3253 | case WPA_ALG_WEP: |
| 3254 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3255 | return RSN_CIPHER_SUITE_WEP40; |
| 3256 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3257 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3258 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3259 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3260 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3261 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3262 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3263 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3264 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3265 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3266 | return RSN_CIPHER_SUITE_GCMP_256; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3267 | case WPA_ALG_BIP_CMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3268 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3269 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3270 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3271 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3272 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3273 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3274 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3275 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3276 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3277 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3278 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3279 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3280 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 3281 | alg); |
| 3282 | return 0; |
| 3283 | } |
| 3284 | |
| 3285 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 3286 | alg); |
| 3287 | return 0; |
| 3288 | } |
| 3289 | |
| 3290 | |
| 3291 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 3292 | { |
| 3293 | switch (cipher) { |
| 3294 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3295 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3296 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3297 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3298 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3299 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3300 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3301 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3302 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3303 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3304 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3305 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3306 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3307 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3308 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3309 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3310 | default: |
| 3311 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3312 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | |
| 3316 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 3317 | int max_suites) |
| 3318 | { |
| 3319 | int num_suites = 0; |
| 3320 | |
| 3321 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3322 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3323 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3324 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3325 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3326 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3327 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3328 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3329 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3330 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3331 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3332 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3333 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3334 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3335 | |
| 3336 | return num_suites; |
| 3337 | } |
| 3338 | |
| 3339 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3340 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3341 | int max_suites) |
| 3342 | { |
| 3343 | int num_suites = 0; |
| 3344 | |
| 3345 | #define __AKM(a, b) \ |
| 3346 | if (num_suites < max_suites && \ |
| 3347 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3348 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3349 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 3350 | __AKM(PSK, PSK_OVER_802_1X); |
| 3351 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 3352 | __AKM(FT_PSK, FT_PSK); |
| 3353 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 3354 | __AKM(PSK_SHA256, PSK_SHA256); |
| 3355 | __AKM(SAE, SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3356 | __AKM(SAE_EXT_KEY, SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3357 | __AKM(FT_SAE, FT_SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3358 | __AKM(FT_SAE_EXT_KEY, FT_SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3359 | __AKM(CCKM, CCKM); |
| 3360 | __AKM(OSEN, OSEN); |
| 3361 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 3362 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 3363 | __AKM(FILS_SHA256, FILS_SHA256); |
| 3364 | __AKM(FILS_SHA384, FILS_SHA384); |
| 3365 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 3366 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 3367 | __AKM(OWE, OWE); |
| 3368 | __AKM(DPP, DPP); |
| 3369 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3370 | __AKM(IEEE8021X_SHA384, 802_1X_SHA384); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3371 | #undef __AKM |
| 3372 | |
| 3373 | return num_suites; |
| 3374 | } |
| 3375 | |
| 3376 | |
Isaac Chiou | 6ce580d | 2024-04-24 17:07:24 +0800 | [diff] [blame] | 3377 | #if (defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(WIFI_BRCM_OPEN_SOURCE_MULTI_AKM)) || \ |
| 3378 | defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3379 | static int wpa_cross_akm_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3380 | int max_suites) |
| 3381 | { |
| 3382 | int num_suites = 0; |
| 3383 | |
| 3384 | #define __AKM_TO_SUITES_ARRAY(a, b) \ |
| 3385 | if (num_suites < max_suites && \ |
| 3386 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3387 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3388 | __AKM_TO_SUITES_ARRAY(PSK, PSK_OVER_802_1X); |
| 3389 | __AKM_TO_SUITES_ARRAY(SAE, SAE); |
| 3390 | #undef __AKM_TO_SUITES_ARRAY |
| 3391 | |
| 3392 | return num_suites; |
| 3393 | } |
Isaac Chiou | 6ce580d | 2024-04-24 17:07:24 +0800 | [diff] [blame] | 3394 | #endif /* (CONFIG_DRIVER_NL80211_BRCM && !WIFI_BRCM_OPEN_SOURCE_MULTI_AKM) || |
| 3395 | * CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3396 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3397 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3398 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3399 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3400 | const u8 *key, size_t key_len) |
| 3401 | { |
| 3402 | struct nl_msg *msg; |
| 3403 | int ret; |
| 3404 | |
| 3405 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 3406 | return 0; |
| 3407 | |
| 3408 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3409 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3410 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3411 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 3412 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 3413 | nl80211_nlmsg_clear(msg); |
| 3414 | nlmsg_free(msg); |
| 3415 | return -1; |
| 3416 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3417 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3418 | if (ret) { |
| 3419 | wpa_printf(MSG_DEBUG, |
| 3420 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3421 | ret, strerror(-ret)); |
| 3422 | } |
| 3423 | |
| 3424 | return ret; |
| 3425 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3426 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3427 | |
| 3428 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3429 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3430 | static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3431 | const u8 *key, size_t key_len) |
| 3432 | { |
| 3433 | struct nl_msg *msg; |
| 3434 | int ret; |
| 3435 | struct nlattr *params; |
| 3436 | |
| 3437 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3438 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3439 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3440 | BRCM_VENDOR_SCMD_SET_PMK) || |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3441 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3442 | nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) { |
| 3443 | nl80211_nlmsg_clear(msg); |
| 3444 | nlmsg_free(msg); |
| 3445 | return -ENOBUFS; |
| 3446 | } |
| 3447 | nla_nest_end(msg, params); |
| 3448 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3449 | ret = send_and_recv_cmd(drv, msg); |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3450 | if (ret) { |
| 3451 | wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)", |
| 3452 | ret, strerror(-ret)); |
| 3453 | } |
| 3454 | |
| 3455 | return ret; |
| 3456 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3457 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3458 | |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3459 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3460 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3461 | const u8 *key, size_t key_len, |
| 3462 | const u8 *addr) |
| 3463 | { |
| 3464 | struct nl_msg *msg = NULL; |
| 3465 | int ret; |
| 3466 | |
| 3467 | /* |
| 3468 | * If the authenticator address is not set, assume it is |
| 3469 | * the current BSSID. |
| 3470 | */ |
| 3471 | if (!addr && drv->associated) |
| 3472 | addr = drv->bssid; |
| 3473 | else if (!addr) |
| 3474 | return -1; |
| 3475 | |
| 3476 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3477 | MAC2STR(addr)); |
| 3478 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3479 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3480 | if (!msg || |
| 3481 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3482 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3483 | nl80211_nlmsg_clear(msg); |
| 3484 | nlmsg_free(msg); |
| 3485 | return -ENOBUFS; |
| 3486 | } |
| 3487 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3488 | ret = send_and_recv_cmd(drv, msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3489 | if (ret) { |
| 3490 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3491 | ret, strerror(-ret)); |
| 3492 | } |
| 3493 | |
| 3494 | return ret; |
| 3495 | } |
| 3496 | |
| 3497 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3498 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3499 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3500 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3501 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3502 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3503 | struct nl_msg *msg; |
| 3504 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3505 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3506 | int skip_set_key = 1; |
| 3507 | const char *ifname = params->ifname; |
| 3508 | enum wpa_alg alg = params->alg; |
| 3509 | const u8 *addr = params->addr; |
| 3510 | int key_idx = params->key_idx; |
| 3511 | int set_tx = params->set_tx; |
| 3512 | const u8 *seq = params->seq; |
| 3513 | size_t seq_len = params->seq_len; |
| 3514 | const u8 *key = params->key; |
| 3515 | size_t key_len = params->key_len; |
| 3516 | int vlan_id = params->vlan_id; |
| 3517 | enum key_flag key_flag = params->key_flag; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3518 | int link_id = params->link_id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3519 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3520 | /* Ignore for P2P Device */ |
| 3521 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3522 | return 0; |
| 3523 | |
| 3524 | ifindex = if_nametoindex(ifname); |
| 3525 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3526 | "set_tx=%d seq_len=%lu key_len=%lu key_flag=0x%x link_id=%d", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3527 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3528 | (unsigned long) seq_len, (unsigned long) key_len, key_flag, |
| 3529 | link_id); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3530 | |
| 3531 | if (check_key_flag(key_flag)) { |
| 3532 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3533 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3534 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3535 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3536 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3537 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3538 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3539 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3540 | __func__); |
| 3541 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3542 | return ret; |
| 3543 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3544 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3545 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3546 | if (key_flag & KEY_FLAG_PMK) { |
| 3547 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3548 | return nl80211_set_pmk(drv, key, key_len, addr); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3549 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3550 | if (drv->vendor_set_pmk) { |
Jay Patel | 731adae | 2021-02-17 14:55:58 -0800 | [diff] [blame] | 3551 | wpa_printf(MSG_INFO, "nl80211: key_mgmt_set_key with key_len %lu", (unsigned long) key_len); |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3552 | return key_mgmt_set_key(drv, key, key_len); |
| 3553 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3554 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3555 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3556 | /* The driver does not have any offload mechanism for PMK, so |
| 3557 | * there is no need to configure this key. */ |
| 3558 | return 0; |
| 3559 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3560 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3561 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3562 | key_msg = nlmsg_alloc(); |
| 3563 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3564 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3565 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3566 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3567 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3568 | wpa_printf(MSG_DEBUG, |
| 3569 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3570 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3571 | if (!msg) |
| 3572 | goto fail2; |
| 3573 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3574 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3575 | __func__); |
| 3576 | ret = -EINVAL; |
| 3577 | goto fail2; |
| 3578 | } else if (alg == WPA_ALG_NONE) { |
| 3579 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3580 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3581 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3582 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3583 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3584 | u32 suite; |
| 3585 | |
| 3586 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3587 | if (!suite) { |
| 3588 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3589 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3590 | } |
| 3591 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3592 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3593 | if (!msg) |
| 3594 | goto fail2; |
| 3595 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3596 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3597 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3598 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3599 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3600 | if (seq && seq_len) { |
| 3601 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3602 | goto fail; |
| 3603 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3604 | seq, seq_len); |
| 3605 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3606 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3607 | |
| 3608 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3609 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3610 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3611 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3612 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3613 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3614 | KEY_FLAG_PAIRWISE_RX || |
| 3615 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3616 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3617 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3618 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3619 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3620 | goto fail; |
| 3621 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3622 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3623 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3624 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3625 | NL80211_KEYTYPE_GROUP)) |
| 3626 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3627 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3628 | wpa_printf(MSG_DEBUG, |
| 3629 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3630 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3631 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3632 | } else if (alg == WPA_ALG_WEP && |
| 3633 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3634 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3635 | skip_set_key = 0; |
| 3636 | } else { |
| 3637 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3638 | } |
| 3639 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3640 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3641 | wpa_printf(MSG_DEBUG, |
| 3642 | " invalid key_flag for a broadcast key"); |
| 3643 | ret = -EINVAL; |
| 3644 | goto fail; |
| 3645 | } else { |
| 3646 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3647 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3648 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3649 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3650 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3651 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3652 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3653 | nl80211_nlmsg_clear(key_msg); |
| 3654 | nlmsg_free(key_msg); |
| 3655 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3656 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3657 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3658 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3659 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3660 | goto fail; |
| 3661 | } |
| 3662 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3663 | if (link_id != -1) { |
| 3664 | wpa_printf(MSG_DEBUG, "nl80211: Link ID %d", link_id); |
| 3665 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 3666 | goto fail; |
| 3667 | } |
| 3668 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3669 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3670 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3671 | ret = 0; |
| 3672 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3673 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3674 | ret, strerror(-ret)); |
| 3675 | |
| 3676 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3677 | * If we failed or don't need to set the key as default (below), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3678 | * we're done here. |
| 3679 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3680 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3681 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3682 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3683 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3684 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3685 | key_msg = nlmsg_alloc(); |
| 3686 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3687 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3688 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3689 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3690 | if (!msg) |
| 3691 | goto fail2; |
| 3692 | if (!key_msg || |
| 3693 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3694 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3695 | (key_idx == 6 || key_idx == 7 ? |
| 3696 | NL80211_KEY_DEFAULT_BEACON : |
| 3697 | NL80211_KEY_DEFAULT_MGMT) : |
| 3698 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3699 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3700 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3701 | struct nlattr *types; |
| 3702 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3703 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3704 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3705 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3706 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3707 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3708 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3709 | struct nlattr *types; |
| 3710 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3711 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3712 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3713 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3714 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3715 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3718 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3719 | goto fail; |
| 3720 | nl80211_nlmsg_clear(key_msg); |
| 3721 | nlmsg_free(key_msg); |
| 3722 | key_msg = NULL; |
| 3723 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3724 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3725 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3726 | vlan_id); |
| 3727 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3728 | goto fail; |
| 3729 | } |
| 3730 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3731 | if (link_id != -1) { |
| 3732 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - Link ID %d", |
| 3733 | link_id); |
| 3734 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 3735 | goto fail; |
| 3736 | } |
| 3737 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3738 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3739 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3740 | wpa_printf(MSG_DEBUG, |
| 3741 | "nl80211: set_key default failed; err=%d %s", |
| 3742 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3743 | return ret; |
| 3744 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3745 | fail: |
| 3746 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3747 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3748 | fail2: |
| 3749 | nl80211_nlmsg_clear(key_msg); |
| 3750 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3751 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | |
| 3755 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3756 | int key_idx, int defkey, |
| 3757 | const u8 *seq, size_t seq_len, |
| 3758 | const u8 *key, size_t key_len) |
| 3759 | { |
| 3760 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3761 | u32 suite; |
| 3762 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3763 | if (!key_attr) |
| 3764 | return -1; |
| 3765 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3766 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3767 | if (!suite) |
| 3768 | return -1; |
| 3769 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3770 | if (defkey && wpa_alg_bip(alg)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3771 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3772 | return -1; |
| 3773 | } else if (defkey) { |
| 3774 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3775 | return -1; |
| 3776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3777 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3778 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3779 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3780 | (seq && seq_len && |
| 3781 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3782 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3783 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3784 | |
| 3785 | nla_nest_end(msg, key_attr); |
| 3786 | |
| 3787 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | |
| 3791 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3792 | struct nl_msg *msg) |
| 3793 | { |
| 3794 | int i, privacy = 0; |
| 3795 | struct nlattr *nl_keys, *nl_key; |
| 3796 | |
| 3797 | for (i = 0; i < 4; i++) { |
| 3798 | if (!params->wep_key[i]) |
| 3799 | continue; |
| 3800 | privacy = 1; |
| 3801 | break; |
| 3802 | } |
| 3803 | if (params->wps == WPS_MODE_PRIVACY) |
| 3804 | privacy = 1; |
| 3805 | if (params->pairwise_suite && |
| 3806 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3807 | privacy = 1; |
| 3808 | |
| 3809 | if (!privacy) |
| 3810 | return 0; |
| 3811 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3812 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3813 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3814 | |
| 3815 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3816 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3817 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3818 | |
| 3819 | for (i = 0; i < 4; i++) { |
| 3820 | if (!params->wep_key[i]) |
| 3821 | continue; |
| 3822 | |
| 3823 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3824 | if (!nl_key || |
| 3825 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3826 | params->wep_key[i]) || |
| 3827 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3828 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3829 | RSN_CIPHER_SUITE_WEP40 : |
| 3830 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3831 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3832 | (i == params->wep_tx_keyidx && |
| 3833 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3834 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | |
| 3836 | nla_nest_end(msg, nl_key); |
| 3837 | } |
| 3838 | nla_nest_end(msg, nl_keys); |
| 3839 | |
| 3840 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3844 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3845 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3846 | int local_state_change, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3847 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3848 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3849 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3850 | struct nl_msg *msg; |
| 3851 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3852 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3853 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3854 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3855 | (local_state_change && |
| 3856 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3857 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3858 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3859 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3860 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3861 | ret = send_and_recv(drv->global, bss->nl_connect, msg, |
| 3862 | NULL, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3863 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3864 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3865 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3866 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3867 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3868 | return ret; |
| 3869 | } |
| 3870 | |
| 3871 | |
| 3872 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3873 | u16 reason_code, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3874 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3875 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3876 | int ret; |
| 3877 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3878 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3879 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3880 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3881 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3882 | reason_code, 0, bss); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3883 | /* |
| 3884 | * For locally generated disconnect, supplicant already generates a |
| 3885 | * DEAUTH event, so ignore the event from NL80211. |
| 3886 | */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3887 | if (ret == 0) |
| 3888 | drv->ignore_next_local_disconnect = send_event_marker(drv); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3889 | |
| 3890 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3894 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3895 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3896 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3897 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3898 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3899 | |
| 3900 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3901 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3902 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3903 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3904 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3905 | return wpa_driver_nl80211_disconnect(drv, reason_code, bss); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3906 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3907 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3908 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3909 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3910 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3911 | reason_code, 0, bss); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3912 | /* |
| 3913 | * For locally generated deauthenticate, supplicant already generates a |
| 3914 | * DEAUTH event, so ignore the event from NL80211. |
| 3915 | */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3916 | if (ret == 0) |
| 3917 | drv->ignore_next_local_deauth = send_event_marker(drv); |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3918 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3919 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3923 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3924 | struct wpa_driver_auth_params *params) |
| 3925 | { |
| 3926 | int i; |
| 3927 | |
| 3928 | drv->auth_freq = params->freq; |
| 3929 | drv->auth_alg = params->auth_alg; |
| 3930 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3931 | drv->auth_local_state_change = params->local_state_change; |
| 3932 | drv->auth_p2p = params->p2p; |
| 3933 | |
| 3934 | if (params->bssid) |
| 3935 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3936 | else |
| 3937 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3938 | |
| 3939 | if (params->ssid) { |
| 3940 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3941 | drv->auth_ssid_len = params->ssid_len; |
| 3942 | } else |
| 3943 | drv->auth_ssid_len = 0; |
| 3944 | |
| 3945 | |
| 3946 | os_free(drv->auth_ie); |
| 3947 | drv->auth_ie = NULL; |
| 3948 | drv->auth_ie_len = 0; |
| 3949 | if (params->ie) { |
| 3950 | drv->auth_ie = os_malloc(params->ie_len); |
| 3951 | if (drv->auth_ie) { |
| 3952 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3953 | drv->auth_ie_len = params->ie_len; |
| 3954 | } |
| 3955 | } |
| 3956 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3957 | if (params->mld && params->ap_mld_addr) { |
| 3958 | drv->auth_mld = params->mld; |
| 3959 | drv->auth_mld_link_id = params->mld_link_id; |
| 3960 | os_memcpy(drv->auth_ap_mld_addr, params->ap_mld_addr, ETH_ALEN); |
| 3961 | } else { |
| 3962 | drv->auth_mld = false; |
| 3963 | drv->auth_mld_link_id = -1; |
| 3964 | } |
| 3965 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3966 | os_free(drv->auth_data); |
| 3967 | drv->auth_data = NULL; |
| 3968 | drv->auth_data_len = 0; |
| 3969 | if (params->auth_data) { |
| 3970 | drv->auth_data = os_memdup(params->auth_data, |
| 3971 | params->auth_data_len); |
| 3972 | if (drv->auth_data) |
| 3973 | drv->auth_data_len = params->auth_data_len; |
| 3974 | } |
| 3975 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3976 | for (i = 0; i < 4; i++) { |
| 3977 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3978 | params->wep_key_len[i] <= 16) { |
| 3979 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3980 | params->wep_key_len[i]); |
| 3981 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3982 | } else |
| 3983 | drv->auth_wep_key_len[i] = 0; |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3988 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3989 | { |
| 3990 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3991 | |
| 3992 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3993 | return; |
| 3994 | |
| 3995 | /* |
| 3996 | * Looks like we failed to unmask 11b rates previously. This could |
| 3997 | * happen, e.g., if the interface was down at the point in time when a |
| 3998 | * P2P group was terminated. |
| 3999 | */ |
| 4000 | wpa_printf(MSG_DEBUG, |
| 4001 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 4002 | bss->ifname); |
| 4003 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 4004 | } |
| 4005 | |
| 4006 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4007 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 4008 | { |
| 4009 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 4010 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4011 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 4012 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 4013 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 4014 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 4015 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 4016 | return NL80211_AUTHTYPE_FT; |
| 4017 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 4018 | return NL80211_AUTHTYPE_SAE; |
| 4019 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 4020 | return NL80211_AUTHTYPE_FILS_SK; |
| 4021 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 4022 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 4023 | |
| 4024 | return NL80211_AUTHTYPE_MAX; |
| 4025 | } |
| 4026 | |
| 4027 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4028 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4029 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4030 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4031 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4032 | int ret = -1, i; |
| 4033 | struct nl_msg *msg; |
| 4034 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4035 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4036 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4037 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4038 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4039 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4040 | nl80211_unmask_11b_rates(bss); |
| 4041 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4042 | is_retry = drv->retry_auth; |
| 4043 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4044 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4045 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4046 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4047 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4048 | if (params->bssid) |
| 4049 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4050 | else |
| 4051 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4052 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4053 | nlmode = params->p2p ? |
| 4054 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4055 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4056 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4057 | return -1; |
| 4058 | |
| 4059 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4060 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 4061 | drv->ifindex); |
| 4062 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4063 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 4064 | if (!msg) |
| 4065 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4067 | os_memset(&p, 0, sizeof(p)); |
| 4068 | p.ifname = bss->ifname; |
| 4069 | p.alg = WPA_ALG_WEP; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4070 | p.link_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4071 | for (i = 0; i < 4; i++) { |
| 4072 | if (!params->wep_key[i]) |
| 4073 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4074 | p.key_idx = i; |
| 4075 | p.set_tx = i == params->wep_tx_keyidx; |
| 4076 | p.key = params->wep_key[i]; |
| 4077 | p.key_len = params->wep_key_len[i]; |
| 4078 | p.key_flag = i == params->wep_tx_keyidx ? |
| 4079 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 4080 | KEY_FLAG_GROUP_RX_TX; |
| 4081 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4082 | if (params->wep_tx_keyidx != i) |
| 4083 | continue; |
| 4084 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4085 | params->wep_key[i], params->wep_key_len[i])) |
| 4086 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4089 | if (params->bssid) { |
| 4090 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4091 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4092 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4093 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4094 | } |
| 4095 | if (params->freq) { |
| 4096 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 4098 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4099 | } |
| 4100 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4101 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 4102 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4103 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4104 | params->ssid)) |
| 4105 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4106 | } |
| 4107 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4108 | if (params->ie && |
| 4109 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 4110 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4111 | if (params->auth_data) { |
| 4112 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 4113 | params->auth_data_len); |
| 4114 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 4115 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4116 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4117 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4118 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4119 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4120 | if (type == NL80211_AUTHTYPE_MAX || |
| 4121 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4122 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | if (params->local_state_change) { |
| 4124 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4125 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 4126 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4129 | if (params->mld && params->ap_mld_addr) { |
| 4130 | wpa_printf(MSG_DEBUG, " * MLD: link_id=%u, MLD addr=" MACSTR, |
| 4131 | params->mld_link_id, MAC2STR(params->ap_mld_addr)); |
| 4132 | |
| 4133 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 4134 | params->mld_link_id) || |
| 4135 | nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, |
| 4136 | params->ap_mld_addr)) |
| 4137 | goto fail; |
| 4138 | } |
| 4139 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4140 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4141 | msg = NULL; |
| 4142 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4143 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4144 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 4145 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4146 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4147 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 4148 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4149 | /* |
| 4150 | * mac80211 does not currently accept new |
| 4151 | * authentication if we are already authenticated. As a |
| 4152 | * workaround, force deauthentication and try again. |
| 4153 | */ |
| 4154 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 4155 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4156 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4157 | wpa_driver_nl80211_deauthenticate( |
| 4158 | bss, params->bssid, |
| 4159 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 4160 | nlmsg_free(msg); |
| 4161 | goto retry; |
| 4162 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4163 | |
| 4164 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 4165 | /* |
| 4166 | * cfg80211 has likely expired the BSS entry even |
| 4167 | * though it was previously available in our internal |
| 4168 | * BSS table. To recover quickly, start a single |
| 4169 | * channel scan on the specified channel. |
| 4170 | */ |
| 4171 | struct wpa_driver_scan_params scan; |
| 4172 | int freqs[2]; |
| 4173 | |
| 4174 | os_memset(&scan, 0, sizeof(scan)); |
| 4175 | scan.num_ssids = 1; |
| 4176 | if (params->ssid) { |
| 4177 | scan.ssids[0].ssid = params->ssid; |
| 4178 | scan.ssids[0].ssid_len = params->ssid_len; |
| 4179 | } |
| 4180 | freqs[0] = params->freq; |
| 4181 | freqs[1] = 0; |
| 4182 | scan.freqs = freqs; |
| 4183 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 4184 | "channel scan to refresh cfg80211 BSS " |
| 4185 | "entry"); |
| 4186 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 4187 | if (ret == 0) { |
| 4188 | nl80211_copy_auth_params(drv, params); |
| 4189 | drv->scan_for_auth = 1; |
| 4190 | } |
| 4191 | } else if (is_retry) { |
| 4192 | /* |
| 4193 | * Need to indicate this with an event since the return |
| 4194 | * value from the retry is not delivered to core code. |
| 4195 | */ |
| 4196 | union wpa_event_data event; |
| 4197 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 4198 | "failed"); |
| 4199 | os_memset(&event, 0, sizeof(event)); |
| 4200 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 4201 | ETH_ALEN); |
| 4202 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 4203 | &event); |
| 4204 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4205 | } else { |
| 4206 | wpa_printf(MSG_DEBUG, |
| 4207 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4208 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4209 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4210 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4211 | nlmsg_free(msg); |
| 4212 | return ret; |
| 4213 | } |
| 4214 | |
| 4215 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4216 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4217 | { |
| 4218 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4219 | struct i802_bss *bss = drv->first_bss; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4220 | u8 ap_mld_addr[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4221 | int i; |
| 4222 | |
| 4223 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 4224 | |
| 4225 | os_memset(¶ms, 0, sizeof(params)); |
| 4226 | params.freq = drv->auth_freq; |
| 4227 | params.auth_alg = drv->auth_alg; |
| 4228 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 4229 | params.local_state_change = drv->auth_local_state_change; |
| 4230 | params.p2p = drv->auth_p2p; |
| 4231 | |
| 4232 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 4233 | params.bssid = drv->auth_bssid_; |
| 4234 | |
| 4235 | if (drv->auth_ssid_len) { |
| 4236 | params.ssid = drv->auth_ssid; |
| 4237 | params.ssid_len = drv->auth_ssid_len; |
| 4238 | } |
| 4239 | |
| 4240 | params.ie = drv->auth_ie; |
| 4241 | params.ie_len = drv->auth_ie_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4242 | params.auth_data = drv->auth_data; |
| 4243 | params.auth_data_len = drv->auth_data_len; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4244 | params.mld = drv->auth_mld; |
| 4245 | params.mld_link_id = drv->auth_mld_link_id; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4246 | if (drv->auth_mld) { |
| 4247 | os_memcpy(ap_mld_addr, drv->auth_ap_mld_addr, ETH_ALEN); |
| 4248 | params.ap_mld_addr = ap_mld_addr; |
| 4249 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4250 | |
| 4251 | for (i = 0; i < 4; i++) { |
| 4252 | if (drv->auth_wep_key_len[i]) { |
| 4253 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 4254 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | drv->retry_auth = 1; |
| 4259 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 4260 | } |
| 4261 | |
| 4262 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4263 | struct i802_link * nl80211_get_link(struct i802_bss *bss, s8 link_id) |
| 4264 | { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4265 | if (link_id < 0 || link_id >= MAX_NUM_MLD_LINKS) |
| 4266 | return bss->flink; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4267 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4268 | if (BIT(link_id) & bss->valid_links) |
| 4269 | return &bss->links[link_id]; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4270 | |
| 4271 | return bss->flink; |
| 4272 | } |
| 4273 | |
| 4274 | |
| 4275 | static void nl80211_link_set_freq(struct i802_bss *bss, s8 link_id, int freq) |
| 4276 | { |
| 4277 | struct i802_link *link = nl80211_get_link(bss, link_id); |
| 4278 | |
| 4279 | link->freq = freq; |
| 4280 | } |
| 4281 | |
| 4282 | |
| 4283 | static int nl80211_get_link_freq(struct i802_bss *bss, const u8 *addr, |
| 4284 | bool bss_freq_debug) |
| 4285 | { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4286 | u8 i; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4287 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4288 | for_each_link(bss->valid_links, i) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4289 | if (ether_addr_equal(bss->links[i].addr, addr)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4290 | wpa_printf(MSG_DEBUG, |
| 4291 | "nl80211: Use link freq=%d for address " |
| 4292 | MACSTR, |
| 4293 | bss->links[i].freq, MAC2STR(addr)); |
| 4294 | return bss->links[i].freq; |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | if (bss_freq_debug) |
| 4299 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 4300 | bss->flink->freq); |
| 4301 | |
| 4302 | return bss->flink->freq; |
| 4303 | } |
| 4304 | |
| 4305 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4306 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 4307 | size_t data_len, int noack, |
| 4308 | unsigned int freq, int no_cck, |
| 4309 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4310 | unsigned int wait_time, |
| 4311 | const u16 *csa_offs, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4312 | size_t csa_offs_len, int no_encrypt, |
| 4313 | int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4314 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4315 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4316 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4317 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4318 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4319 | int use_cookie = 1; |
| 4320 | int res; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4321 | struct i802_link *link = nl80211_get_link(bss, link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4322 | |
| 4323 | mgmt = (struct ieee80211_mgmt *) data; |
| 4324 | fc = le_to_host16(mgmt->frame_control); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4325 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR " sa=" MACSTR |
| 4326 | " bssid=" MACSTR |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4327 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d", |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4328 | MAC2STR(mgmt->da), MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid), |
| 4329 | noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4330 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4331 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4332 | if ((is_sta_interface(drv->nlmode) || |
| 4333 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4334 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4335 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 4336 | /* |
| 4337 | * The use of last_mgmt_freq is a bit of a hack, |
| 4338 | * but it works due to the single-threaded nature |
| 4339 | * of wpa_supplicant. |
| 4340 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4341 | if (freq == 0) { |
| 4342 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 4343 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4344 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4345 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4346 | wait_time = 0; |
| 4347 | use_cookie = 0; |
| 4348 | no_cck = 1; |
| 4349 | offchanok = 1; |
| 4350 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4351 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4352 | |
| 4353 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4354 | unsigned int link_freq = nl80211_get_link_freq(bss, mgmt->sa, |
| 4355 | !freq); |
| 4356 | |
| 4357 | if (!freq) |
| 4358 | freq = link_freq; |
| 4359 | |
| 4360 | if (freq == link_freq) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4361 | wait_time = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4362 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4363 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 4364 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 4365 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4366 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4367 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4368 | /* |
| 4369 | * Only one of the authentication frame types is encrypted. |
| 4370 | * In order for static WEP encryption to work properly (i.e., |
| 4371 | * to not encrypt the frame), we need to tell mac80211 about |
| 4372 | * the frames that must not be encrypted. |
| 4373 | */ |
| 4374 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4375 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4376 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 4377 | encrypt = 0; |
| 4378 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4379 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4380 | if (is_sta_interface(drv->nlmode) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4381 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4382 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4383 | if (freq == 0 && |
| 4384 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 4385 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 4386 | freq = nl80211_get_assoc_freq(drv); |
| 4387 | wpa_printf(MSG_DEBUG, |
| 4388 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 4389 | freq); |
| 4390 | } |
| 4391 | |
| 4392 | /* Allow off channel for PASN authentication */ |
| 4393 | if (data_len >= IEEE80211_HDRLEN + 2 && |
| 4394 | WPA_GET_LE16(data + IEEE80211_HDRLEN) == WLAN_AUTH_PASN && |
| 4395 | !offchanok) { |
| 4396 | wpa_printf(MSG_DEBUG, |
| 4397 | "nl80211: send_mlme: allow off channel for PASN"); |
| 4398 | offchanok = 1; |
| 4399 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4402 | #ifdef CONFIG_PASN |
| 4403 | if (is_sta_interface(drv->nlmode) && |
| 4404 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4405 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DEAUTH) { |
| 4406 | wpa_printf(MSG_DEBUG, |
| 4407 | "nl80211: send_mlme: allow Deauthentication frame for PASN"); |
| 4408 | |
| 4409 | use_cookie = 0; |
| 4410 | offchanok = 1; |
| 4411 | goto send_frame_cmd; |
| 4412 | } |
| 4413 | #endif /* CONFIG_PASN */ |
| 4414 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4415 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4416 | freq = nl80211_get_assoc_freq(drv); |
| 4417 | wpa_printf(MSG_DEBUG, |
| 4418 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 4419 | freq); |
| 4420 | } |
| 4421 | if (freq == 0) { |
| 4422 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4423 | link->freq); |
| 4424 | freq = link->freq; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4425 | } |
| 4426 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4427 | if (drv->use_monitor && is_ap_interface(drv->nlmode)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4428 | wpa_printf(MSG_DEBUG, |
| 4429 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4430 | freq, link->freq); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4431 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4432 | noack); |
| 4433 | } |
| 4434 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4435 | if ((noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 4436 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) && |
| 4437 | link_id == NL80211_DRV_LINK_ID_NA) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4438 | use_cookie = 0; |
| 4439 | send_frame_cmd: |
| 4440 | #ifdef CONFIG_TESTING_OPTIONS |
| 4441 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 4442 | wpa_printf(MSG_DEBUG, |
| 4443 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 4444 | if (nl80211_create_monitor_interface(drv) < 0) |
| 4445 | return -1; |
| 4446 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4447 | noack); |
| 4448 | nl80211_remove_monitor_interface(drv); |
| 4449 | return res; |
| 4450 | } |
| 4451 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4452 | |
| 4453 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 4454 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 4455 | use_cookie, no_cck, noack, offchanok, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4456 | csa_offs, csa_offs_len, link_id); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4457 | if (!res) |
| 4458 | drv->send_frame_link_id = link_id; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4459 | |
| 4460 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4464 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 4465 | { |
| 4466 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 4467 | u8 rates_len = 0; |
| 4468 | int i; |
| 4469 | |
| 4470 | if (!basic_rates) |
| 4471 | return 0; |
| 4472 | |
| 4473 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 4474 | rates[rates_len++] = basic_rates[i] / 5; |
| 4475 | |
| 4476 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 4477 | } |
| 4478 | |
| 4479 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4480 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 4481 | int slot, int ht_opmode, int ap_isolate, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4482 | const int *basic_rates, int link_id) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4483 | { |
| 4484 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4485 | struct nl_msg *msg; |
| 4486 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4487 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 4488 | (cts >= 0 && |
| 4489 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 4490 | (preamble >= 0 && |
| 4491 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 4492 | (slot >= 0 && |
| 4493 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 4494 | (ht_opmode >= 0 && |
| 4495 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 4496 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4497 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4498 | nl80211_put_basic_rates(msg, basic_rates) || |
| 4499 | (link_id != NL80211_DRV_LINK_ID_NA && |
| 4500 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4501 | nlmsg_free(msg); |
| 4502 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4503 | } |
| 4504 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4505 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4509 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 4510 | struct hostapd_acl_params *params) |
| 4511 | { |
| 4512 | struct i802_bss *bss = priv; |
| 4513 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4514 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4515 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4516 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4517 | int ret; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4518 | size_t acl_nla_sz, acl_nlmsg_sz, nla_sz, nlmsg_sz; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4519 | |
| 4520 | if (!(drv->capa.max_acl_mac_addrs)) |
| 4521 | return -ENOTSUP; |
| 4522 | |
| 4523 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 4524 | return -ENOTSUP; |
| 4525 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4526 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 4527 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 4528 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4529 | acl_nla_sz = nla_total_size(ETH_ALEN) * params->num_mac_acl; |
| 4530 | acl_nlmsg_sz = nlmsg_total_size(acl_nla_sz); |
| 4531 | acl = nlmsg_alloc_size(acl_nlmsg_sz); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4532 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4533 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4534 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4535 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 4536 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4537 | return -ENOMEM; |
| 4538 | } |
| 4539 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4540 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4541 | /* |
| 4542 | * genetlink message header (Length of user header is 0) + |
| 4543 | * u32 attr: NL80211_ATTR_IFINDEX + |
| 4544 | * u32 attr: NL80211_ATTR_ACL_POLICY + |
| 4545 | * nested acl attr |
| 4546 | */ |
| 4547 | nla_sz = GENL_HDRLEN + |
| 4548 | nla_total_size(4) * 2 + |
| 4549 | nla_total_size(acl_nla_sz); |
| 4550 | nlmsg_sz = nlmsg_total_size(nla_sz); |
| 4551 | if (!(msg = nl80211_ifindex_msg_build(drv, nlmsg_alloc_size(nlmsg_sz), |
| 4552 | drv->ifindex, 0, |
| 4553 | NL80211_CMD_SET_MAC_ACL)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4554 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 4555 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 4556 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 4557 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 4558 | nlmsg_free(msg); |
| 4559 | nlmsg_free(acl); |
| 4560 | return -ENOMEM; |
| 4561 | } |
| 4562 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4563 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4564 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4565 | if (ret) { |
| 4566 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 4567 | ret, strerror(-ret)); |
| 4568 | } |
| 4569 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4570 | return ret; |
| 4571 | } |
| 4572 | |
| 4573 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4574 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 4575 | { |
| 4576 | if (beacon_int > 0) { |
| 4577 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 4578 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4579 | beacon_int); |
| 4580 | } |
| 4581 | |
| 4582 | return 0; |
| 4583 | } |
| 4584 | |
| 4585 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4586 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 4587 | { |
| 4588 | if (dtim_period > 0) { |
| 4589 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 4590 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 4591 | } |
| 4592 | |
| 4593 | return 0; |
| 4594 | } |
| 4595 | |
| 4596 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4597 | #ifdef CONFIG_MESH |
| 4598 | static int nl80211_set_mesh_config(void *priv, |
| 4599 | struct wpa_driver_mesh_bss_params *params) |
| 4600 | { |
| 4601 | struct i802_bss *bss = priv; |
| 4602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4603 | struct nl_msg *msg; |
| 4604 | int ret; |
| 4605 | |
| 4606 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4607 | if (!msg) |
| 4608 | return -1; |
| 4609 | |
| 4610 | ret = nl80211_put_mesh_config(msg, params); |
| 4611 | if (ret < 0) { |
| 4612 | nlmsg_free(msg); |
| 4613 | return ret; |
| 4614 | } |
| 4615 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4616 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4617 | if (ret) { |
| 4618 | wpa_printf(MSG_ERROR, |
| 4619 | "nl80211: Mesh config set failed: %d (%s)", |
| 4620 | ret, strerror(-ret)); |
| 4621 | return ret; |
| 4622 | } |
| 4623 | return 0; |
| 4624 | } |
| 4625 | #endif /* CONFIG_MESH */ |
| 4626 | |
| 4627 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4628 | static int nl80211_put_beacon_rate(struct nl_msg *msg, u64 flags, u64 flags2, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4629 | struct wpa_driver_ap_params *params) |
| 4630 | { |
| 4631 | struct nlattr *bands, *band; |
| 4632 | struct nl80211_txrate_vht vht_rate; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4633 | struct nl80211_txrate_he he_rate; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4634 | |
| 4635 | if (!params->freq || |
| 4636 | (params->beacon_rate == 0 && |
| 4637 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4638 | return 0; |
| 4639 | |
| 4640 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4641 | if (!bands) |
| 4642 | return -1; |
| 4643 | |
| 4644 | switch (params->freq->mode) { |
| 4645 | case HOSTAPD_MODE_IEEE80211B: |
| 4646 | case HOSTAPD_MODE_IEEE80211G: |
| 4647 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4648 | break; |
| 4649 | case HOSTAPD_MODE_IEEE80211A: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4650 | if (is_6ghz_freq(params->freq->freq)) |
| 4651 | band = nla_nest_start(msg, NL80211_BAND_6GHZ); |
| 4652 | else |
| 4653 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4654 | break; |
| 4655 | case HOSTAPD_MODE_IEEE80211AD: |
| 4656 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4657 | break; |
| 4658 | default: |
| 4659 | return 0; |
| 4660 | } |
| 4661 | |
| 4662 | if (!band) |
| 4663 | return -1; |
| 4664 | |
| 4665 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4666 | os_memset(&he_rate, 0, sizeof(he_rate)); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4667 | |
| 4668 | switch (params->rate_type) { |
| 4669 | case BEACON_RATE_LEGACY: |
| 4670 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4671 | wpa_printf(MSG_INFO, |
| 4672 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4673 | return -1; |
| 4674 | } |
| 4675 | |
| 4676 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4677 | (u8) (params->beacon_rate / 5)) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4678 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4679 | (params->freq->vht_enabled && |
| 4680 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4681 | &vht_rate))) |
| 4682 | return -1; |
| 4683 | |
| 4684 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4685 | params->beacon_rate); |
| 4686 | break; |
| 4687 | case BEACON_RATE_HT: |
| 4688 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4689 | wpa_printf(MSG_INFO, |
| 4690 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4691 | return -1; |
| 4692 | } |
| 4693 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4694 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4695 | (params->freq->vht_enabled && |
| 4696 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4697 | &vht_rate))) |
| 4698 | return -1; |
| 4699 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4700 | params->beacon_rate); |
| 4701 | break; |
| 4702 | case BEACON_RATE_VHT: |
| 4703 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4704 | wpa_printf(MSG_INFO, |
| 4705 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4706 | return -1; |
| 4707 | } |
| 4708 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4709 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4710 | return -1; |
| 4711 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4712 | return -1; |
| 4713 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4714 | &vht_rate)) |
| 4715 | return -1; |
| 4716 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4717 | params->beacon_rate); |
| 4718 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4719 | case BEACON_RATE_HE: |
| 4720 | if (!(flags2 & WPA_DRIVER_FLAGS2_BEACON_RATE_HE)) { |
| 4721 | wpa_printf(MSG_INFO, |
| 4722 | "nl80211: Driver does not support setting Beacon frame rate (HE)"); |
| 4723 | return -1; |
| 4724 | } |
| 4725 | he_rate.mcs[0] = BIT(params->beacon_rate); |
| 4726 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4727 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4728 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4729 | &vht_rate) || |
| 4730 | nla_put(msg, NL80211_TXRATE_HE, sizeof(he_rate), &he_rate)) |
| 4731 | return -1; |
| 4732 | wpa_printf(MSG_DEBUG, " * beacon_rate = HE-MCS %u", |
| 4733 | params->beacon_rate); |
| 4734 | break; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | nla_nest_end(msg, band); |
| 4738 | nla_nest_end(msg, bands); |
| 4739 | |
| 4740 | return 0; |
| 4741 | } |
| 4742 | |
| 4743 | |
| 4744 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4745 | int multicast_to_unicast) |
| 4746 | { |
| 4747 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4748 | struct nl_msg *msg; |
| 4749 | int ret; |
| 4750 | |
| 4751 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4752 | if (!msg || |
| 4753 | (multicast_to_unicast && |
| 4754 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4755 | wpa_printf(MSG_ERROR, |
| 4756 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4757 | bss->ifname); |
| 4758 | nlmsg_free(msg); |
| 4759 | return -ENOBUFS; |
| 4760 | } |
| 4761 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4762 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4763 | |
| 4764 | switch (ret) { |
| 4765 | case 0: |
| 4766 | wpa_printf(MSG_DEBUG, |
| 4767 | "nl80211: multicast to unicast %s on interface %s", |
| 4768 | multicast_to_unicast ? "enabled" : "disabled", |
| 4769 | bss->ifname); |
| 4770 | break; |
| 4771 | case -EOPNOTSUPP: |
| 4772 | if (!multicast_to_unicast) |
| 4773 | break; |
| 4774 | wpa_printf(MSG_INFO, |
| 4775 | "nl80211: multicast to unicast not supported on interface %s", |
| 4776 | bss->ifname); |
| 4777 | break; |
| 4778 | default: |
| 4779 | wpa_printf(MSG_ERROR, |
| 4780 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4781 | multicast_to_unicast ? "enabling" : "disabling", |
| 4782 | ret, strerror(-ret), bss->ifname); |
| 4783 | break; |
| 4784 | } |
| 4785 | |
| 4786 | return ret; |
| 4787 | } |
| 4788 | |
| 4789 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4790 | #ifdef CONFIG_SAE |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4791 | static int nl80211_put_sae_pwe(struct nl_msg *msg, enum sae_pwe pwe) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4792 | { |
| 4793 | u8 sae_pwe; |
| 4794 | |
| 4795 | wpa_printf(MSG_DEBUG, "nl802111: sae_pwe=%d", pwe); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4796 | if (pwe == SAE_PWE_HUNT_AND_PECK) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4797 | sae_pwe = NL80211_SAE_PWE_HUNT_AND_PECK; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4798 | else if (pwe == SAE_PWE_HASH_TO_ELEMENT) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4799 | sae_pwe = NL80211_SAE_PWE_HASH_TO_ELEMENT; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4800 | else if (pwe == SAE_PWE_BOTH) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4801 | sae_pwe = NL80211_SAE_PWE_BOTH; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4802 | else if (pwe == SAE_PWE_FORCE_HUNT_AND_PECK) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4803 | return 0; /* special test mode */ |
| 4804 | else |
| 4805 | return -1; |
| 4806 | if (nla_put_u8(msg, NL80211_ATTR_SAE_PWE, sae_pwe)) |
| 4807 | return -1; |
| 4808 | |
| 4809 | return 0; |
| 4810 | } |
| 4811 | #endif /* CONFIG_SAE */ |
| 4812 | |
| 4813 | |
| 4814 | #ifdef CONFIG_FILS |
| 4815 | static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
| 4816 | struct wpa_driver_ap_params *params) |
| 4817 | { |
| 4818 | struct nlattr *attr; |
| 4819 | |
| 4820 | if (!bss->drv->fils_discovery) { |
| 4821 | wpa_printf(MSG_ERROR, |
| 4822 | "nl80211: Driver does not support FILS Discovery frame transmission for %s", |
| 4823 | bss->ifname); |
| 4824 | return -1; |
| 4825 | } |
| 4826 | |
| 4827 | attr = nla_nest_start(msg, NL80211_ATTR_FILS_DISCOVERY); |
| 4828 | if (!attr || |
| 4829 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 4830 | params->fd_min_int) || |
| 4831 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 4832 | params->fd_max_int) || |
| 4833 | (params->fd_frame_tmpl && |
| 4834 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 4835 | params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 4836 | return -1; |
| 4837 | |
| 4838 | nla_nest_end(msg, attr); |
| 4839 | return 0; |
| 4840 | } |
| 4841 | #endif /* CONFIG_FILS */ |
| 4842 | |
| 4843 | |
| 4844 | #ifdef CONFIG_IEEE80211AX |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4845 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4846 | static int nl80211_unsol_bcast_probe_resp(struct i802_bss *bss, |
| 4847 | struct nl_msg *msg, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 4848 | struct unsol_bcast_probe_resp *ubpr) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4849 | { |
| 4850 | struct nlattr *attr; |
| 4851 | |
| 4852 | if (!bss->drv->unsol_bcast_probe_resp) { |
| 4853 | wpa_printf(MSG_ERROR, |
| 4854 | "nl80211: Driver does not support unsolicited broadcast Probe Response frame transmission for %s", |
| 4855 | bss->ifname); |
| 4856 | return -1; |
| 4857 | } |
| 4858 | |
| 4859 | wpa_printf(MSG_DEBUG, |
| 4860 | "nl80211: Unsolicited broadcast Probe Response frame interval: %u", |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 4861 | ubpr->unsol_bcast_probe_resp_interval); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4862 | attr = nla_nest_start(msg, NL80211_ATTR_UNSOL_BCAST_PROBE_RESP); |
| 4863 | if (!attr || |
| 4864 | nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 4865 | ubpr->unsol_bcast_probe_resp_interval) || |
| 4866 | (ubpr->unsol_bcast_probe_resp_tmpl && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4867 | nla_put(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 4868 | ubpr->unsol_bcast_probe_resp_tmpl_len, |
| 4869 | ubpr->unsol_bcast_probe_resp_tmpl))) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4870 | return -1; |
| 4871 | |
| 4872 | nla_nest_end(msg, attr); |
| 4873 | return 0; |
| 4874 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4875 | |
| 4876 | |
| 4877 | static int nl80211_mbssid(struct nl_msg *msg, |
| 4878 | struct wpa_driver_ap_params *params) |
| 4879 | { |
| 4880 | struct nlattr *config, *elems; |
| 4881 | int ifidx; |
| 4882 | |
| 4883 | if (!params->mbssid_tx_iface) |
| 4884 | return 0; |
| 4885 | |
| 4886 | config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); |
| 4887 | if (!config || |
| 4888 | nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_INDEX, |
| 4889 | params->mbssid_index)) |
| 4890 | return -1; |
| 4891 | |
| 4892 | if (params->mbssid_tx_iface) { |
| 4893 | ifidx = if_nametoindex(params->mbssid_tx_iface); |
| 4894 | if (ifidx <= 0 || |
| 4895 | nla_put_u32(msg, NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX, |
| 4896 | ifidx)) |
| 4897 | return -1; |
| 4898 | } |
| 4899 | |
| 4900 | if (params->ema && nla_put_flag(msg, NL80211_MBSSID_CONFIG_ATTR_EMA)) |
| 4901 | return -1; |
| 4902 | |
| 4903 | nla_nest_end(msg, config); |
| 4904 | |
| 4905 | if (params->mbssid_elem_count && params->mbssid_elem_len && |
| 4906 | params->mbssid_elem_offset && *params->mbssid_elem_offset) { |
| 4907 | u8 i, **offs = params->mbssid_elem_offset; |
| 4908 | |
| 4909 | elems = nla_nest_start(msg, NL80211_ATTR_MBSSID_ELEMS); |
| 4910 | if (!elems) |
| 4911 | return -1; |
| 4912 | |
| 4913 | for (i = 0; i < params->mbssid_elem_count - 1; i++) { |
| 4914 | if (nla_put(msg, i + 1, offs[i + 1] - offs[i], offs[i])) |
| 4915 | return -1; |
| 4916 | } |
| 4917 | |
| 4918 | if (nla_put(msg, i + 1, |
| 4919 | *offs + params->mbssid_elem_len - offs[i], |
| 4920 | offs[i])) |
| 4921 | return -1; |
| 4922 | |
| 4923 | nla_nest_end(msg, elems); |
| 4924 | } |
| 4925 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4926 | if (!params->ema) |
| 4927 | return 0; |
| 4928 | |
| 4929 | if (params->rnr_elem_count && params->rnr_elem_len && |
| 4930 | params->rnr_elem_offset && *params->rnr_elem_offset) { |
| 4931 | u8 i, **offs = params->rnr_elem_offset; |
| 4932 | |
| 4933 | elems = nla_nest_start(msg, NL80211_ATTR_EMA_RNR_ELEMS); |
| 4934 | if (!elems) |
| 4935 | return -1; |
| 4936 | |
| 4937 | for (i = 0; i < params->rnr_elem_count - 1; i++) { |
| 4938 | if (nla_put(msg, i + 1, offs[i + 1] - offs[i], offs[i])) |
| 4939 | return -1; |
| 4940 | } |
| 4941 | |
| 4942 | if (nla_put(msg, i + 1, *offs + params->rnr_elem_len - offs[i], |
| 4943 | offs[i])) |
| 4944 | return -1; |
| 4945 | nla_nest_end(msg, elems); |
| 4946 | } |
| 4947 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4948 | return 0; |
| 4949 | } |
| 4950 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4951 | #endif /* CONFIG_IEEE80211AX */ |
| 4952 | |
| 4953 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4954 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 4955 | static void qca_set_allowed_ap_freqs(struct wpa_driver_nl80211_data *drv, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4956 | const int *freqs, int num_freqs, |
| 4957 | int link_id) |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4958 | { |
| 4959 | struct nl_msg *msg; |
| 4960 | struct nlattr *params, *freqs_list; |
| 4961 | int i, ret; |
| 4962 | |
| 4963 | if (!drv->set_wifi_conf_vendor_cmd_avail || !drv->qca_ap_allowed_freqs) |
| 4964 | return; |
| 4965 | |
| 4966 | wpa_printf(MSG_DEBUG, "nl80211: Set AP allowed frequency list"); |
| 4967 | |
| 4968 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 4969 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 4970 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 4971 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 4972 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA))) |
| 4973 | goto err; |
| 4974 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4975 | if (link_id != NL80211_DRV_LINK_ID_NA && |
| 4976 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_MLO_LINK_ID, link_id)) |
| 4977 | goto err; |
| 4978 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4979 | freqs_list = nla_nest_start( |
| 4980 | msg, QCA_WLAN_VENDOR_ATTR_CONFIG_AP_ALLOWED_FREQ_LIST); |
| 4981 | if (!freqs_list) |
| 4982 | goto err; |
| 4983 | |
| 4984 | for (i = 0; i < num_freqs; i++) { |
| 4985 | if (nla_put_u32(msg, i, freqs[i])) |
| 4986 | goto err; |
| 4987 | } |
| 4988 | |
| 4989 | nla_nest_end(msg, freqs_list); |
| 4990 | nla_nest_end(msg, params); |
| 4991 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4992 | ret = send_and_recv_cmd(drv, msg); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4993 | if (ret) |
| 4994 | wpa_printf(MSG_ERROR, |
| 4995 | "nl80211: Failed set AP alllowed frequency list: %d (%s)", |
| 4996 | ret, strerror(-ret)); |
| 4997 | |
| 4998 | return; |
| 4999 | err: |
| 5000 | nlmsg_free(msg); |
| 5001 | } |
| 5002 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 5003 | |
| 5004 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5005 | static int nl80211_put_freq_params(struct nl_msg *msg, |
| 5006 | const struct hostapd_freq_params *freq) |
| 5007 | { |
| 5008 | enum hostapd_hw_mode hw_mode; |
| 5009 | int is_24ghz; |
| 5010 | u8 channel; |
| 5011 | |
| 5012 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
| 5013 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 5014 | return -ENOBUFS; |
| 5015 | |
| 5016 | wpa_printf(MSG_DEBUG, " * eht_enabled=%d", freq->eht_enabled); |
| 5017 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
| 5018 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 5019 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 5020 | wpa_printf(MSG_DEBUG, " * radar_background=%d", |
| 5021 | freq->radar_background); |
| 5022 | |
| 5023 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 5024 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 5025 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 5026 | |
| 5027 | if (freq->vht_enabled || |
| 5028 | ((freq->he_enabled || freq->eht_enabled) && !is_24ghz)) { |
| 5029 | enum nl80211_chan_width cw; |
| 5030 | |
| 5031 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
| 5032 | switch (freq->bandwidth) { |
| 5033 | case 20: |
| 5034 | cw = NL80211_CHAN_WIDTH_20; |
| 5035 | break; |
| 5036 | case 40: |
| 5037 | cw = NL80211_CHAN_WIDTH_40; |
| 5038 | break; |
| 5039 | case 80: |
| 5040 | if (freq->center_freq2) |
| 5041 | cw = NL80211_CHAN_WIDTH_80P80; |
| 5042 | else |
| 5043 | cw = NL80211_CHAN_WIDTH_80; |
| 5044 | break; |
| 5045 | case 160: |
| 5046 | cw = NL80211_CHAN_WIDTH_160; |
| 5047 | break; |
| 5048 | case 320: |
| 5049 | cw = NL80211_CHAN_WIDTH_320; |
| 5050 | break; |
| 5051 | default: |
| 5052 | return -EINVAL; |
| 5053 | } |
| 5054 | |
| 5055 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 5056 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 5057 | freq->center_freq1); |
| 5058 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 5059 | freq->center_freq2); |
| 5060 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 5061 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 5062 | freq->center_freq1) || |
| 5063 | (freq->center_freq2 && |
| 5064 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 5065 | freq->center_freq2))) |
| 5066 | return -ENOBUFS; |
| 5067 | } else if (freq->ht_enabled) { |
| 5068 | enum nl80211_channel_type ct; |
| 5069 | |
| 5070 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 5071 | freq->sec_channel_offset); |
| 5072 | switch (freq->sec_channel_offset) { |
| 5073 | case -1: |
| 5074 | ct = NL80211_CHAN_HT40MINUS; |
| 5075 | break; |
| 5076 | case 1: |
| 5077 | ct = NL80211_CHAN_HT40PLUS; |
| 5078 | break; |
| 5079 | default: |
| 5080 | ct = NL80211_CHAN_HT20; |
| 5081 | break; |
| 5082 | } |
| 5083 | |
| 5084 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
| 5085 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 5086 | return -ENOBUFS; |
| 5087 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 5088 | wpa_printf(MSG_DEBUG, |
| 5089 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5090 | freq->edmg.channels, freq->edmg.bw_config); |
| 5091 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5092 | freq->edmg.channels) || |
| 5093 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5094 | freq->edmg.bw_config)) |
| 5095 | return -1; |
| 5096 | } else { |
| 5097 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 5098 | NL80211_CHAN_NO_HT); |
| 5099 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 5100 | NL80211_CHAN_NO_HT)) |
| 5101 | return -ENOBUFS; |
| 5102 | } |
| 5103 | if (freq->radar_background && |
| 5104 | nla_put_flag(msg, NL80211_ATTR_RADAR_BACKGROUND)) |
| 5105 | return -ENOBUFS; |
| 5106 | |
| 5107 | return 0; |
| 5108 | } |
| 5109 | |
| 5110 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5111 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 5112 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5113 | { |
| 5114 | struct i802_bss *bss = priv; |
| 5115 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5116 | struct i802_link *link = bss->flink; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5117 | struct nl_msg *msg; |
| 5118 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5119 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5121 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5122 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5123 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5124 | #ifdef CONFIG_MESH |
| 5125 | struct wpa_driver_mesh_bss_params mesh_params; |
| 5126 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5127 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5128 | if (params->mld_ap) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5129 | if (!nl80211_link_valid(bss->valid_links, |
| 5130 | params->mld_link_id)) { |
| 5131 | wpa_printf(MSG_DEBUG, |
| 5132 | "nl80211: Link ID=%u invalid (valid: 0x%04x)", |
| 5133 | params->mld_link_id, bss->valid_links); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 5134 | return -EINVAL; |
| 5135 | } |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5136 | |
| 5137 | link = nl80211_get_link(bss, params->mld_link_id); |
| 5138 | } else if (bss->valid_links) { |
| 5139 | wpa_printf(MSG_DEBUG, "nl80211: MLD configuration expected"); |
| 5140 | return -EINVAL; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | beacon_set = params->reenable ? 0 : link->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5144 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5145 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 5146 | beacon_set); |
| 5147 | if (beacon_set) |
| 5148 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5149 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 5150 | !nl80211_get_wiphy_data_ap(bss)) |
| 5151 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5152 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5153 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 5154 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5155 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 5156 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5157 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5158 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5159 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 5160 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5161 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5162 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 5163 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5164 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 5165 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 5166 | params->head) || |
| 5167 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 5168 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5169 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5170 | nl80211_put_beacon_rate(msg, drv->capa.flags, drv->capa.flags2, |
| 5171 | params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5172 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5173 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5174 | goto fail; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5175 | |
| 5176 | if (params->mld_ap) { |
| 5177 | wpa_printf(MSG_DEBUG, "nl80211: link_id=%u", |
| 5178 | params->mld_link_id); |
| 5179 | |
| 5180 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5181 | params->mld_link_id)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5182 | goto fail; |
| 5183 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5184 | if (params->freq) |
| 5185 | nl80211_link_set_freq(bss, params->mld_link_id, |
| 5186 | params->freq->freq); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5189 | if (params->proberesp && params->proberesp_len) { |
| 5190 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 5191 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5192 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 5193 | params->proberesp)) |
| 5194 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5195 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5196 | switch (params->hide_ssid) { |
| 5197 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5198 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5199 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5200 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 5201 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5202 | break; |
| 5203 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5204 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5205 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5206 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 5207 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5208 | break; |
| 5209 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5210 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5211 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5212 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 5213 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5214 | break; |
| 5215 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5216 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5217 | if (params->privacy && |
| 5218 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 5219 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5220 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5221 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 5222 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 5223 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5224 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 5225 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 5226 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 5227 | goto fail; |
| 5228 | } else { |
| 5229 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 5230 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 5231 | goto fail; |
| 5232 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5233 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5234 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5235 | ver = 0; |
| 5236 | if (params->wpa_version & WPA_PROTO_WPA) |
| 5237 | ver |= NL80211_WPA_VERSION_1; |
| 5238 | if (params->wpa_version & WPA_PROTO_RSN) |
| 5239 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5240 | if (ver && |
| 5241 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5242 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5243 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5244 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 5245 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5246 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 5247 | suites, ARRAY_SIZE(suites)); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 5248 | if ((unsigned int) num_suites > drv->capa.max_num_akms) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5249 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 5250 | "nl80211: Not enough room for all AKM suites (num_suites=%d > %d)", |
| 5251 | num_suites, drv->capa.max_num_akms); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5252 | else if (num_suites && |
| 5253 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 5254 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5255 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5256 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5257 | if (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suites) && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5258 | (drv->capa.flags2 & WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5259 | params->psk_len && |
| 5260 | nla_put(msg, NL80211_ATTR_PMK, params->psk_len, params->psk)) |
| 5261 | goto fail; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5262 | |
| 5263 | if (wpa_key_mgmt_sae(params->key_mgmt_suites) && |
| 5264 | (drv->capa.flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5265 | params->sae_password && |
| 5266 | nla_put(msg, NL80211_ATTR_SAE_PASSWORD, |
| 5267 | os_strlen(params->sae_password), params->sae_password)) |
| 5268 | goto fail; |
| 5269 | |
| 5270 | if (nl80211_put_control_port(drv, msg) < 0) |
| 5271 | goto fail; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5272 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5273 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5274 | (!params->pairwise_ciphers || |
| 5275 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5276 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5277 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5278 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5279 | if (drv->device_ap_sme) { |
| 5280 | u32 flags = 0; |
| 5281 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 5282 | if (params->key_mgmt_suites & (WPA_KEY_MGMT_SAE | |
| 5283 | WPA_KEY_MGMT_SAE_EXT_KEY)) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5284 | /* Add the previously used flag attribute to support |
| 5285 | * older kernel versions and the newer flag bit for |
| 5286 | * newer kernels. */ |
| 5287 | if (nla_put_flag(msg, |
| 5288 | NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5289 | goto fail; |
| 5290 | flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 5291 | } |
| 5292 | |
| 5293 | flags |= NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT; |
| 5294 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5295 | if (nl80211_attr_supported(drv, |
| 5296 | NL80211_ATTR_AP_SETTINGS_FLAGS) && |
| 5297 | nla_put_u32(msg, NL80211_ATTR_AP_SETTINGS_FLAGS, flags)) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5298 | goto fail; |
| 5299 | } |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 5300 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5301 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 5302 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5303 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 5304 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5305 | if (num_suites && |
| 5306 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5307 | num_suites * sizeof(u32), suites)) |
| 5308 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5309 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5310 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 5311 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5312 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5313 | if (suite && |
| 5314 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 5315 | goto fail; |
| 5316 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5317 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5318 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 5319 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5320 | if (nla_put(msg, NL80211_ATTR_IE, |
| 5321 | wpabuf_len(params->beacon_ies), |
| 5322 | wpabuf_head(params->beacon_ies))) |
| 5323 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5324 | } |
| 5325 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5326 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 5327 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5328 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 5329 | wpabuf_len(params->proberesp_ies), |
| 5330 | wpabuf_head(params->proberesp_ies))) |
| 5331 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5332 | } |
| 5333 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5334 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 5335 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5336 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 5337 | wpabuf_len(params->assocresp_ies), |
| 5338 | wpabuf_head(params->assocresp_ies))) |
| 5339 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5340 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5341 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5342 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5343 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 5344 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5345 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 5346 | params->ap_max_inactivity)) |
| 5347 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5350 | #ifdef CONFIG_P2P |
| 5351 | if (params->p2p_go_ctwindow > 0) { |
| 5352 | if (drv->p2p_go_ctwindow_supported) { |
| 5353 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 5354 | params->p2p_go_ctwindow); |
| 5355 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 5356 | params->p2p_go_ctwindow)) |
| 5357 | goto fail; |
| 5358 | } else { |
| 5359 | wpa_printf(MSG_INFO, |
| 5360 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 5361 | } |
| 5362 | } |
| 5363 | #endif /* CONFIG_P2P */ |
| 5364 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5365 | if (params->pbss) { |
| 5366 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 5367 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5368 | goto fail; |
| 5369 | } |
| 5370 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5371 | if (params->ftm_responder) { |
| 5372 | struct nlattr *ftm; |
| 5373 | |
| 5374 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 5375 | ret = -ENOTSUP; |
| 5376 | goto fail; |
| 5377 | } |
| 5378 | |
| 5379 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 5380 | if (!ftm || |
| 5381 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 5382 | (params->lci && |
| 5383 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 5384 | wpabuf_len(params->lci), |
| 5385 | wpabuf_head(params->lci))) || |
| 5386 | (params->civic && |
| 5387 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 5388 | wpabuf_len(params->civic), |
| 5389 | wpabuf_head(params->civic)))) |
| 5390 | goto fail; |
| 5391 | nla_nest_end(msg, ftm); |
| 5392 | } |
| 5393 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5394 | if (params->freq && nl80211_put_freq_params(msg, params->freq) < 0) |
| 5395 | goto fail; |
| 5396 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5397 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5398 | if (params->he_spr_ctrl) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5399 | struct nlattr *spr; |
| 5400 | |
| 5401 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5402 | wpa_printf(MSG_DEBUG, "nl80211: he_spr_ctrl=0x%x", |
| 5403 | params->he_spr_ctrl); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5404 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5405 | if (!spr || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5406 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_SR_CTRL, |
| 5407 | params->he_spr_ctrl) || |
| 5408 | ((params->he_spr_ctrl & |
| 5409 | SPATIAL_REUSE_NON_SRG_OFFSET_PRESENT) && |
| 5410 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET, |
| 5411 | params->he_spr_non_srg_obss_pd_max_offset))) |
| 5412 | goto fail; |
| 5413 | |
| 5414 | if ((params->he_spr_ctrl & |
| 5415 | SPATIAL_REUSE_SRG_INFORMATION_PRESENT) && |
| 5416 | (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
| 5417 | params->he_spr_srg_obss_pd_min_offset) || |
| 5418 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 5419 | params->he_spr_srg_obss_pd_max_offset) || |
| 5420 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP, |
| 5421 | sizeof(params->he_spr_bss_color_bitmap), |
| 5422 | params->he_spr_bss_color_bitmap) || |
| 5423 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP, |
| 5424 | sizeof(params->he_spr_partial_bssid_bitmap), |
| 5425 | params->he_spr_partial_bssid_bitmap))) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5426 | goto fail; |
| 5427 | |
| 5428 | nla_nest_end(msg, spr); |
| 5429 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5430 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5431 | if (params->freq && params->freq->he_enabled && |
| 5432 | nl80211_attr_supported(drv, NL80211_ATTR_HE_BSS_COLOR)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5433 | struct nlattr *bss_color; |
| 5434 | |
| 5435 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 5436 | if (!bss_color || |
| 5437 | (params->he_bss_color_disabled && |
| 5438 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 5439 | (params->he_bss_color_partial && |
| 5440 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 5441 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 5442 | params->he_bss_color)) |
| 5443 | goto fail; |
| 5444 | nla_nest_end(msg, bss_color); |
| 5445 | } |
| 5446 | |
| 5447 | if (params->twt_responder) { |
| 5448 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 5449 | params->twt_responder); |
| 5450 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 5451 | goto fail; |
| 5452 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5453 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 5454 | if (params->ubpr.unsol_bcast_probe_resp_interval && |
| 5455 | nl80211_unsol_bcast_probe_resp(bss, msg, ¶ms->ubpr) < 0) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5456 | goto fail; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5457 | |
| 5458 | if (nl80211_mbssid(msg, params) < 0) |
| 5459 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5460 | #endif /* CONFIG_IEEE80211AX */ |
| 5461 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5462 | #ifdef CONFIG_SAE |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 5463 | if (wpa_key_mgmt_sae(params->key_mgmt_suites) && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5464 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 5465 | goto fail; |
| 5466 | #endif /* CONFIG_SAE */ |
| 5467 | |
| 5468 | #ifdef CONFIG_FILS |
| 5469 | if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
| 5470 | goto fail; |
| 5471 | #endif /* CONFIG_FILS */ |
| 5472 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5473 | if (params->punct_bitmap) { |
| 5474 | wpa_printf(MSG_DEBUG, "nl80211: Puncturing bitmap=0x%04x", |
| 5475 | params->punct_bitmap); |
| 5476 | if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, |
| 5477 | params->punct_bitmap)) |
| 5478 | goto fail; |
| 5479 | } |
| 5480 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 5481 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 5482 | if (cmd == NL80211_CMD_NEW_BEACON && params->allowed_freqs) |
| 5483 | qca_set_allowed_ap_freqs(drv, params->allowed_freqs, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5484 | int_array_len(params->allowed_freqs), |
| 5485 | params->mld_ap ? params->mld_link_id : |
| 5486 | NL80211_DRV_LINK_ID_NA); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 5487 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 5488 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5489 | if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER)) |
| 5490 | goto fail; |
| 5491 | ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL, |
| 5492 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5493 | if (ret) { |
| 5494 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 5495 | ret, strerror(-ret)); |
| 5496 | } else { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5497 | link->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5498 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 5499 | params->short_slot_time, params->ht_opmode, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5500 | params->isolate, params->basic_rates, |
| 5501 | params->mld_ap ? params->mld_link_id : |
| 5502 | NL80211_DRV_LINK_ID_NA); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5503 | nl80211_set_multicast_to_unicast(bss, |
| 5504 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5505 | if (beacon_set && params->freq && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5506 | params->freq->bandwidth != link->bandwidth) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5507 | wpa_printf(MSG_DEBUG, |
| 5508 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5509 | bss->ifname, link->bandwidth, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5510 | params->freq->bandwidth); |
| 5511 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 5512 | if (ret) { |
| 5513 | wpa_printf(MSG_DEBUG, |
| 5514 | "nl80211: Frequency set failed: %d (%s)", |
| 5515 | ret, strerror(-ret)); |
| 5516 | } else { |
| 5517 | wpa_printf(MSG_DEBUG, |
| 5518 | "nl80211: Frequency set succeeded for ht2040 coex"); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5519 | link->bandwidth = params->freq->bandwidth; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5520 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5521 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5522 | /* |
| 5523 | * cfg80211 updates the driver on frequence change in AP |
| 5524 | * mode only at the point when beaconing is started, so |
| 5525 | * set the initial value here. |
| 5526 | */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5527 | link->bandwidth = params->freq->bandwidth; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5528 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5529 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5530 | |
| 5531 | #ifdef CONFIG_MESH |
| 5532 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 5533 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 5534 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 5535 | mesh_params.ht_opmode = params->ht_opmode; |
| 5536 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 5537 | if (ret < 0) |
| 5538 | return ret; |
| 5539 | } |
| 5540 | #endif /* CONFIG_MESH */ |
| 5541 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5542 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5543 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5544 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5545 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5546 | } |
| 5547 | |
| 5548 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5549 | static int nl80211_set_channel(struct i802_bss *bss, |
| 5550 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5551 | { |
| 5552 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5553 | struct nl_msg *msg; |
| 5554 | int ret; |
| 5555 | |
| 5556 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5557 | "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)", |
| 5558 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 5559 | freq->he_enabled, freq->eht_enabled, freq->bandwidth, |
| 5560 | freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5561 | |
| 5562 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 5563 | NL80211_CMD_SET_WIPHY); |
| 5564 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 5565 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5566 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5567 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5568 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5569 | if (nl80211_link_valid(bss->valid_links, freq->link_id)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5570 | wpa_printf(MSG_DEBUG, "nl80211: Set link_id=%u for freq", |
| 5571 | freq->link_id); |
| 5572 | |
| 5573 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, freq->link_id)) { |
| 5574 | nlmsg_free(msg); |
| 5575 | return -ENOBUFS; |
| 5576 | } |
| 5577 | } |
| 5578 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5579 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5580 | if (ret == 0) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5581 | nl80211_link_set_freq(bss, freq->link_id, freq->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5582 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5583 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5584 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5585 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5586 | return -1; |
| 5587 | } |
| 5588 | |
| 5589 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5590 | static u32 sta_flags_nl80211(int flags) |
| 5591 | { |
| 5592 | u32 f = 0; |
| 5593 | |
| 5594 | if (flags & WPA_STA_AUTHORIZED) |
| 5595 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5596 | if (flags & WPA_STA_WMM) |
| 5597 | f |= BIT(NL80211_STA_FLAG_WME); |
| 5598 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 5599 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 5600 | if (flags & WPA_STA_MFP) |
| 5601 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 5602 | if (flags & WPA_STA_TDLS_PEER) |
| 5603 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5604 | if (flags & WPA_STA_AUTHENTICATED) |
| 5605 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5606 | if (flags & WPA_STA_ASSOCIATED) |
| 5607 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5608 | |
| 5609 | return f; |
| 5610 | } |
| 5611 | |
| 5612 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5613 | #ifdef CONFIG_MESH |
| 5614 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 5615 | { |
| 5616 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5617 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5618 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5619 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5620 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5621 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5622 | return NL80211_PLINK_OPN_RCVD; |
| 5623 | case PLINK_CNF_RCVD: |
| 5624 | return NL80211_PLINK_CNF_RCVD; |
| 5625 | case PLINK_ESTAB: |
| 5626 | return NL80211_PLINK_ESTAB; |
| 5627 | case PLINK_HOLDING: |
| 5628 | return NL80211_PLINK_HOLDING; |
| 5629 | case PLINK_BLOCKED: |
| 5630 | return NL80211_PLINK_BLOCKED; |
| 5631 | default: |
| 5632 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 5633 | state); |
| 5634 | } |
| 5635 | return -1; |
| 5636 | } |
| 5637 | #endif /* CONFIG_MESH */ |
| 5638 | |
| 5639 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5640 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 5641 | struct hostapd_sta_add_params *params) |
| 5642 | { |
| 5643 | struct i802_bss *bss = priv; |
| 5644 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5645 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5646 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5647 | int ret = -ENOBUFS; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5648 | u8 cmd; |
| 5649 | const char *cmd_string; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5650 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5651 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 5652 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 5653 | return -EOPNOTSUPP; |
| 5654 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5655 | if (params->mld_link_sta) { |
| 5656 | cmd = params->set ? NL80211_CMD_MODIFY_LINK_STA : |
| 5657 | NL80211_CMD_ADD_LINK_STA; |
| 5658 | cmd_string = params->set ? "NL80211_CMD_MODIFY_LINK_STA" : |
| 5659 | "NL80211_CMD_ADD_LINK_STA"; |
| 5660 | } else { |
| 5661 | cmd = params->set ? NL80211_CMD_SET_STATION : |
| 5662 | NL80211_CMD_NEW_STATION; |
| 5663 | cmd_string = params->set ? "NL80211_CMD_SET_STATION" : |
| 5664 | "NL80211_CMD_NEW_STATION"; |
| 5665 | } |
| 5666 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5667 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5668 | cmd_string, MAC2STR(params->addr)); |
| 5669 | msg = nl80211_bss_msg(bss, 0, cmd); |
| 5670 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5671 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5673 | /* |
| 5674 | * Set the below properties only in one of the following cases: |
| 5675 | * 1. New station is added, already associated. |
| 5676 | * 2. Set WPA_STA_TDLS_PEER station. |
| 5677 | * 3. Set an already added unassociated station, if driver supports |
| 5678 | * full AP client state. (Set these properties after station became |
| 5679 | * associated will be rejected by the driver). |
| 5680 | */ |
| 5681 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5682 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5683 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5684 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 5685 | params->supp_rates, params->supp_rates_len); |
| 5686 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 5687 | params->capability); |
| 5688 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 5689 | params->supp_rates_len, params->supp_rates) || |
| 5690 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 5691 | params->capability)) |
| 5692 | goto fail; |
| 5693 | |
| 5694 | if (params->ht_capabilities) { |
| 5695 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 5696 | (u8 *) params->ht_capabilities, |
| 5697 | sizeof(*params->ht_capabilities)); |
| 5698 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 5699 | sizeof(*params->ht_capabilities), |
| 5700 | params->ht_capabilities)) |
| 5701 | goto fail; |
| 5702 | } |
| 5703 | |
| 5704 | if (params->vht_capabilities) { |
| 5705 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 5706 | (u8 *) params->vht_capabilities, |
| 5707 | sizeof(*params->vht_capabilities)); |
| 5708 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 5709 | sizeof(*params->vht_capabilities), |
| 5710 | params->vht_capabilities)) |
| 5711 | goto fail; |
| 5712 | } |
| 5713 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5714 | if (params->he_capab) { |
| 5715 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 5716 | params->he_capab, params->he_capab_len); |
| 5717 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 5718 | params->he_capab_len, params->he_capab)) |
| 5719 | goto fail; |
| 5720 | } |
| 5721 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5722 | if (params->he_6ghz_capab) { |
| 5723 | wpa_hexdump(MSG_DEBUG, " * he_6ghz_capab", |
| 5724 | params->he_6ghz_capab, |
| 5725 | sizeof(*params->he_6ghz_capab)); |
| 5726 | if (nla_put(msg, NL80211_ATTR_HE_6GHZ_CAPABILITY, |
| 5727 | sizeof(*params->he_6ghz_capab), |
| 5728 | params->he_6ghz_capab)) |
| 5729 | goto fail; |
| 5730 | } |
| 5731 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5732 | if (params->eht_capab) { |
| 5733 | wpa_hexdump(MSG_DEBUG, " * eht_capab", |
| 5734 | params->eht_capab, params->eht_capab_len); |
| 5735 | if (nla_put(msg, NL80211_ATTR_EHT_CAPABILITY, |
| 5736 | params->eht_capab_len, params->eht_capab)) |
| 5737 | goto fail; |
| 5738 | } |
| 5739 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5740 | if (params->ext_capab) { |
| 5741 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 5742 | params->ext_capab, params->ext_capab_len); |
| 5743 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 5744 | params->ext_capab_len, params->ext_capab)) |
| 5745 | goto fail; |
| 5746 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5747 | |
| 5748 | if (is_ap_interface(drv->nlmode) && |
| 5749 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 5750 | params->support_p2p_ps ? |
| 5751 | NL80211_P2P_PS_SUPPORTED : |
| 5752 | NL80211_P2P_PS_UNSUPPORTED)) |
| 5753 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5754 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5755 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5756 | if (params->aid) { |
| 5757 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5758 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 5759 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5760 | } else { |
| 5761 | /* |
| 5762 | * cfg80211 validates that AID is non-zero, so we have |
| 5763 | * to make this a non-zero value for the TDLS case where |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5764 | * a stub STA entry is used for now and for a station |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5765 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5766 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5767 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 5768 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 5769 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5770 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 5771 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5772 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5773 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5774 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5775 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5776 | params->listen_interval)) |
| 5777 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5778 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 5779 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5780 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 5781 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5782 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5783 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 5784 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 5785 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5786 | params->listen_interval); |
| 5787 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 5788 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5789 | params->listen_interval)) |
| 5790 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 5793 | if (params->vht_opmode_enabled) { |
| 5794 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5795 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 5796 | params->vht_opmode)) |
| 5797 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5798 | } |
| 5799 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5800 | if (params->supp_channels) { |
| 5801 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 5802 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5803 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 5804 | params->supp_channels_len, params->supp_channels)) |
| 5805 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | if (params->supp_oper_classes) { |
| 5809 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 5810 | params->supp_oper_classes, |
| 5811 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5812 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 5813 | params->supp_oper_classes_len, |
| 5814 | params->supp_oper_classes)) |
| 5815 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5816 | } |
| 5817 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5818 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5819 | upd.set = sta_flags_nl80211(params->flags); |
| 5820 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5821 | |
| 5822 | /* |
| 5823 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 5824 | * flags, as nl80211 driver moves a new station, by default, into |
| 5825 | * associated state. |
| 5826 | * |
| 5827 | * On the other hand, if the driver supports that feature and the |
| 5828 | * station is added in unauthenticated state, set the |
| 5829 | * authenticated/associated bits in the mask to prevent moving this |
| 5830 | * station to associated state before it is actually associated. |
| 5831 | * |
| 5832 | * This is irrelevant for mesh mode where the station is added to the |
| 5833 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 5834 | * nl80211 API. |
| 5835 | */ |
| 5836 | if (!is_mesh_interface(drv->nlmode)) { |
| 5837 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 5838 | wpa_printf(MSG_DEBUG, |
| 5839 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 5840 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5841 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 5842 | } else if (!params->set && |
| 5843 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 5844 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 5845 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 5846 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 5847 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 5848 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5849 | #ifdef CONFIG_MESH |
| 5850 | } else { |
| 5851 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 5852 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 5853 | params->peer_aid); |
| 5854 | if (ret) |
| 5855 | goto fail; |
| 5856 | } |
| 5857 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5858 | } |
| 5859 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5860 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 5861 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5862 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5863 | goto fail; |
| 5864 | |
| 5865 | #ifdef CONFIG_MESH |
| 5866 | if (params->plink_state && |
| 5867 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 5868 | sta_plink_state_nl80211(params->plink_state))) |
| 5869 | goto fail; |
| 5870 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5871 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5872 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5873 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 5874 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5875 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 5876 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5877 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5878 | if (!wme || |
| 5879 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 5880 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 5881 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 5882 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 5883 | WMM_QOSINFO_STA_SP_MASK)) |
| 5884 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5885 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5886 | } |
| 5887 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5888 | /* In case we are an AP MLD need to always specify the link ID */ |
| 5889 | if (params->mld_link_id >= 0) { |
| 5890 | wpa_printf(MSG_DEBUG, " * mld_link_id=%d", |
| 5891 | params->mld_link_id); |
| 5892 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 5893 | params->mld_link_id)) |
| 5894 | goto fail; |
| 5895 | |
| 5896 | /* |
| 5897 | * If the link address is specified the station is a non-AP MLD |
| 5898 | * and thus need to provide the MLD address as the station |
| 5899 | * address, and the non-AP MLD link address as the link address. |
| 5900 | */ |
| 5901 | if (params->mld_link_addr) { |
| 5902 | wpa_printf(MSG_DEBUG, " * mld_link_addr=" MACSTR, |
| 5903 | MAC2STR(params->mld_link_addr)); |
| 5904 | |
| 5905 | if (nla_put(msg, NL80211_ATTR_MLD_ADDR, |
| 5906 | ETH_ALEN, params->addr) || |
| 5907 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 5908 | params->mld_link_addr)) |
| 5909 | goto fail; |
| 5910 | } else { |
| 5911 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 5912 | params->addr)) |
| 5913 | goto fail; |
| 5914 | } |
| 5915 | } else { |
| 5916 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 5917 | goto fail; |
| 5918 | } |
| 5919 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5920 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5921 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | if (ret) |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5923 | wpa_printf(MSG_DEBUG, "nl80211: %s result: %d (%s)", |
| 5924 | cmd_string, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5925 | if (ret == -EEXIST) |
| 5926 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5927 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5928 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5929 | return ret; |
| 5930 | } |
| 5931 | |
| 5932 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5933 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 5934 | { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5935 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5936 | struct ndmsg nhdr = { |
| 5937 | .ndm_state = NUD_PERMANENT, |
| 5938 | .ndm_ifindex = bss->ifindex, |
| 5939 | .ndm_family = AF_BRIDGE, |
| 5940 | }; |
| 5941 | struct nl_msg *msg; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5942 | int err; |
| 5943 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5944 | msg = nlmsg_alloc_simple(RTM_DELNEIGH, NLM_F_CREATE); |
| 5945 | if (!msg) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5946 | return; |
| 5947 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5948 | if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0 || |
| 5949 | nla_put(msg, NDA_LLADDR, ETH_ALEN, (void *) addr) || |
| 5950 | nl_send_auto_complete(drv->rtnl_sk, msg) < 0) |
| 5951 | goto errout; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5952 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5953 | err = nl_wait_for_ack(drv->rtnl_sk); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5954 | if (err < 0) { |
| 5955 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 5956 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 5957 | bss->ifindex, nl_geterror(err)); |
| 5958 | } else { |
| 5959 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 5960 | MACSTR, MAC2STR(addr)); |
| 5961 | } |
| 5962 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5963 | errout: |
| 5964 | nlmsg_free(msg); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5968 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 5969 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5971 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5972 | struct nl_msg *msg; |
| 5973 | int ret; |
| 5974 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5975 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 5976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5977 | (deauth == 0 && |
| 5978 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5979 | WLAN_FC_STYPE_DISASSOC)) || |
| 5980 | (deauth == 1 && |
| 5981 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5982 | WLAN_FC_STYPE_DEAUTH)) || |
| 5983 | (reason_code && |
| 5984 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 5985 | nlmsg_free(msg); |
| 5986 | return -ENOBUFS; |
| 5987 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5988 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5989 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5990 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 5991 | " --> %d (%s)", |
| 5992 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5993 | |
| 5994 | if (drv->rtnl_sk) |
| 5995 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 5996 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5997 | if (ret == -ENOENT) |
| 5998 | return 0; |
| 5999 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6003 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6004 | { |
| 6005 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6006 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6007 | |
| 6008 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 6009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6011 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 6012 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6013 | { |
| 6014 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 6015 | /* Remove all bridges learned for this iface */ |
| 6016 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 6017 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6018 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6019 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6020 | if (send_and_recv_cmd(drv, msg) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6021 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6022 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 6023 | } |
| 6024 | |
| 6025 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6026 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6027 | { |
| 6028 | switch (mode) { |
| 6029 | case NL80211_IFTYPE_ADHOC: |
| 6030 | return "ADHOC"; |
| 6031 | case NL80211_IFTYPE_STATION: |
| 6032 | return "STATION"; |
| 6033 | case NL80211_IFTYPE_AP: |
| 6034 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 6035 | case NL80211_IFTYPE_AP_VLAN: |
| 6036 | return "AP_VLAN"; |
| 6037 | case NL80211_IFTYPE_WDS: |
| 6038 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6039 | case NL80211_IFTYPE_MONITOR: |
| 6040 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 6041 | case NL80211_IFTYPE_MESH_POINT: |
| 6042 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6043 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6044 | return "P2P_CLIENT"; |
| 6045 | case NL80211_IFTYPE_P2P_GO: |
| 6046 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6047 | case NL80211_IFTYPE_P2P_DEVICE: |
| 6048 | return "P2P_DEVICE"; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6049 | case NL80211_IFTYPE_OCB: |
| 6050 | return "OCB"; |
| 6051 | case NL80211_IFTYPE_NAN: |
| 6052 | return "NAN"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6053 | default: |
| 6054 | return "unknown"; |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6059 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 6060 | const char *ifname, |
| 6061 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6062 | const u8 *addr, int wds, |
| 6063 | int (*handler)(struct nl_msg *, void *), |
| 6064 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6065 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6066 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6067 | int ifidx; |
| 6068 | int ret = -ENOBUFS; |
| 6069 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6070 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 6071 | iftype, nl80211_iftype_str(iftype)); |
| 6072 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6073 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 6074 | if (!msg || |
| 6075 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 6076 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 6077 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6078 | |
| 6079 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6080 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6081 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6082 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6083 | if (!flags || |
| 6084 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 6085 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6086 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6087 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6088 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6089 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 6090 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6091 | } |
| 6092 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 6093 | /* |
| 6094 | * Tell cfg80211 that the interface belongs to the socket that created |
| 6095 | * it, and the interface should be deleted when the socket is closed. |
| 6096 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6097 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 6098 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 6099 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6100 | if ((addr && iftype == NL80211_IFTYPE_P2P_DEVICE) && |
| 6101 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 6102 | goto fail; |
| 6103 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6104 | ret = send_and_recv_resp(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6105 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6107 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6108 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6109 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 6110 | ifname, ret, strerror(-ret)); |
| 6111 | return ret; |
| 6112 | } |
| 6113 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6114 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 6115 | return 0; |
| 6116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6117 | ifidx = if_nametoindex(ifname); |
| 6118 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 6119 | ifname, ifidx); |
| 6120 | |
| 6121 | if (ifidx <= 0) |
| 6122 | return -1; |
| 6123 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6124 | /* |
| 6125 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6126 | * the parent interface. This is used mainly with hostapd. |
| 6127 | */ |
| 6128 | if (drv->hostapd || |
| 6129 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 6130 | iftype == NL80211_IFTYPE_WDS || |
| 6131 | iftype == NL80211_IFTYPE_MONITOR) { |
| 6132 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6133 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6134 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6135 | |
| 6136 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6137 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6138 | nl80211_remove_iface(drv, ifidx); |
| 6139 | return -1; |
| 6140 | } |
| 6141 | |
| 6142 | return ifidx; |
| 6143 | } |
| 6144 | |
| 6145 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6146 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 6147 | const char *ifname, enum nl80211_iftype iftype, |
| 6148 | const u8 *addr, int wds, |
| 6149 | int (*handler)(struct nl_msg *, void *), |
| 6150 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | { |
| 6152 | int ret; |
| 6153 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6154 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 6155 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6158 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6159 | if (use_existing) { |
| 6160 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 6161 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6162 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 6163 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 6164 | addr) < 0 && |
| 6165 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 6166 | ifname, 0) < 0 || |
| 6167 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 6168 | addr) < 0 || |
| 6169 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 6170 | ifname, 1) < 0)) |
| 6171 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6172 | return -ENFILE; |
| 6173 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6174 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 6175 | |
| 6176 | /* Try to remove the interface that was already there. */ |
| 6177 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 6178 | |
| 6179 | /* Try to create the interface again */ |
| 6180 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6181 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6182 | } |
| 6183 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6184 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 6185 | wpa_printf(MSG_DEBUG, |
| 6186 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 6187 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6188 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6189 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6190 | |
| 6191 | return ret; |
| 6192 | } |
| 6193 | |
| 6194 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6195 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 6196 | { |
| 6197 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6198 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6199 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 6200 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6201 | |
| 6202 | /* |
| 6203 | * Disable Probe Request reporting unless we need it in this way for |
| 6204 | * devices that include the AP SME, in the other case (unless using |
| 6205 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 6206 | */ |
| 6207 | if (!drv->device_ap_sme) |
| 6208 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 6209 | |
| 6210 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 6211 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 6212 | return -1; |
| 6213 | |
| 6214 | if (drv->device_ap_sme && !drv->use_monitor) |
| 6215 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6216 | wpa_printf(MSG_DEBUG, |
| 6217 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6218 | |
| 6219 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 6220 | nl80211_create_monitor_interface(drv) && |
| 6221 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6222 | return -1; |
| 6223 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6224 | if (drv->device_ap_sme && |
| 6225 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 6226 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 6227 | "Probe Request frame reporting in AP mode"); |
| 6228 | /* Try to survive without this */ |
| 6229 | } |
| 6230 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6231 | return 0; |
| 6232 | } |
| 6233 | |
| 6234 | |
| 6235 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 6236 | { |
| 6237 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6238 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6239 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 6240 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6241 | if (drv->device_ap_sme) { |
| 6242 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 6243 | if (!drv->use_monitor) |
| 6244 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 6245 | } else if (drv->use_monitor) |
| 6246 | nl80211_remove_monitor_interface(drv); |
| 6247 | else |
| 6248 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 6249 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6250 | nl80211_put_wiphy_data_ap(bss); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6251 | if (bss->flink) |
| 6252 | bss->flink->beacon_set = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6256 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 6257 | u16 proto, const u8 *buf, size_t len, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6258 | int no_encrypt, int link_id) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6259 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6260 | struct nl80211_ack_ext_arg ext_arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6261 | struct i802_bss *bss = priv; |
| 6262 | struct nl_msg *msg; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6263 | u64 cookie = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6264 | int ret; |
| 6265 | |
| 6266 | wpa_printf(MSG_DEBUG, |
| 6267 | "nl80211: Send over control port dest=" MACSTR |
| 6268 | " proto=0x%04x len=%u no_encrypt=%d", |
| 6269 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 6270 | |
| 6271 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 6272 | if (!msg || |
| 6273 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 6274 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 6275 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 6276 | (no_encrypt && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6277 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) || |
| 6278 | (link_id != NL80211_DRV_LINK_ID_NA && |
| 6279 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6280 | nlmsg_free(msg); |
| 6281 | return -ENOBUFS; |
| 6282 | } |
| 6283 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6284 | os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg)); |
| 6285 | ext_arg.ext_data = &cookie; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6286 | ret = send_and_recv(bss->drv->global, bss->drv->global->nl, msg, |
| 6287 | NULL, NULL, ack_handler_cookie, &ext_arg, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6288 | if (ret) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6289 | wpa_printf(MSG_DEBUG, |
| 6290 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 6291 | ret, strerror(-ret)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6292 | } else { |
| 6293 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6294 | |
| 6295 | wpa_printf(MSG_DEBUG, |
| 6296 | "nl80211: tx_control_port cookie=0x%llx", |
| 6297 | (long long unsigned int) cookie); |
| 6298 | drv->eapol_tx_cookie = cookie; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6299 | drv->eapol_tx_link_id = link_id; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6300 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6301 | |
| 6302 | return ret; |
| 6303 | } |
| 6304 | |
| 6305 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6306 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 6307 | const u8 *addr, const u8 *data, |
| 6308 | size_t data_len) |
| 6309 | { |
| 6310 | struct sockaddr_ll ll; |
| 6311 | int ret; |
| 6312 | |
| 6313 | if (bss->drv->eapol_tx_sock < 0) { |
| 6314 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 6315 | return -1; |
| 6316 | } |
| 6317 | |
| 6318 | os_memset(&ll, 0, sizeof(ll)); |
| 6319 | ll.sll_family = AF_PACKET; |
| 6320 | ll.sll_ifindex = bss->ifindex; |
| 6321 | ll.sll_protocol = htons(ETH_P_PAE); |
| 6322 | ll.sll_halen = ETH_ALEN; |
| 6323 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 6324 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 6325 | (struct sockaddr *) &ll, sizeof(ll)); |
| 6326 | if (ret < 0) |
| 6327 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 6328 | strerror(errno)); |
| 6329 | |
| 6330 | return ret; |
| 6331 | } |
| 6332 | |
| 6333 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6334 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 6335 | |
| 6336 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 6337 | void *priv, const u8 *addr, const u8 *data, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6338 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags, |
| 6339 | int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6340 | { |
| 6341 | struct i802_bss *bss = priv; |
| 6342 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6343 | struct ieee80211_hdr *hdr; |
| 6344 | size_t len; |
| 6345 | u8 *pos; |
| 6346 | int res; |
| 6347 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 6348 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6349 | /* For now, disable EAPOL TX over control port in AP mode by default |
| 6350 | * since it does not provide TX status notifications. */ |
| 6351 | if (drv->control_port_ap && |
| 6352 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6353 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6354 | data, data_len, !encrypt, |
| 6355 | link_id); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6356 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6357 | if (drv->device_ap_sme || !drv->use_monitor) |
| 6358 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 6359 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 6361 | data_len; |
| 6362 | hdr = os_zalloc(len); |
| 6363 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6364 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 6365 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6366 | return -1; |
| 6367 | } |
| 6368 | |
| 6369 | hdr->frame_control = |
| 6370 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 6371 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6372 | if (encrypt) |
| 6373 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 6374 | if (qos) { |
| 6375 | hdr->frame_control |= |
| 6376 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 6377 | } |
| 6378 | |
| 6379 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6380 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6381 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6382 | pos = (u8 *) (hdr + 1); |
| 6383 | |
| 6384 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6385 | /* Set highest priority in QoS header */ |
| 6386 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6387 | pos[1] = 0; |
| 6388 | pos += 2; |
| 6389 | } |
| 6390 | |
| 6391 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 6392 | pos += sizeof(rfc1042_header); |
| 6393 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 6394 | pos += 2; |
| 6395 | memcpy(pos, data, data_len); |
| 6396 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6397 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6398 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6399 | wpa_printf(MSG_ERROR, |
| 6400 | "hapd_send_eapol - packet len: %lu - failed", |
| 6401 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6402 | } |
| 6403 | os_free(hdr); |
| 6404 | |
| 6405 | return res; |
| 6406 | } |
| 6407 | |
| 6408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6409 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6410 | unsigned int total_flags, |
| 6411 | unsigned int flags_or, |
| 6412 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6413 | { |
| 6414 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6415 | struct nl_msg *msg; |
| 6416 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6417 | struct nl80211_sta_flag_update upd; |
| 6418 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6419 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 6420 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 6421 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 6422 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 6423 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6424 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6425 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 6426 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6427 | |
| 6428 | /* |
| 6429 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 6430 | * can be removed eventually. |
| 6431 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6432 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6433 | if (!flags || |
| 6434 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 6435 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 6436 | ((total_flags & WPA_STA_WMM) && |
| 6437 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 6438 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 6439 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 6440 | ((total_flags & WPA_STA_MFP) && |
| 6441 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 6442 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 6443 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 6444 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6445 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6446 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6447 | |
| 6448 | os_memset(&upd, 0, sizeof(upd)); |
| 6449 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 6450 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6451 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 6452 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6453 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6454 | return send_and_recv_cmd(bss->drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6455 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6456 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6457 | return -ENOBUFS; |
| 6458 | } |
| 6459 | |
| 6460 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6461 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 6462 | unsigned int weight) |
| 6463 | { |
| 6464 | struct i802_bss *bss = priv; |
| 6465 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6466 | int ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6467 | |
| 6468 | wpa_printf(MSG_DEBUG, |
| 6469 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 6470 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 6471 | |
| 6472 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6473 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6474 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 6475 | goto fail; |
| 6476 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6477 | ret = send_and_recv_cmd(bss->drv, msg); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6478 | if (ret) { |
| 6479 | wpa_printf(MSG_DEBUG, |
| 6480 | "nl80211: SET_STATION[AIRTIME_WEIGHT] failed: ret=%d (%s)", |
| 6481 | ret, strerror(-ret)); |
| 6482 | } |
| 6483 | return ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6484 | fail: |
| 6485 | nlmsg_free(msg); |
| 6486 | return -ENOBUFS; |
| 6487 | } |
| 6488 | |
| 6489 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6490 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 6491 | struct wpa_driver_associate_params *params) |
| 6492 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6493 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6494 | |
| 6495 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6496 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 6497 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6498 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 6499 | } else |
| 6500 | nlmode = NL80211_IFTYPE_AP; |
| 6501 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6502 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6503 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6504 | nl80211_remove_monitor_interface(drv); |
| 6505 | return -1; |
| 6506 | } |
| 6507 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6508 | if (params->freq.freq && |
| 6509 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6510 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6511 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6512 | nl80211_remove_monitor_interface(drv); |
| 6513 | return -1; |
| 6514 | } |
| 6515 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6516 | return 0; |
| 6517 | } |
| 6518 | |
| 6519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6520 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 6521 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6522 | { |
| 6523 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6524 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6525 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6526 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6527 | ret = send_and_recv(drv->global, drv->first_bss->nl_connect, msg, NULL, |
| 6528 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6529 | if (ret) { |
| 6530 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 6531 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6532 | } else { |
| 6533 | wpa_printf(MSG_DEBUG, |
| 6534 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6535 | } |
| 6536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6537 | if (reset_mode && |
| 6538 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6539 | NL80211_IFTYPE_STATION)) { |
| 6540 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6541 | "station mode"); |
| 6542 | } |
| 6543 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6544 | return ret; |
| 6545 | } |
| 6546 | |
| 6547 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6548 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 6549 | struct wpa_driver_associate_params *params) |
| 6550 | { |
| 6551 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 6552 | return -1; |
| 6553 | |
| 6554 | if (params->htcaps && params->htcaps_mask) { |
| 6555 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 6556 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 6557 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 6558 | params->htcaps_mask, sz); |
| 6559 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 6560 | params->htcaps) || |
| 6561 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 6562 | params->htcaps_mask)) |
| 6563 | return -1; |
| 6564 | } |
| 6565 | |
| 6566 | #ifdef CONFIG_VHT_OVERRIDES |
| 6567 | if (params->disable_vht) { |
| 6568 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 6569 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 6570 | return -1; |
| 6571 | } |
| 6572 | |
| 6573 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 6574 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 6575 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 6576 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 6577 | params->vhtcaps_mask, sz); |
| 6578 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 6579 | params->vhtcaps) || |
| 6580 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 6581 | params->vhtcaps_mask)) |
| 6582 | return -1; |
| 6583 | } |
| 6584 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 6585 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6586 | #ifdef CONFIG_HE_OVERRIDES |
| 6587 | if (params->disable_he) { |
| 6588 | wpa_printf(MSG_DEBUG, " * HE disabled"); |
| 6589 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_HE)) |
| 6590 | return -1; |
| 6591 | } |
| 6592 | #endif /* CONFIG_HE_OVERRIDES */ |
| 6593 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6594 | if (params->disable_eht) { |
| 6595 | wpa_printf(MSG_DEBUG, " * EHT disabled"); |
| 6596 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_EHT)) |
| 6597 | return -1; |
| 6598 | } |
| 6599 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6600 | return 0; |
| 6601 | } |
| 6602 | |
| 6603 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6604 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 6605 | struct wpa_driver_associate_params *params) |
| 6606 | { |
| 6607 | struct nl_msg *msg; |
| 6608 | int ret = -1; |
| 6609 | int count = 0; |
| 6610 | |
| 6611 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 6612 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6613 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6614 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6615 | "IBSS mode"); |
| 6616 | return -1; |
| 6617 | } |
| 6618 | |
| 6619 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6620 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 6621 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 6622 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6623 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6624 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6625 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6626 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 6627 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6629 | drv->ssid_len = params->ssid_len; |
| 6630 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6631 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 6632 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6633 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6634 | |
| 6635 | ret = nl80211_set_conn_keys(params, msg); |
| 6636 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6637 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6638 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6639 | if (params->bssid && params->fixed_bssid) { |
| 6640 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 6641 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6642 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6643 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6644 | } |
| 6645 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6646 | if (params->fixed_freq) { |
| 6647 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 6648 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 6649 | goto fail; |
| 6650 | } |
| 6651 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6652 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6653 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6654 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6655 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 6656 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6657 | wpa_printf(MSG_DEBUG, " * control port"); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6658 | if (nl80211_put_control_port(drv, msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6659 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6660 | } |
| 6661 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6662 | if (params->wpa_ie) { |
| 6663 | wpa_hexdump(MSG_DEBUG, |
| 6664 | " * Extra IEs for Beacon/Probe Response frames", |
| 6665 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6666 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 6667 | params->wpa_ie)) |
| 6668 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6669 | } |
| 6670 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 6671 | ret = nl80211_ht_vht_overrides(msg, params); |
| 6672 | if (ret < 0) |
| 6673 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6674 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6675 | if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER)) |
| 6676 | goto fail; |
| 6677 | ret = send_and_recv(drv->global, drv->first_bss->nl_connect, msg, NULL, |
| 6678 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6679 | msg = NULL; |
| 6680 | if (ret) { |
| 6681 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 6682 | ret, strerror(-ret)); |
| 6683 | count++; |
| 6684 | if (ret == -EALREADY && count == 1) { |
| 6685 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 6686 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6687 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6688 | nlmsg_free(msg); |
| 6689 | goto retry; |
| 6690 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6691 | } else { |
| 6692 | wpa_printf(MSG_DEBUG, |
| 6693 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6694 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6695 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6696 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | nlmsg_free(msg); |
| 6698 | return ret; |
| 6699 | } |
| 6700 | |
| 6701 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6702 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 6703 | struct wpa_driver_associate_params *params, |
| 6704 | struct nl_msg *msg) |
| 6705 | { |
| 6706 | if (params->fils_erp_username_len) { |
| 6707 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 6708 | params->fils_erp_username, |
| 6709 | params->fils_erp_username_len); |
| 6710 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 6711 | params->fils_erp_username_len, |
| 6712 | params->fils_erp_username)) |
| 6713 | return -1; |
| 6714 | } |
| 6715 | |
| 6716 | if (params->fils_erp_realm_len) { |
| 6717 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 6718 | params->fils_erp_realm, |
| 6719 | params->fils_erp_realm_len); |
| 6720 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 6721 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 6722 | return -1; |
| 6723 | } |
| 6724 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6725 | if (params->fils_erp_rrk_len) { |
Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 6726 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 6727 | params->fils_erp_next_seq_num); |
| 6728 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 6729 | params->fils_erp_next_seq_num)) |
| 6730 | return -1; |
| 6731 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6732 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 6733 | (unsigned long) params->fils_erp_rrk_len); |
| 6734 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 6735 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 6736 | return -1; |
| 6737 | } |
| 6738 | |
| 6739 | return 0; |
| 6740 | } |
| 6741 | |
| 6742 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6743 | static unsigned int num_bits_set(u32 val) |
| 6744 | { |
| 6745 | unsigned int c; |
| 6746 | |
| 6747 | for (c = 0; val; c++) |
| 6748 | val &= val - 1; |
| 6749 | |
| 6750 | return c; |
| 6751 | } |
| 6752 | |
| 6753 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6754 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 6755 | struct wpa_driver_associate_params *params, |
| 6756 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6757 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6758 | if (params->mld_params.mld_addr && params->mld_params.valid_links > 0) { |
| 6759 | struct wpa_driver_mld_params *mld_params = ¶ms->mld_params; |
| 6760 | struct nlattr *links, *attr; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6761 | u8 link_id; |
| 6762 | |
| 6763 | wpa_printf(MSG_DEBUG, " * MLD: MLD addr=" MACSTR, |
| 6764 | MAC2STR(mld_params->mld_addr)); |
| 6765 | |
| 6766 | if (nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, |
| 6767 | mld_params->mld_addr) || |
| 6768 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 6769 | mld_params->assoc_link_id)) |
| 6770 | return -1; |
| 6771 | |
| 6772 | links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); |
| 6773 | if (!links) |
| 6774 | return -1; |
| 6775 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6776 | for_each_link(mld_params->valid_links, link_id) { |
| 6777 | attr = nla_nest_start(msg, 0); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6778 | if (!attr) |
| 6779 | return -1; |
| 6780 | |
| 6781 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 6782 | link_id) || |
| 6783 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 6784 | mld_params->mld_links[link_id].bssid) || |
| 6785 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6786 | mld_params->mld_links[link_id].freq) || |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6787 | (mld_params->mld_links[link_id].disabled && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6788 | nla_put_flag(msg, |
| 6789 | NL80211_ATTR_MLO_LINK_DISABLED)) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6790 | (mld_params->mld_links[link_id].ies && |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6791 | mld_params->mld_links[link_id].ies_len && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6792 | nla_put(msg, NL80211_ATTR_IE, |
| 6793 | mld_params->mld_links[link_id].ies_len, |
| 6794 | mld_params->mld_links[link_id].ies))) |
| 6795 | return -1; |
| 6796 | |
| 6797 | os_memcpy(drv->sta_mlo_info.links[link_id].bssid, |
| 6798 | mld_params->mld_links[link_id].bssid, |
| 6799 | ETH_ALEN); |
| 6800 | nla_nest_end(msg, attr); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
| 6803 | nla_nest_end(msg, links); |
| 6804 | |
| 6805 | os_memcpy(drv->sta_mlo_info.ap_mld_addr, |
| 6806 | params->mld_params.mld_addr, ETH_ALEN); |
| 6807 | drv->sta_mlo_info.assoc_link_id = mld_params->assoc_link_id; |
| 6808 | drv->sta_mlo_info.req_links = mld_params->valid_links; |
| 6809 | } |
| 6810 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6811 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 6812 | return -1; |
| 6813 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6814 | if (params->bssid && !params->mld_params.mld_addr) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6815 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 6816 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6817 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6818 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6819 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6820 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6821 | if (params->bssid_hint) { |
| 6822 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 6823 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6824 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 6825 | params->bssid_hint)) |
| 6826 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6827 | } |
| 6828 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6829 | if (params->freq.freq && !params->mld_params.mld_addr) { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6830 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6831 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6832 | params->freq.freq)) |
| 6833 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6834 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6835 | } else |
| 6836 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6837 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6838 | if (params->freq_hint) { |
| 6839 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6840 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 6841 | params->freq_hint)) |
| 6842 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6843 | } |
| 6844 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6845 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 6846 | wpa_printf(MSG_DEBUG, |
| 6847 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 6848 | params->freq.edmg.channels, |
| 6849 | params->freq.edmg.bw_config); |
| 6850 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 6851 | params->freq.edmg.channels) || |
| 6852 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 6853 | params->freq.edmg.bw_config)) |
| 6854 | return -1; |
| 6855 | } |
| 6856 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6857 | if (params->bg_scan_period >= 0) { |
| 6858 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 6859 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6860 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 6861 | params->bg_scan_period)) |
| 6862 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6863 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6864 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6865 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6866 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6867 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6868 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6869 | params->ssid)) |
| 6870 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6871 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6872 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6873 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6874 | drv->ssid_len = params->ssid_len; |
| 6875 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6876 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6877 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6878 | if (params->wpa_ie && |
| 6879 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 6880 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6881 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6882 | if (params->wpa_proto) { |
| 6883 | enum nl80211_wpa_versions ver = 0; |
| 6884 | |
| 6885 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 6886 | ver |= NL80211_WPA_VERSION_1; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6887 | if (params->wpa_proto & WPA_PROTO_RSN) { |
| 6888 | #if !defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(CONFIG_DRIVER_NL80211_SYNA) |
| 6889 | /* |
| 6890 | * NL80211_ATTR_SAE_PASSWORD is related and was added |
| 6891 | * at the same time as NL80211_WPA_VERSION_3. |
| 6892 | */ |
| 6893 | if (nl80211_attr_supported(drv, |
| 6894 | NL80211_ATTR_SAE_PASSWORD) && |
| 6895 | wpa_key_mgmt_sae(params->key_mgmt_suite)) |
| 6896 | ver |= NL80211_WPA_VERSION_3; |
| 6897 | else |
| 6898 | #endif |
| 6899 | ver |= NL80211_WPA_VERSION_2; |
| 6900 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6901 | |
| 6902 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6903 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 6904 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 6908 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 6909 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6910 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 6911 | cipher)) |
| 6912 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6913 | } |
| 6914 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6915 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 6916 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 6917 | /* |
| 6918 | * This is likely to work even though many drivers do not |
| 6919 | * advertise support for operations without GTK. |
| 6920 | */ |
| 6921 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 6922 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6923 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 6924 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6925 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 6926 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6930 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6931 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 6932 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6933 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6934 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 6935 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6936 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6937 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6938 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE_EXT_KEY || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6939 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6940 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE_EXT_KEY || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6941 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6942 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6943 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6944 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 6945 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 6946 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6947 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 6948 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6949 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP || |
| 6950 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6951 | u32 *mgmt; |
| 6952 | unsigned int akm_count = 1, i; |
| 6953 | |
| 6954 | /* |
| 6955 | * Make sure the driver has capability to handle default AKM in |
| 6956 | * key_mgmt_suite plus allowed AKMs in allowed_key_mgmts. |
| 6957 | */ |
| 6958 | if (drv->capa.max_num_akms <= |
| 6959 | num_bits_set(params->allowed_key_mgmts)) { |
| 6960 | wpa_printf(MSG_INFO, |
| 6961 | "nl80211: Not enough support for the allowed AKMs (max_num_akms=%u <= num_bits_set=%u)", |
| 6962 | drv->capa.max_num_akms, |
| 6963 | num_bits_set(params->allowed_key_mgmts)); |
| 6964 | return -1; |
| 6965 | } |
| 6966 | |
| 6967 | mgmt = os_malloc(sizeof(u32) * drv->capa.max_num_akms); |
| 6968 | if (!mgmt) |
| 6969 | return -1; |
| 6970 | |
| 6971 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6972 | |
| 6973 | switch (params->key_mgmt_suite) { |
| 6974 | case WPA_KEY_MGMT_CCKM: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6975 | mgmt[0] = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6976 | break; |
| 6977 | case WPA_KEY_MGMT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6978 | mgmt[0] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6979 | break; |
| 6980 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6981 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6982 | break; |
| 6983 | case WPA_KEY_MGMT_FT_PSK: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6984 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6985 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6986 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6987 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6988 | break; |
| 6989 | case WPA_KEY_MGMT_PSK_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6990 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6991 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6992 | case WPA_KEY_MGMT_OSEN: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6993 | mgmt[0] = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6994 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6995 | case WPA_KEY_MGMT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6996 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE; |
| 6997 | break; |
| 6998 | case WPA_KEY_MGMT_SAE_EXT_KEY: |
| 6999 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7000 | break; |
| 7001 | case WPA_KEY_MGMT_FT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7002 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 7003 | break; |
| 7004 | case WPA_KEY_MGMT_FT_SAE_EXT_KEY: |
| 7005 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7006 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7007 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7008 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7009 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7010 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7011 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7012 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7013 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7014 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7015 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7016 | case WPA_KEY_MGMT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7017 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7018 | break; |
| 7019 | case WPA_KEY_MGMT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7020 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7021 | break; |
| 7022 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7023 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7024 | break; |
| 7025 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7026 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7027 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7028 | case WPA_KEY_MGMT_OWE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7029 | mgmt[0] = RSN_AUTH_KEY_MGMT_OWE; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7030 | break; |
| 7031 | case WPA_KEY_MGMT_DPP: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7032 | mgmt[0] = RSN_AUTH_KEY_MGMT_DPP; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7033 | break; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7034 | case WPA_KEY_MGMT_IEEE8021X_SHA384: |
| 7035 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA384; |
| 7036 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7037 | case WPA_KEY_MGMT_PSK: |
| 7038 | default: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7039 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7040 | break; |
| 7041 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7042 | |
| 7043 | if (drv->capa.max_num_akms > 1) { |
| 7044 | akm_count += wpa_key_mgmt_to_suites( |
| 7045 | params->allowed_key_mgmts, &mgmt[1], |
| 7046 | drv->capa.max_num_akms - 1); |
| 7047 | } |
| 7048 | |
| 7049 | for (i = 0; i < akm_count; i++) |
| 7050 | wpa_printf(MSG_DEBUG, " * akm[%d]=0x%x", i, mgmt[i]); |
| 7051 | |
| 7052 | if (nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 7053 | akm_count * sizeof(u32), mgmt)) { |
| 7054 | os_free(mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7055 | return -1; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7056 | } |
| 7057 | |
| 7058 | os_free(mgmt); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7059 | } |
| 7060 | |
Isaac Chiou | 6ce580d | 2024-04-24 17:07:24 +0800 | [diff] [blame] | 7061 | #if (defined(CONFIG_DRIVER_NL80211_BRCM) && !defined(WIFI_BRCM_OPEN_SOURCE_MULTI_AKM)) || \ |
| 7062 | defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 7063 | if (IS_CROSS_AKM_ROAM_KEY_MGMT(params->key_mgmt_suite)) { |
| 7064 | int num_suites; |
| 7065 | u32 suites[NL80211_MAX_NR_AKM_SUITES]; |
| 7066 | |
| 7067 | wpa_printf(MSG_INFO, "nl80211: key_mgmt_suites=0x%x", |
| 7068 | params->key_mgmt_suite); |
| 7069 | num_suites = wpa_cross_akm_key_mgmt_to_suites(params->key_mgmt_suite, |
| 7070 | suites, ARRAY_SIZE(suites)); |
| 7071 | if (num_suites && |
| 7072 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), suites)) { |
| 7073 | wpa_printf(MSG_ERROR, "Updating multi akm_suite failed"); |
| 7074 | return -1; |
| 7075 | } |
| 7076 | } |
Isaac Chiou | 6ce580d | 2024-04-24 17:07:24 +0800 | [diff] [blame] | 7077 | #endif /* (CONFIG_DRIVER_NL80211_BRCM && !WIFI_BRCM_OPEN_SOURCE_MULTI_AKM) || |
| 7078 | * CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 7079 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7080 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 7081 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 7082 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 7083 | return -1; |
| 7084 | } |
| 7085 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7086 | /* Add PSK in case of 4-way handshake offload */ |
| 7087 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7088 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7089 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 7090 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 7091 | return -1; |
| 7092 | } |
| 7093 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7094 | if (nl80211_put_control_port(drv, msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7095 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7096 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 7097 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 7098 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 7099 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 7100 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7101 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 7102 | return -1; |
| 7103 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7104 | if (params->rrm_used) { |
| 7105 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7106 | if ((!((drv_rrm_flags & |
| 7107 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 7108 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 7109 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7110 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 7111 | return -1; |
| 7112 | } |
| 7113 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7114 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7115 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7116 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7117 | if (params->p2p) |
| 7118 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 7119 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7120 | if (params->pbss) { |
| 7121 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 7122 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 7123 | return -1; |
| 7124 | } |
| 7125 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7126 | drv->connect_reassoc = 0; |
| 7127 | if (params->prev_bssid) { |
| 7128 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 7129 | MAC2STR(params->prev_bssid)); |
| 7130 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 7131 | params->prev_bssid)) |
| 7132 | return -1; |
| 7133 | drv->connect_reassoc = 1; |
| 7134 | } |
| 7135 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7136 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 7137 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 7138 | return -1; |
| 7139 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7140 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 7141 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7142 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 7143 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 7144 | return -1; |
| 7145 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7146 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
| 7147 | nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT)) |
| 7148 | return -1; |
| 7149 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7150 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7151 | } |
| 7152 | |
| 7153 | |
| 7154 | static int wpa_driver_nl80211_try_connect( |
| 7155 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7156 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7157 | struct i802_bss *bss) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7158 | { |
| 7159 | struct nl_msg *msg; |
| 7160 | enum nl80211_auth_type type; |
| 7161 | int ret; |
| 7162 | int algs; |
| 7163 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7164 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7165 | if (params->req_key_mgmt_offload && params->psk && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7166 | (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suite) || |
| 7167 | wpa_key_mgmt_wpa_psk_no_sae(params->allowed_key_mgmts))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7168 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 7169 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 7170 | if (ret) |
| 7171 | return ret; |
| 7172 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7173 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7174 | |
| 7175 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 7176 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7177 | if (!msg) |
| 7178 | return -1; |
| 7179 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7180 | ret = nl80211_connect_common(drv, params, msg); |
| 7181 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7182 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7183 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7184 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 7185 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 7186 | goto fail; |
| 7187 | |
| 7188 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 7189 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 7190 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 7191 | goto fail; |
| 7192 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7193 | #ifdef CONFIG_SAE |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7194 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 7195 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7196 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 7197 | goto fail; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7198 | |
| 7199 | /* Add SAE password in case of SAE authentication offload */ |
| 7200 | if ((params->sae_password || params->passphrase) && |
| 7201 | (drv->capa.flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA)) { |
| 7202 | const char *password; |
| 7203 | size_t pwd_len; |
| 7204 | |
| 7205 | if (params->sae_password && params->sae_password_id) { |
| 7206 | wpa_printf(MSG_INFO, |
| 7207 | "nl80211: Use of SAE password identifiers not supported with driver-based SAE"); |
| 7208 | goto fail; |
| 7209 | } |
| 7210 | |
| 7211 | password = params->sae_password; |
| 7212 | if (!password) |
| 7213 | password = params->passphrase; |
| 7214 | pwd_len = os_strlen(password); |
| 7215 | wpa_printf(MSG_DEBUG, " * SAE password"); |
| 7216 | if (nla_put(msg, NL80211_ATTR_SAE_PASSWORD, pwd_len, password)) |
| 7217 | goto fail; |
| 7218 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7219 | #endif /* CONFIG_SAE */ |
| 7220 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7221 | algs = 0; |
| 7222 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 7223 | algs++; |
| 7224 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 7225 | algs++; |
| 7226 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 7227 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7228 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 7229 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7230 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 7231 | algs++; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7232 | if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 7233 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7234 | if (algs > 1) { |
| 7235 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 7236 | "selection"); |
| 7237 | goto skip_auth_type; |
| 7238 | } |
| 7239 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7240 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7241 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7242 | if (type == NL80211_AUTHTYPE_MAX || |
| 7243 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7244 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7245 | |
| 7246 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7247 | ret = nl80211_set_conn_keys(params, msg); |
| 7248 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7249 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7250 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7251 | if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER)) |
| 7252 | goto fail; |
| 7253 | ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL, |
| 7254 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7255 | msg = NULL; |
| 7256 | if (ret) { |
| 7257 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 7258 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7259 | } else { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7260 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7261 | drv->roam_indication_done = false; |
| 7262 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7263 | wpa_printf(MSG_DEBUG, |
| 7264 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7265 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7267 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7268 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7269 | nlmsg_free(msg); |
| 7270 | return ret; |
| 7271 | |
| 7272 | } |
| 7273 | |
| 7274 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7275 | static int wpa_driver_nl80211_connect( |
| 7276 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7277 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7278 | struct i802_bss *bss) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7279 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 7280 | int ret; |
| 7281 | |
| 7282 | /* Store the connection attempted bssid for future use */ |
| 7283 | if (params->bssid) |
| 7284 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 7285 | else |
| 7286 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 7287 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7288 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7289 | if (ret == -EALREADY) { |
| 7290 | /* |
| 7291 | * cfg80211 does not currently accept new connections if |
| 7292 | * we are already connected. As a workaround, force |
| 7293 | * disconnection and try again. |
| 7294 | */ |
| 7295 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 7296 | "disconnecting before reassociation " |
| 7297 | "attempt"); |
| 7298 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7299 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, bss)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7300 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7301 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7302 | } |
| 7303 | return ret; |
| 7304 | } |
| 7305 | |
| 7306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7307 | static int wpa_driver_nl80211_associate( |
| 7308 | void *priv, struct wpa_driver_associate_params *params) |
| 7309 | { |
| 7310 | struct i802_bss *bss = priv; |
| 7311 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7312 | struct nl80211_err_info err_info; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7313 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7314 | struct nl_msg *msg; |
| 7315 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7316 | nl80211_unmask_11b_rates(bss); |
| 7317 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7318 | if (params->mode == IEEE80211_MODE_AP) |
| 7319 | return wpa_driver_nl80211_ap(drv, params); |
| 7320 | |
| 7321 | if (params->mode == IEEE80211_MODE_IBSS) |
| 7322 | return wpa_driver_nl80211_ibss(drv, params); |
| 7323 | |
| 7324 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7325 | enum nl80211_iftype nlmode = params->p2p ? |
| 7326 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 7327 | |
| 7328 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7329 | return -1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7330 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7331 | return wpa_driver_nl80211_connect(drv, params, bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7332 | } |
| 7333 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7334 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7335 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7336 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 7337 | drv->ifindex); |
| 7338 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7339 | if (!msg) |
| 7340 | return -1; |
| 7341 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7342 | ret = nl80211_connect_common(drv, params, msg); |
| 7343 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7344 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7345 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7346 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 7347 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 7348 | goto fail; |
| 7349 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7350 | if (params->fils_kek) { |
| 7351 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 7352 | (unsigned int) params->fils_kek_len); |
| 7353 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 7354 | params->fils_kek)) |
| 7355 | goto fail; |
| 7356 | } |
| 7357 | if (params->fils_nonces) { |
| 7358 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 7359 | params->fils_nonces, |
| 7360 | params->fils_nonces_len); |
| 7361 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 7362 | params->fils_nonces_len, params->fils_nonces)) |
| 7363 | goto fail; |
| 7364 | } |
| 7365 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7366 | if (!TEST_FAIL_TAG("assoc")) { |
| 7367 | if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER)) |
| 7368 | goto fail; |
| 7369 | ret = send_and_recv(drv->global, drv->first_bss->nl_connect, |
| 7370 | msg, NULL, NULL, NULL, NULL, &err_info); |
| 7371 | msg = NULL; |
| 7372 | } else { |
| 7373 | int i; |
| 7374 | |
| 7375 | /* Error and force TEST_FAIL checking for each link */ |
| 7376 | ret = -EINVAL; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7377 | for_each_link(params->mld_params.valid_links, i) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7378 | if (TEST_FAIL_TAG("link")) |
| 7379 | err_info.link_id = i; |
| 7380 | } |
| 7381 | } |
| 7382 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7383 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7384 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 7385 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 7386 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7387 | nl80211_dump_scan(drv); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7388 | |
| 7389 | /* Mark failed link within params */ |
| 7390 | if (err_info.link_id >= 0) { |
| 7391 | if (err_info.link_id >= MAX_NUM_MLD_LINKS || |
| 7392 | !(params->mld_params.valid_links & |
| 7393 | BIT(err_info.link_id))) { |
| 7394 | wpa_printf(MSG_DEBUG, |
| 7395 | "nl80211: Invalid errorred link_id %d", |
| 7396 | err_info.link_id); |
| 7397 | goto fail; |
| 7398 | } |
| 7399 | params->mld_params.mld_links[err_info.link_id].error = |
| 7400 | ret; |
| 7401 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7402 | } else { |
| 7403 | wpa_printf(MSG_DEBUG, |
| 7404 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7405 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7407 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7408 | nlmsg_free(msg); |
| 7409 | return ret; |
| 7410 | } |
| 7411 | |
| 7412 | |
| 7413 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7414 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7415 | { |
| 7416 | struct nl_msg *msg; |
| 7417 | int ret = -ENOBUFS; |
| 7418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7419 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 7420 | ifindex, mode, nl80211_iftype_str(mode)); |
| 7421 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7422 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 7423 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 7424 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7425 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7426 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7427 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7428 | if (!ret) |
| 7429 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7430 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7431 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7432 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 7433 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 7434 | return ret; |
| 7435 | } |
| 7436 | |
| 7437 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7438 | static int wpa_driver_nl80211_set_mode_impl( |
| 7439 | struct i802_bss *bss, |
| 7440 | enum nl80211_iftype nlmode, |
| 7441 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7442 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7443 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7444 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7445 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7446 | int was_ap = is_ap_interface(drv->nlmode); |
| 7447 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7448 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7449 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7450 | if (TEST_FAIL()) |
| 7451 | return -1; |
| 7452 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7453 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 7454 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 7455 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7456 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7457 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7458 | drv->nlmode = nlmode; |
| 7459 | ret = 0; |
| 7460 | goto done; |
| 7461 | } |
| 7462 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7463 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7464 | return -1; |
| 7465 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7466 | if (nlmode == drv->nlmode) { |
| 7467 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 7468 | "requested mode - ignore error"); |
| 7469 | ret = 0; |
| 7470 | goto done; /* Already in the requested mode */ |
| 7471 | } |
| 7472 | |
| 7473 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 7474 | * take the device down, try to set the mode again, and bring the |
| 7475 | * device back up. |
| 7476 | */ |
| 7477 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 7478 | "interface down"); |
| 7479 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7480 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7481 | if (res == -EACCES || res == -ENODEV) |
| 7482 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7483 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7484 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 7485 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7486 | os_sleep(0, 100000); |
| 7487 | continue; |
| 7488 | } |
| 7489 | |
| 7490 | /* |
| 7491 | * Setting the mode will fail for some drivers if the phy is |
| 7492 | * on a frequency that the mode is disallowed in. |
| 7493 | */ |
| 7494 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7495 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7496 | if (res) { |
| 7497 | wpa_printf(MSG_DEBUG, |
| 7498 | "nl80211: Failed to set frequency on interface"); |
| 7499 | } |
| 7500 | } |
| 7501 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7502 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && |
| 7503 | bss->brname[0] && |
| 7504 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 7505 | wpa_printf(MSG_DEBUG, |
| 7506 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", |
| 7507 | bss->ifname, bss->brname); |
| 7508 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 7509 | bss->brname, bss->ifname) < 0) |
| 7510 | wpa_printf(MSG_INFO, |
| 7511 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7512 | bss->ifname, bss->brname, |
| 7513 | strerror(errno)); |
| 7514 | } |
| 7515 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7516 | /* Try to set the mode again while the interface is down */ |
| 7517 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 7518 | if (mode_switch_res == -EBUSY) { |
| 7519 | wpa_printf(MSG_DEBUG, |
| 7520 | "nl80211: Delaying mode set while interface going down"); |
| 7521 | os_sleep(0, 100000); |
| 7522 | continue; |
| 7523 | } |
| 7524 | ret = mode_switch_res; |
| 7525 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | if (!ret) { |
| 7529 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 7530 | "interface is down"); |
| 7531 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7532 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7533 | } |
| 7534 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7535 | /* Bring the interface back up */ |
| 7536 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 7537 | if (res != 0) { |
| 7538 | wpa_printf(MSG_DEBUG, |
| 7539 | "nl80211: Failed to set interface up after switching mode"); |
| 7540 | ret = -1; |
| 7541 | } |
| 7542 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7543 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7544 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7545 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 7546 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7547 | return ret; |
| 7548 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7549 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7550 | if (is_p2p_net_interface(nlmode)) { |
| 7551 | wpa_printf(MSG_DEBUG, |
| 7552 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 7553 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7554 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7555 | } else if (drv->disabled_11b_rates) { |
| 7556 | wpa_printf(MSG_DEBUG, |
| 7557 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 7558 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7559 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7560 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7562 | if (is_ap_interface(nlmode)) { |
| 7563 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 7564 | /* Setup additional AP mode functionality if needed */ |
| 7565 | if (nl80211_setup_ap(bss)) |
| 7566 | return -1; |
| 7567 | } else if (was_ap) { |
| 7568 | /* Remove additional AP mode functionality */ |
| 7569 | nl80211_teardown_ap(bss); |
| 7570 | } else { |
| 7571 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 7572 | } |
| 7573 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7574 | if (is_mesh_interface(nlmode) && |
| 7575 | nl80211_mgmt_subscribe_mesh(bss)) |
| 7576 | return -1; |
| 7577 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7578 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7579 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7580 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 7581 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 7582 | "frame processing - ignore for now"); |
| 7583 | |
| 7584 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7585 | } |
| 7586 | |
| 7587 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7588 | void nl80211_restore_ap_mode(struct i802_bss *bss) |
| 7589 | { |
| 7590 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7591 | int was_ap = is_ap_interface(drv->nlmode); |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7592 | int br_ifindex; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7593 | |
| 7594 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); |
| 7595 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && |
| 7596 | bss->brname[0] && |
| 7597 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 7598 | wpa_printf(MSG_DEBUG, |
| 7599 | "nl80211: Add AP interface %s back into the bridge %s", |
| 7600 | bss->ifname, bss->brname); |
| 7601 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, |
| 7602 | bss->ifname) < 0) { |
| 7603 | wpa_printf(MSG_WARNING, |
| 7604 | "nl80211: Failed to add interface %s into bridge %s: %s", |
| 7605 | bss->ifname, bss->brname, strerror(errno)); |
| 7606 | } |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7607 | br_ifindex = if_nametoindex(bss->brname); |
| 7608 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7609 | } |
| 7610 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
| 7611 | } |
| 7612 | |
| 7613 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7614 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 7615 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7616 | { |
| 7617 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 7618 | } |
| 7619 | |
| 7620 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7621 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 7622 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7623 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7624 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7625 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7626 | } |
| 7627 | |
| 7628 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7629 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 7630 | struct wpa_driver_capa *capa) |
| 7631 | { |
| 7632 | struct i802_bss *bss = priv; |
| 7633 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 7634 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7635 | if (!drv->has_capability) |
| 7636 | return -1; |
| 7637 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7638 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 7639 | capa->extended_capa = drv->extended_capa; |
| 7640 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 7641 | capa->extended_capa_len = drv->extended_capa_len; |
| 7642 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7643 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7644 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | |
| 7648 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 7649 | { |
| 7650 | struct i802_bss *bss = priv; |
| 7651 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7652 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7653 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 7654 | bss->ifname, drv->operstate, state, |
| 7655 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7656 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7657 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7658 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 7659 | } |
| 7660 | |
| 7661 | |
| 7662 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 7663 | { |
| 7664 | struct i802_bss *bss = priv; |
| 7665 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7666 | struct nl_msg *msg; |
| 7667 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7668 | int ret; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7669 | const u8 *connected_addr = drv->sta_mlo_info.valid_links ? |
| 7670 | drv->sta_mlo_info.ap_mld_addr : drv->bssid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7671 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7672 | if (!drv->associated && is_zero_ether_addr(connected_addr) && |
| 7673 | !authorized) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7674 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 7675 | return 0; |
| 7676 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7677 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7678 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7679 | MACSTR, authorized ? "" : "un", MAC2STR(connected_addr)); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7681 | os_memset(&upd, 0, sizeof(upd)); |
| 7682 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7683 | if (authorized) |
| 7684 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7685 | |
| 7686 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7687 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7688 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 7689 | nlmsg_free(msg); |
| 7690 | return -ENOBUFS; |
| 7691 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7692 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7693 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7694 | if (!ret) |
| 7695 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7696 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 7697 | ret, strerror(-ret)); |
| 7698 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7699 | } |
| 7700 | |
| 7701 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7702 | /* Set kernel driver on given frequency (MHz) */ |
| 7703 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7704 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7705 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 7706 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7710 | static inline int min_int(int a, int b) |
| 7711 | { |
| 7712 | if (a < b) |
| 7713 | return a; |
| 7714 | return b; |
| 7715 | } |
| 7716 | |
| 7717 | |
| 7718 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 7719 | { |
| 7720 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7721 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7722 | |
| 7723 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7724 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7725 | |
| 7726 | /* |
| 7727 | * TODO: validate the key index and mac address! |
| 7728 | * Otherwise, there's a race condition as soon as |
| 7729 | * the kernel starts sending key notifications. |
| 7730 | */ |
| 7731 | |
| 7732 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 7733 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 7734 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7735 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7736 | return NL_SKIP; |
| 7737 | } |
| 7738 | |
| 7739 | |
| 7740 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7741 | int idx, int link_id, u8 *seq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7742 | { |
| 7743 | struct i802_bss *bss = priv; |
| 7744 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7745 | struct nl_msg *msg; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7746 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7747 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7748 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 7749 | NL80211_CMD_GET_KEY); |
| 7750 | if (!msg || |
| 7751 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7752 | (link_id != NL80211_DRV_LINK_ID_NA && |
| 7753 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7754 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 7755 | nlmsg_free(msg); |
| 7756 | return -ENOBUFS; |
| 7757 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7758 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7759 | os_memset(seq, 0, 6); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7760 | res = send_and_recv_resp(drv, msg, get_key_handler, seq); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7761 | if (res) { |
| 7762 | wpa_printf(MSG_DEBUG, |
| 7763 | "nl80211: Failed to get current TX sequence for a key (link_id=%d idx=%d): %d (%s)", |
| 7764 | link_id, idx, res, strerror(-res)); |
| 7765 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7766 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7767 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | } |
| 7769 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7770 | |
| 7771 | static int i802_set_rts(void *priv, int rts) |
| 7772 | { |
| 7773 | struct i802_bss *bss = priv; |
| 7774 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7775 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7776 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7777 | u32 val; |
| 7778 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7779 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7780 | val = (u32) -1; |
| 7781 | else |
| 7782 | val = rts; |
| 7783 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7784 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7785 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 7786 | nlmsg_free(msg); |
| 7787 | return -ENOBUFS; |
| 7788 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7789 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7790 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7791 | if (!ret) |
| 7792 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7793 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 7794 | "%d (%s)", rts, ret, strerror(-ret)); |
| 7795 | return ret; |
| 7796 | } |
| 7797 | |
| 7798 | |
| 7799 | static int i802_set_frag(void *priv, int frag) |
| 7800 | { |
| 7801 | struct i802_bss *bss = priv; |
| 7802 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7803 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7804 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7805 | u32 val; |
| 7806 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7807 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7808 | val = (u32) -1; |
| 7809 | else |
| 7810 | val = frag; |
| 7811 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7812 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7813 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 7814 | nlmsg_free(msg); |
| 7815 | return -ENOBUFS; |
| 7816 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7817 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7818 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7819 | if (!ret) |
| 7820 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7821 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 7822 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 7823 | return ret; |
| 7824 | } |
| 7825 | |
| 7826 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 7827 | static int i802_flush(void *priv, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7828 | { |
| 7829 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7830 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7831 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7832 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 7833 | if (link_id == NL80211_DRV_LINK_ID_NA) |
| 7834 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 7835 | bss->ifname); |
| 7836 | else |
| 7837 | wpa_printf(MSG_DEBUG, |
| 7838 | "nl80211: flush -> DEL_STATION %s (with link %d)", |
| 7839 | bss->ifname, link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7840 | |
| 7841 | /* |
| 7842 | * XXX: FIX! this needs to flush all VLANs too |
| 7843 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7844 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 7845 | if (link_id >= 0 && (bss->valid_links & BIT(link_id)) && |
| 7846 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 7847 | goto fail; |
| 7848 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7849 | res = send_and_recv_cmd(bss->drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7850 | if (res) { |
| 7851 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 7852 | "(%s)", res, strerror(-res)); |
| 7853 | } |
| 7854 | return res; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 7855 | fail: |
| 7856 | nlmsg_free(msg); |
| 7857 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7858 | } |
| 7859 | |
| 7860 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7861 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 7862 | struct nlattr *attr) |
| 7863 | { |
| 7864 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 7865 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 7866 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 7867 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 7868 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 7869 | }; |
| 7870 | int rem; |
| 7871 | |
| 7872 | nla_for_each_nested(tidattr, attr, rem) { |
| 7873 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 7874 | tidattr, NULL) != 0 || |
| 7875 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 7876 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 7877 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 7878 | txq_stats_policy) != 0) |
| 7879 | continue; |
| 7880 | /* sum the backlogs over all TIDs for station */ |
| 7881 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 7882 | data->backlog_bytes += nla_get_u32( |
| 7883 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 7884 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 7885 | data->backlog_bytes += nla_get_u32( |
| 7886 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 7887 | } |
| 7888 | } |
| 7889 | |
| 7890 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7891 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 7892 | { |
| 7893 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7894 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7895 | struct hostap_sta_driver_data *data = arg; |
| 7896 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 7897 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 7898 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 7899 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 7900 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7901 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7902 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 7903 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7904 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7905 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7906 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
| 7907 | [NL80211_STA_INFO_CONNECTED_TIME] = { .type = NLA_U32 }, |
| 7908 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7909 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 7910 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7911 | [NL80211_STA_INFO_EXPECTED_THROUGHPUT] = { .type = NLA_U32 }, |
| 7912 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64 }, |
| 7913 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64 }, |
| 7914 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8}, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7915 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7916 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
| 7917 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_S8 }, |
| 7918 | [NL80211_STA_INFO_RX_MPDUS] = { .type = NLA_U32 }, |
| 7919 | [NL80211_STA_INFO_FCS_ERROR_COUNT] = { .type = NLA_U32 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7920 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7921 | }; |
| 7922 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 7923 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 7924 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 7925 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 7926 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 7927 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 7928 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 7929 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7930 | [NL80211_RATE_INFO_HE_MCS] = { .type = NLA_U8 }, |
| 7931 | [NL80211_RATE_INFO_HE_NSS] = { .type = NLA_U8 }, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7932 | [NL80211_RATE_INFO_HE_GI] = { .type = NLA_U8 }, |
| 7933 | [NL80211_RATE_INFO_HE_DCM] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7934 | }; |
| 7935 | |
| 7936 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7937 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7938 | |
| 7939 | /* |
| 7940 | * TODO: validate the interface and mac address! |
| 7941 | * Otherwise, there's a race condition as soon as |
| 7942 | * the kernel starts sending station notifications. |
| 7943 | */ |
| 7944 | |
| 7945 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 7946 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 7947 | return NL_SKIP; |
| 7948 | } |
| 7949 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 7950 | tb[NL80211_ATTR_STA_INFO], |
| 7951 | stats_policy)) { |
| 7952 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 7953 | return NL_SKIP; |
| 7954 | } |
| 7955 | |
| 7956 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 7957 | data->inactive_msec = |
| 7958 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7959 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7960 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 7961 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 7962 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 7963 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7964 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 7965 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 7966 | /* |
| 7967 | * The driver supports 64-bit counters, so use them to override |
| 7968 | * the 32-bit values. |
| 7969 | */ |
| 7970 | data->rx_bytes = |
| 7971 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 7972 | data->tx_bytes = |
| 7973 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 7974 | data->bytes_64bit = 1; |
| 7975 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7976 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 7977 | data->signal = (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7978 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 7979 | data->rx_packets = |
| 7980 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 7981 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 7982 | data->tx_packets = |
| 7983 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7984 | if (stats[NL80211_STA_INFO_TX_RETRIES]) |
| 7985 | data->tx_retry_count = |
| 7986 | nla_get_u32(stats[NL80211_STA_INFO_TX_RETRIES]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7987 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 7988 | data->tx_retry_failed = |
| 7989 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7990 | if (stats[NL80211_STA_INFO_SIGNAL_AVG]) |
| 7991 | data->avg_signal = |
| 7992 | (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL_AVG]); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7993 | if (stats[NL80211_STA_INFO_CONNECTED_TIME]) { |
| 7994 | data->connected_sec = |
| 7995 | nla_get_u32(stats[NL80211_STA_INFO_CONNECTED_TIME]); |
| 7996 | data->flags |= STA_DRV_DATA_CONN_TIME; |
| 7997 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7998 | if (stats[NL80211_STA_INFO_BEACON_LOSS]) |
| 7999 | data->beacon_loss_count = |
| 8000 | nla_get_u32(stats[NL80211_STA_INFO_BEACON_LOSS]); |
| 8001 | if (stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) |
| 8002 | data->expected_throughput = |
| 8003 | nla_get_u32(stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); |
| 8004 | if (stats[NL80211_STA_INFO_RX_DROP_MISC]) |
| 8005 | data->rx_drop_misc = |
| 8006 | nla_get_u64(stats[NL80211_STA_INFO_RX_DROP_MISC]); |
| 8007 | if (stats[NL80211_STA_INFO_BEACON_RX]) |
| 8008 | data->beacons_count = |
| 8009 | nla_get_u64(stats[NL80211_STA_INFO_BEACON_RX]); |
| 8010 | if (stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 8011 | data->avg_beacon_signal = |
| 8012 | (s8) nla_get_u8(stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 8013 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 8014 | data->rx_airtime = |
| 8015 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 8016 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 8017 | data->last_ack_rssi = |
| 8018 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 8019 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 8020 | } |
| 8021 | if (stats[NL80211_STA_INFO_ACK_SIGNAL_AVG]) |
| 8022 | data->avg_ack_signal = |
| 8023 | nla_get_s8(stats[NL80211_STA_INFO_ACK_SIGNAL_AVG]); |
| 8024 | if (stats[NL80211_STA_INFO_RX_MPDUS]) |
| 8025 | data->rx_mpdus = nla_get_u32(stats[NL80211_STA_INFO_RX_MPDUS]); |
| 8026 | if (stats[NL80211_STA_INFO_FCS_ERROR_COUNT]) |
| 8027 | data->fcs_error_count = |
| 8028 | nla_get_u32(stats[NL80211_STA_INFO_FCS_ERROR_COUNT]); |
| 8029 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 8030 | data->tx_airtime = |
| 8031 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8032 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8033 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 8034 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 8035 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 8036 | rate_policy) == 0) { |
| 8037 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 8038 | data->current_tx_rate = |
| 8039 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 8040 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 8041 | data->current_tx_rate = |
| 8042 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 8043 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8044 | /* Convert from 100 kbps to kbps; it's a more convenient unit. |
| 8045 | * It's also safe up until ~1Tbps. */ |
| 8046 | data->current_tx_rate = data->current_tx_rate * 100; |
| 8047 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8048 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 8049 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 8050 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 8051 | } |
| 8052 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 8053 | data->tx_vhtmcs = |
| 8054 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 8055 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 8056 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8057 | if (rate[NL80211_RATE_INFO_SHORT_GI]) { |
| 8058 | data->tx_guard_interval = GUARD_INTERVAL_0_4; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8059 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8060 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8061 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 8062 | data->tx_vht_nss = |
| 8063 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 8064 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 8065 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8066 | if (rate[NL80211_RATE_INFO_HE_MCS]) { |
| 8067 | data->tx_hemcs = |
| 8068 | nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]); |
| 8069 | data->flags |= STA_DRV_DATA_TX_HE_MCS; |
| 8070 | } |
| 8071 | if (rate[NL80211_RATE_INFO_HE_NSS]) { |
| 8072 | data->tx_he_nss = |
| 8073 | nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]); |
| 8074 | data->flags |= STA_DRV_DATA_TX_HE_NSS; |
| 8075 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8076 | if (rate[NL80211_RATE_INFO_HE_GI]) { |
| 8077 | switch (nla_get_u8(rate[NL80211_RATE_INFO_HE_GI])) { |
| 8078 | case NL80211_RATE_INFO_HE_GI_0_8: |
| 8079 | data->tx_guard_interval = GUARD_INTERVAL_0_8; |
| 8080 | break; |
| 8081 | case NL80211_RATE_INFO_HE_GI_1_6: |
| 8082 | data->tx_guard_interval = GUARD_INTERVAL_1_6; |
| 8083 | break; |
| 8084 | case NL80211_RATE_INFO_HE_GI_3_2: |
| 8085 | data->tx_guard_interval = GUARD_INTERVAL_3_2; |
| 8086 | break; |
| 8087 | } |
| 8088 | data->flags |= STA_DRV_DATA_TX_HE_GI; |
| 8089 | } |
| 8090 | if (rate[NL80211_RATE_INFO_HE_DCM]) { |
| 8091 | data->tx_dcm = |
| 8092 | nla_get_u8(rate[NL80211_RATE_INFO_HE_DCM]); |
| 8093 | data->flags |= STA_DRV_DATA_TX_HE_DCM; |
| 8094 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8095 | } |
| 8096 | |
| 8097 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 8098 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 8099 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 8100 | rate_policy) == 0) { |
| 8101 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 8102 | data->current_rx_rate = |
| 8103 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 8104 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 8105 | data->current_rx_rate = |
| 8106 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 8107 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8108 | /* Convert from 100 kbps to kbps; it's a more convenient unit. |
| 8109 | * It's also safe up until ~1Tbps. */ |
| 8110 | data->current_rx_rate = data->current_rx_rate * 100; |
| 8111 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8112 | if (rate[NL80211_RATE_INFO_MCS]) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8113 | data->rx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8114 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 8115 | } |
| 8116 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 8117 | data->rx_vhtmcs = |
| 8118 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 8119 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 8120 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8121 | if (rate[NL80211_RATE_INFO_SHORT_GI]) { |
| 8122 | data->rx_guard_interval = GUARD_INTERVAL_0_4; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8123 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8124 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8125 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 8126 | data->rx_vht_nss = |
| 8127 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 8128 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 8129 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8130 | if (rate[NL80211_RATE_INFO_HE_MCS]) { |
| 8131 | data->rx_hemcs = |
| 8132 | nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]); |
| 8133 | data->flags |= STA_DRV_DATA_RX_HE_MCS; |
| 8134 | } |
| 8135 | if (rate[NL80211_RATE_INFO_HE_NSS]) { |
| 8136 | data->rx_he_nss = |
| 8137 | nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]); |
| 8138 | data->flags |= STA_DRV_DATA_RX_HE_NSS; |
| 8139 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8140 | if (rate[NL80211_RATE_INFO_HE_GI]) { |
| 8141 | switch (nla_get_u8(rate[NL80211_RATE_INFO_HE_GI])) { |
| 8142 | case NL80211_RATE_INFO_HE_GI_0_8: |
| 8143 | data->rx_guard_interval = GUARD_INTERVAL_0_8; |
| 8144 | break; |
| 8145 | case NL80211_RATE_INFO_HE_GI_1_6: |
| 8146 | data->rx_guard_interval = GUARD_INTERVAL_1_6; |
| 8147 | break; |
| 8148 | case NL80211_RATE_INFO_HE_GI_3_2: |
| 8149 | data->rx_guard_interval = GUARD_INTERVAL_3_2; |
| 8150 | break; |
| 8151 | } |
| 8152 | data->flags |= STA_DRV_DATA_RX_HE_GI; |
| 8153 | } |
| 8154 | if (rate[NL80211_RATE_INFO_HE_DCM]) { |
| 8155 | data->rx_dcm = |
| 8156 | nla_get_u8(rate[NL80211_RATE_INFO_HE_DCM]); |
| 8157 | data->flags |= STA_DRV_DATA_RX_HE_DCM; |
| 8158 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8159 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8160 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8161 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 8162 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 8163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8164 | return NL_SKIP; |
| 8165 | } |
| 8166 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8167 | |
| 8168 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 8169 | const u8 *bssid, |
| 8170 | struct hostap_sta_driver_data *data) |
| 8171 | { |
| 8172 | struct nl_msg *msg; |
| 8173 | |
| 8174 | data->signal = -WPA_INVALID_NOISE; |
| 8175 | data->current_tx_rate = 0; |
| 8176 | |
| 8177 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 8178 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) { |
| 8179 | nlmsg_free(msg); |
| 8180 | return -ENOBUFS; |
| 8181 | } |
| 8182 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8183 | return send_and_recv_resp(drv, msg, get_sta_handler, data); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8184 | } |
| 8185 | |
| 8186 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8187 | static int i802_read_sta_data(struct i802_bss *bss, |
| 8188 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8189 | const u8 *addr) |
| 8190 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8191 | struct nl_msg *msg; |
| 8192 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8193 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 8194 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8195 | nlmsg_free(msg); |
| 8196 | return -ENOBUFS; |
| 8197 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8198 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8199 | return send_and_recv_resp(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8200 | } |
| 8201 | |
| 8202 | |
| 8203 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8204 | int cw_min, int cw_max, int burst_time, |
| 8205 | int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8206 | { |
| 8207 | struct i802_bss *bss = priv; |
| 8208 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8209 | struct nl_msg *msg; |
| 8210 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8211 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8212 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8213 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8214 | if (!msg) |
| 8215 | return -1; |
| 8216 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8217 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 8218 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8219 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8220 | |
| 8221 | /* We are only sending parameters for a single TXQ at a time */ |
| 8222 | params = nla_nest_start(msg, 1); |
| 8223 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8224 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8225 | |
| 8226 | switch (queue) { |
| 8227 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8228 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 8229 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8230 | break; |
| 8231 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8232 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 8233 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8234 | break; |
| 8235 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8236 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 8237 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8238 | break; |
| 8239 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8240 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 8241 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8242 | break; |
| 8243 | } |
| 8244 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 8245 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8246 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 8247 | (burst_time * 100 + 16) / 32) || |
| 8248 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 8249 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 8250 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 8251 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8252 | |
| 8253 | nla_nest_end(msg, params); |
| 8254 | |
| 8255 | nla_nest_end(msg, txq); |
| 8256 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8257 | if (link_id != NL80211_DRV_LINK_ID_NA && |
| 8258 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 8259 | goto fail; |
| 8260 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8261 | res = send_and_recv_cmd(drv, msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8262 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8263 | "nl80211: link=%d: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 8264 | link_id, queue, aifs, cw_min, cw_max, burst_time, res); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8265 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8266 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8267 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8268 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8269 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8270 | return -1; |
| 8271 | } |
| 8272 | |
| 8273 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8274 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8275 | const char *ifname, int vlan_id, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8276 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8277 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8278 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8279 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8280 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8281 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 8282 | ", ifname=%s[%d], vlan_id=%d)", |
| 8283 | bss->ifname, if_nametoindex(bss->ifname), |
| 8284 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8285 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 8286 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8287 | (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8288 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8289 | (link_id != NL80211_DRV_LINK_ID_NA && |
| 8290 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8291 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 8292 | nlmsg_free(msg); |
| 8293 | return -ENOBUFS; |
| 8294 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8295 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8296 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8297 | if (ret < 0) { |
| 8298 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 8299 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 8300 | MAC2STR(addr), ifname, vlan_id, ret, |
| 8301 | strerror(-ret)); |
| 8302 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8303 | return ret; |
| 8304 | } |
| 8305 | |
| 8306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8307 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 8308 | { |
| 8309 | struct hostap_sta_driver_data data; |
| 8310 | int ret; |
| 8311 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8312 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8313 | data.inactive_msec = (unsigned long) -1; |
| 8314 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8315 | if (ret == -ENOENT) |
| 8316 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8317 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 8318 | return -1; |
| 8319 | return data.inactive_msec / 1000; |
| 8320 | } |
| 8321 | |
| 8322 | |
| 8323 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 8324 | { |
| 8325 | #if 0 |
| 8326 | /* TODO */ |
| 8327 | #endif |
| 8328 | return 0; |
| 8329 | } |
| 8330 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8331 | |
| 8332 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8333 | u16 reason, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8334 | { |
| 8335 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8336 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8337 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8338 | u8 channel; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8339 | struct i802_link *link = nl80211_get_link(bss, link_id); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8340 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8341 | if (ieee80211_freq_to_chan(link->freq, &channel) == |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8342 | HOSTAPD_MODE_IEEE80211AD) { |
| 8343 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 8344 | * disassociate the STA instead. */ |
| 8345 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 8346 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8347 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8348 | if (is_mesh_interface(drv->nlmode)) |
| 8349 | return -1; |
| 8350 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8351 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8352 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8354 | memset(&mgmt, 0, sizeof(mgmt)); |
| 8355 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 8356 | WLAN_FC_STYPE_DEAUTH); |
| 8357 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 8358 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 8359 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 8360 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 8361 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 8362 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8363 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 8364 | 0, NULL, 0, 0, link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8365 | } |
| 8366 | |
| 8367 | |
| 8368 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8369 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8370 | { |
| 8371 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8372 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8373 | struct ieee80211_mgmt mgmt; |
| 8374 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8375 | if (is_mesh_interface(drv->nlmode)) |
| 8376 | return -1; |
| 8377 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8378 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8379 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8381 | memset(&mgmt, 0, sizeof(mgmt)); |
| 8382 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 8383 | WLAN_FC_STYPE_DISASSOC); |
| 8384 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 8385 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 8386 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 8387 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 8388 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 8389 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8390 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8391 | 0, NULL, 0, 0, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8392 | } |
| 8393 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8394 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8395 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 8396 | { |
| 8397 | char buf[200], *pos, *end; |
| 8398 | int i, res; |
| 8399 | |
| 8400 | pos = buf; |
| 8401 | end = pos + sizeof(buf); |
| 8402 | |
| 8403 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8404 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8405 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8406 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8407 | drv->if_indices[i].ifindex, |
| 8408 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8409 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8410 | break; |
| 8411 | pos += res; |
| 8412 | } |
| 8413 | *pos = '\0'; |
| 8414 | |
| 8415 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 8416 | drv->num_if_indices, buf); |
| 8417 | } |
| 8418 | |
| 8419 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8420 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 8421 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8422 | { |
| 8423 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8424 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8425 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8426 | wpa_printf(MSG_DEBUG, |
| 8427 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 8428 | ifidx, ifidx_reason); |
| 8429 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8430 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 8431 | ifidx); |
| 8432 | return; |
| 8433 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8434 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8435 | if (drv->if_indices[i].ifindex == 0) { |
| 8436 | drv->if_indices[i].ifindex = ifidx; |
| 8437 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8438 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8439 | return; |
| 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | if (drv->if_indices != drv->default_if_indices) |
| 8444 | old = drv->if_indices; |
| 8445 | else |
| 8446 | old = NULL; |
| 8447 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8448 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8449 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8450 | if (!drv->if_indices) { |
| 8451 | if (!old) |
| 8452 | drv->if_indices = drv->default_if_indices; |
| 8453 | else |
| 8454 | drv->if_indices = old; |
| 8455 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 8456 | "interfaces"); |
| 8457 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 8458 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8459 | } |
| 8460 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8461 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 8462 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8463 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 8464 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8465 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8466 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8467 | } |
| 8468 | |
| 8469 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8470 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 8471 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8472 | { |
| 8473 | int i; |
| 8474 | |
| 8475 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8476 | if ((drv->if_indices[i].ifindex == ifidx || |
| 8477 | ifidx == IFIDX_ANY) && |
| 8478 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8479 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8480 | drv->if_indices[i].ifindex = 0; |
| 8481 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8482 | break; |
| 8483 | } |
| 8484 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8485 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8486 | } |
| 8487 | |
| 8488 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8489 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 8490 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8491 | { |
| 8492 | int i; |
| 8493 | |
| 8494 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8495 | if (drv->if_indices[i].ifindex == ifidx && |
| 8496 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8497 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8498 | return 1; |
| 8499 | |
| 8500 | return 0; |
| 8501 | } |
| 8502 | |
| 8503 | |
| 8504 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8505 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8506 | { |
| 8507 | struct i802_bss *bss = priv; |
| 8508 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8509 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8510 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8511 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8512 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8513 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 8514 | if (ret >= (int) sizeof(name)) |
| 8515 | wpa_printf(MSG_WARNING, |
| 8516 | "nl80211: WDS interface name was truncated"); |
| 8517 | else if (ret < 0) |
| 8518 | return ret; |
| 8519 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8520 | if (ifname_wds) |
| 8521 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 8522 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8523 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 8524 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 8525 | if (val) { |
| 8526 | if (!if_nametoindex(name)) { |
| 8527 | if (nl80211_create_iface(drv, name, |
| 8528 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8529 | bss->addr, 1, NULL, NULL, 0) < |
| 8530 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8531 | return -1; |
| 8532 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8533 | linux_br_add_if(drv->global->ioctl_sock, |
| 8534 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8535 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8536 | |
| 8537 | os_memset(&event, 0, sizeof(event)); |
| 8538 | event.wds_sta_interface.sta_addr = addr; |
| 8539 | event.wds_sta_interface.ifname = name; |
| 8540 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 8541 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8542 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 8543 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8544 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8545 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 8546 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 8547 | "interface %s up", name); |
| 8548 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8549 | return i802_set_sta_vlan(priv, addr, name, 0, |
| 8550 | NL80211_DRV_LINK_ID_NA); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8551 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8552 | if (bridge_ifname && |
| 8553 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 8554 | name) < 0) |
| 8555 | wpa_printf(MSG_INFO, |
| 8556 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 8557 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8558 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 8559 | i802_set_sta_vlan(priv, addr, bss->ifname, 0, |
| 8560 | NL80211_DRV_LINK_ID_NA); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8561 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8562 | os_memset(&event, 0, sizeof(event)); |
| 8563 | event.wds_sta_interface.sta_addr = addr; |
| 8564 | event.wds_sta_interface.ifname = name; |
| 8565 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 8566 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8567 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8568 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8569 | } |
| 8570 | } |
| 8571 | |
| 8572 | |
| 8573 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 8574 | { |
| 8575 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 8576 | struct sockaddr_ll lladdr; |
| 8577 | unsigned char buf[3000]; |
| 8578 | int len; |
| 8579 | socklen_t fromlen = sizeof(lladdr); |
| 8580 | |
| 8581 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 8582 | (struct sockaddr *)&lladdr, &fromlen); |
| 8583 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8584 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 8585 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8586 | return; |
| 8587 | } |
| 8588 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8589 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8590 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 8591 | } |
| 8592 | |
| 8593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8594 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 8595 | struct i802_bss *bss, |
| 8596 | const char *brname, const char *ifname) |
| 8597 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8598 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8599 | char in_br[IFNAMSIZ]; |
| 8600 | |
| 8601 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8602 | br_ifindex = if_nametoindex(brname); |
| 8603 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8604 | /* |
| 8605 | * Bridge was configured, but the bridge device does |
| 8606 | * not exist. Try to add it now. |
| 8607 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8608 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8609 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 8610 | "bridge interface %s: %s", |
| 8611 | brname, strerror(errno)); |
| 8612 | return -1; |
| 8613 | } |
| 8614 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8615 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8616 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8617 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8618 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8619 | |
| 8620 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8621 | if (os_strcmp(in_br, brname) == 0) { |
| 8622 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8623 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8624 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8625 | |
| 8626 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 8627 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8628 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 8629 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8630 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 8631 | "remove interface %s from bridge " |
| 8632 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8633 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8634 | return -1; |
| 8635 | } |
| 8636 | } |
| 8637 | |
| 8638 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 8639 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8640 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8641 | wpa_printf(MSG_WARNING, |
| 8642 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8643 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8644 | /* Try to continue without the interface being in a bridge. This |
| 8645 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 8646 | * an external component will need to handle bridge |
| 8647 | * configuration. */ |
| 8648 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8649 | } |
| 8650 | bss->added_if_into_bridge = 1; |
| 8651 | |
| 8652 | return 0; |
| 8653 | } |
| 8654 | |
| 8655 | |
| 8656 | static void *i802_init(struct hostapd_data *hapd, |
| 8657 | struct wpa_init_params *params) |
| 8658 | { |
| 8659 | struct wpa_driver_nl80211_data *drv; |
| 8660 | struct i802_bss *bss; |
| 8661 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8662 | char master_ifname[IFNAMSIZ]; |
| 8663 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8664 | int br_added = 0; |
| 8665 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8666 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 8667 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8668 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8669 | if (bss == NULL) |
| 8670 | return NULL; |
| 8671 | |
| 8672 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8673 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8674 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8675 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8676 | params->ifname, master_ifname); |
| 8677 | br_ifindex = if_nametoindex(master_ifname); |
| 8678 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 8679 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 8680 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 8681 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 8682 | params->ifname, master_ifname); |
| 8683 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8684 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 8685 | |
| 8686 | /* check if master itself is under bridge */ |
| 8687 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 8688 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 8689 | master_ifname); |
| 8690 | br_ifindex = if_nametoindex(master_ifname); |
| 8691 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 8692 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8693 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8694 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8695 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8696 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8697 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8698 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8699 | for (i = 0; i < params->num_bridge; i++) { |
| 8700 | if (params->bridge[i]) { |
| 8701 | ifindex = if_nametoindex(params->bridge[i]); |
| 8702 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8703 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8704 | if (ifindex == br_ifindex) |
| 8705 | br_added = 1; |
| 8706 | } |
| 8707 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8708 | |
| 8709 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8710 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8711 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8712 | if (params->num_bridge && params->bridge[0]) { |
| 8713 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 8714 | params->ifname) < 0) |
| 8715 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8716 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8717 | br_added = 1; |
| 8718 | } |
| 8719 | |
| 8720 | if (!br_added && br_ifindex && |
| 8721 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8722 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8723 | |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8724 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8725 | int err; |
| 8726 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8727 | drv->rtnl_sk = nl_socket_alloc(); |
| 8728 | if (drv->rtnl_sk == NULL) { |
| 8729 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 8730 | goto failed; |
| 8731 | } |
| 8732 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8733 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 8734 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8735 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8736 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8737 | goto failed; |
| 8738 | } |
| 8739 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8740 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8741 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |
| 8742 | wpa_printf(MSG_DEBUG, |
| 8743 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); |
| 8744 | goto skip_eapol_sock; |
| 8745 | } |
| 8746 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8747 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 8748 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8749 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 8750 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8751 | goto failed; |
| 8752 | } |
| 8753 | |
| 8754 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 8755 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8756 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8757 | goto failed; |
| 8758 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8759 | skip_eapol_sock: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8760 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8761 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8762 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8763 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8764 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8765 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8766 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 8767 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8768 | return bss; |
| 8769 | |
| 8770 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8771 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8772 | return NULL; |
| 8773 | } |
| 8774 | |
| 8775 | |
| 8776 | static void i802_deinit(void *priv) |
| 8777 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8778 | struct i802_bss *bss = priv; |
| 8779 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8780 | } |
| 8781 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8782 | |
| 8783 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 8784 | enum wpa_driver_if_type type) |
| 8785 | { |
| 8786 | switch (type) { |
| 8787 | case WPA_IF_STATION: |
| 8788 | return NL80211_IFTYPE_STATION; |
| 8789 | case WPA_IF_P2P_CLIENT: |
| 8790 | case WPA_IF_P2P_GROUP: |
| 8791 | return NL80211_IFTYPE_P2P_CLIENT; |
| 8792 | case WPA_IF_AP_VLAN: |
| 8793 | return NL80211_IFTYPE_AP_VLAN; |
| 8794 | case WPA_IF_AP_BSS: |
| 8795 | return NL80211_IFTYPE_AP; |
| 8796 | case WPA_IF_P2P_GO: |
| 8797 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8798 | case WPA_IF_P2P_DEVICE: |
| 8799 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8800 | case WPA_IF_MESH: |
| 8801 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8802 | default: |
| 8803 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8804 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8808 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 8809 | { |
| 8810 | struct wpa_driver_nl80211_data *drv; |
| 8811 | dl_list_for_each(drv, &global->interfaces, |
| 8812 | struct wpa_driver_nl80211_data, list) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8813 | if (ether_addr_equal(addr, drv->first_bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8814 | return 1; |
| 8815 | } |
| 8816 | return 0; |
| 8817 | } |
| 8818 | |
| 8819 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8820 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8821 | { |
| 8822 | unsigned int idx; |
| 8823 | |
| 8824 | if (!drv->global) |
| 8825 | return -1; |
| 8826 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8827 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8828 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8829 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8830 | new_addr[0] ^= idx << 2; |
| 8831 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 8832 | break; |
| 8833 | } |
| 8834 | if (idx == 64) |
| 8835 | return -1; |
| 8836 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8837 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8838 | MACSTR, MAC2STR(new_addr)); |
| 8839 | |
| 8840 | return 0; |
| 8841 | } |
| 8842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8843 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8844 | struct wdev_info { |
| 8845 | u64 wdev_id; |
| 8846 | int wdev_id_set; |
| 8847 | u8 macaddr[ETH_ALEN]; |
| 8848 | }; |
| 8849 | |
| 8850 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 8851 | { |
| 8852 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8853 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8854 | struct wdev_info *wi = arg; |
| 8855 | |
| 8856 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8857 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8858 | if (tb[NL80211_ATTR_WDEV]) { |
| 8859 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 8860 | wi->wdev_id_set = 1; |
| 8861 | } |
| 8862 | |
| 8863 | if (tb[NL80211_ATTR_MAC]) |
| 8864 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 8865 | ETH_ALEN); |
| 8866 | |
| 8867 | return NL_SKIP; |
| 8868 | } |
| 8869 | |
| 8870 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8871 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 8872 | const char *ifname, const u8 *addr, |
| 8873 | void *bss_ctx, void **drv_priv, |
| 8874 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8875 | const char *bridge, int use_existing, |
| 8876 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8877 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8878 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8879 | struct i802_bss *bss = priv; |
| 8880 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8881 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8882 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8883 | |
| 8884 | if (addr) |
| 8885 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8886 | nlmode = wpa_driver_nl80211_if_type(type); |
| 8887 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 8888 | struct wdev_info p2pdev_info; |
| 8889 | |
| 8890 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 8891 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 8892 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8893 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8894 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 8895 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 8896 | ifname); |
| 8897 | return -1; |
| 8898 | } |
| 8899 | |
| 8900 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 8901 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8902 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8903 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8904 | os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 8905 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8906 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 8907 | ifname, |
| 8908 | (long long unsigned int) p2pdev_info.wdev_id); |
| 8909 | } else { |
| 8910 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8911 | 0, NULL, NULL, use_existing); |
| 8912 | if (use_existing && ifidx == -ENFILE) { |
| 8913 | added = 0; |
| 8914 | ifidx = if_nametoindex(ifname); |
| 8915 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8916 | return -1; |
| 8917 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8918 | } |
| 8919 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8920 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8921 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8922 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 8923 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8924 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8925 | if (added) |
| 8926 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8927 | return -1; |
| 8928 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8929 | } |
| 8930 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8931 | if (!addr && |
| 8932 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8933 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8934 | type == WPA_IF_STATION || type == WPA_IF_AP_BSS)) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8935 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8936 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8937 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8938 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8939 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8940 | if (added) |
| 8941 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8942 | return -1; |
| 8943 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8944 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8945 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8946 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8947 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8948 | if (added) |
| 8949 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8950 | return -1; |
| 8951 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8952 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8953 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8954 | if (added) |
| 8955 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8956 | return -1; |
| 8957 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8958 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8959 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8960 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8961 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8962 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8963 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8964 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8965 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8966 | if (added) |
| 8967 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8968 | return -1; |
| 8969 | } |
| 8970 | |
| 8971 | if (bridge && |
| 8972 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 8973 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 8974 | "interface %s to a bridge %s", |
| 8975 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8976 | if (added) |
| 8977 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8978 | os_free(new_bss); |
| 8979 | return -1; |
| 8980 | } |
| 8981 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8982 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 8983 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8984 | if (added) |
| 8985 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8986 | os_free(new_bss); |
| 8987 | return -1; |
| 8988 | } |
| 8989 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8990 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8991 | new_bss->ifindex = ifidx; |
| 8992 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8993 | new_bss->next = drv->first_bss->next; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8994 | new_bss->flink = &new_bss->links[0]; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8995 | new_bss->valid_links = 0; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8996 | os_memcpy(new_bss->flink->addr, new_bss->addr, ETH_ALEN); |
| 8997 | |
| 8998 | new_bss->flink->freq = drv->first_bss->flink->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8999 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9000 | new_bss->added_if = added; |
| 9001 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9002 | if (drv_priv) |
| 9003 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9004 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9005 | |
| 9006 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 9007 | if (nl80211_setup_ap(new_bss)) |
| 9008 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9009 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9010 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9011 | if (drv->global) |
| 9012 | drv->global->if_add_ifindex = ifidx; |
| 9013 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9014 | /* |
| 9015 | * Some virtual interfaces need to process EAPOL packets and events on |
| 9016 | * the parent interface. This is used mainly with hostapd. |
| 9017 | */ |
| 9018 | if (ifidx > 0 && |
| 9019 | (drv->hostapd || |
| 9020 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 9021 | nlmode == NL80211_IFTYPE_WDS || |
| 9022 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9023 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 9024 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9025 | return 0; |
| 9026 | } |
| 9027 | |
| 9028 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9029 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9030 | enum wpa_driver_if_type type, |
| 9031 | const char *ifname) |
| 9032 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9033 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9034 | int ifindex = if_nametoindex(ifname); |
| 9035 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9036 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 9037 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 9038 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9039 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 9040 | else if (ifindex > 0 && !bss->added_if) { |
| 9041 | struct wpa_driver_nl80211_data *drv2; |
| 9042 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9043 | struct wpa_driver_nl80211_data, list) { |
| 9044 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 9045 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 9046 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 9047 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9048 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9049 | if (type != WPA_IF_AP_BSS) |
| 9050 | return 0; |
| 9051 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9052 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9053 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 9054 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9055 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9056 | "interface %s from bridge %s: %s", |
| 9057 | bss->ifname, bss->brname, strerror(errno)); |
| 9058 | } |
| 9059 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9060 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9061 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9062 | "bridge %s: %s", |
| 9063 | bss->brname, strerror(errno)); |
| 9064 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9065 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9066 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9067 | struct i802_bss *tbss; |
| 9068 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9069 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 9070 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9071 | if (tbss->next == bss) { |
| 9072 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9073 | /* Unsubscribe management frames */ |
| 9074 | nl80211_teardown_ap(bss); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9075 | nl80211_remove_links(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9076 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 9077 | if (!bss->added_if) |
| 9078 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9079 | os_free(bss); |
| 9080 | bss = NULL; |
| 9081 | break; |
| 9082 | } |
| 9083 | } |
| 9084 | if (bss) |
| 9085 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 9086 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9087 | } else { |
| 9088 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 9089 | nl80211_teardown_ap(bss); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9090 | nl80211_remove_links(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9091 | if (!bss->added_if && !drv->first_bss->next) |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9092 | wpa_driver_nl80211_del_beacon_all(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9093 | nl80211_destroy_bss(bss); |
| 9094 | if (!bss->added_if) |
| 9095 | i802_set_iface_flags(bss, 0); |
| 9096 | if (drv->first_bss->next) { |
| 9097 | drv->first_bss = drv->first_bss->next; |
| 9098 | drv->ctx = drv->first_bss->ctx; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9099 | drv->ifindex = drv->first_bss->ifindex; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9100 | os_free(bss); |
| 9101 | } else { |
| 9102 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 9103 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9104 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9105 | |
| 9106 | return 0; |
| 9107 | } |
| 9108 | |
| 9109 | |
| 9110 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 9111 | { |
| 9112 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9113 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9114 | u64 *cookie = arg; |
| 9115 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9116 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9117 | if (tb[NL80211_ATTR_COOKIE]) |
| 9118 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 9119 | return NL_SKIP; |
| 9120 | } |
| 9121 | |
| 9122 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9123 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9124 | unsigned int freq, unsigned int wait, |
| 9125 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9126 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9127 | int offchanok, const u16 *csa_offs, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9128 | size_t csa_offs_len, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9129 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9130 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9131 | struct nl_msg *msg; |
| 9132 | u64 cookie; |
| 9133 | int ret = -1; |
| 9134 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9135 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9136 | "no_ack=%d offchanok=%d", |
| 9137 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9138 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9139 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9140 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9141 | ((link_id != NL80211_DRV_LINK_ID_NA) && |
| 9142 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9143 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9144 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 9145 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 9146 | drv->test_use_roc_tx) && |
| 9147 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 9148 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 9149 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9150 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 9151 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9152 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 9153 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9154 | |
| 9155 | cookie = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9156 | ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9157 | msg = NULL; |
| 9158 | if (ret) { |
| 9159 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9160 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 9161 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9162 | } else { |
| 9163 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 9164 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 9165 | (long long unsigned int) cookie); |
| 9166 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9167 | if (save_cookie) |
| 9168 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9169 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 9170 | if (!wait) { |
| 9171 | /* There is no need to store this cookie since there |
| 9172 | * is no wait that could be canceled later. */ |
| 9173 | goto fail; |
| 9174 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9175 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9176 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9177 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9178 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9179 | drv->send_frame_cookies[0]); |
| 9180 | os_memmove(&drv->send_frame_cookies[0], |
| 9181 | &drv->send_frame_cookies[1], |
| 9182 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9183 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9184 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9185 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9186 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 9187 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9189 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9190 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9191 | nlmsg_free(msg); |
| 9192 | return ret; |
| 9193 | } |
| 9194 | |
| 9195 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9196 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 9197 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9198 | unsigned int wait_time, |
| 9199 | const u8 *dst, const u8 *src, |
| 9200 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9201 | const u8 *data, size_t data_len, |
| 9202 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9203 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9204 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9205 | int ret = -1; |
| 9206 | u8 *buf; |
| 9207 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9208 | int offchanok = 1; |
| 9209 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9210 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->flink->freq && |
| 9211 | bss->flink->beacon_set) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9212 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9213 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9214 | if (!freq && is_sta_interface(drv->nlmode)) |
| 9215 | offchanok = 0; |
| 9216 | |
| 9217 | wpa_printf(MSG_DEBUG, |
| 9218 | "nl80211: Send Action frame (ifindex=%d, freq=%u MHz wait=%d ms no_cck=%d offchanok=%d dst=" |
| 9219 | MACSTR " src=" MACSTR " bssid=" MACSTR ")", |
| 9220 | drv->ifindex, freq, wait_time, no_cck, offchanok, |
| 9221 | MAC2STR(dst), MAC2STR(src), MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9222 | |
| 9223 | buf = os_zalloc(24 + data_len); |
| 9224 | if (buf == NULL) |
| 9225 | return ret; |
| 9226 | os_memcpy(buf + 24, data, data_len); |
| 9227 | hdr = (struct ieee80211_hdr *) buf; |
| 9228 | hdr->frame_control = |
| 9229 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 9230 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 9231 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 9232 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 9233 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9234 | if (!ether_addr_equal(bss->addr, src)) { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9235 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 9236 | MAC2STR(src)); |
| 9237 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 9238 | } else { |
| 9239 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 9240 | } |
| 9241 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9242 | #ifdef CONFIG_MESH |
| 9243 | if (is_mesh_interface(drv->nlmode)) { |
| 9244 | struct hostapd_hw_modes *modes; |
| 9245 | u16 num_modes, flags; |
| 9246 | u8 dfs_domain; |
| 9247 | int i; |
| 9248 | |
| 9249 | modes = nl80211_get_hw_feature_data(bss, &num_modes, |
| 9250 | &flags, &dfs_domain); |
| 9251 | if (dfs_domain != HOSTAPD_DFS_REGION_ETSI && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9252 | ieee80211_is_dfs(bss->flink->freq, modes, num_modes)) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9253 | offchanok = 0; |
| 9254 | if (modes) { |
| 9255 | for (i = 0; i < num_modes; i++) { |
| 9256 | os_free(modes[i].channels); |
| 9257 | os_free(modes[i].rates); |
| 9258 | } |
| 9259 | os_free(modes); |
| 9260 | } |
| 9261 | } |
| 9262 | #endif /* CONFIG_MESH */ |
| 9263 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9264 | if (is_ap_interface(drv->nlmode) && |
| 9265 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9266 | (int) freq == bss->flink->freq || drv->device_ap_sme || |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9267 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9268 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9269 | 0, freq, no_cck, offchanok, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 9270 | wait_time, NULL, 0, 0, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9271 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9272 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9273 | 24 + data_len, 1, no_cck, 0, |
| 9274 | offchanok, NULL, 0, |
| 9275 | NL80211_DRV_LINK_ID_NA); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9276 | |
| 9277 | os_free(buf); |
| 9278 | return ret; |
| 9279 | } |
| 9280 | |
| 9281 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9282 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9283 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9284 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9285 | struct nl_msg *msg; |
| 9286 | int ret; |
| 9287 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 9288 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9289 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9290 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9291 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9292 | nlmsg_free(msg); |
| 9293 | return; |
| 9294 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9295 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9296 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9297 | if (ret) |
| 9298 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 9299 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9300 | } |
| 9301 | |
| 9302 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9303 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 9304 | { |
| 9305 | struct i802_bss *bss = priv; |
| 9306 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9307 | unsigned int i; |
| 9308 | u64 cookie; |
| 9309 | |
| 9310 | /* Cancel the last pending TX cookie */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 9311 | if (drv->send_frame_cookie != (u64) -1) |
| 9312 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9313 | |
| 9314 | /* |
| 9315 | * Cancel the other pending TX cookies, if any. This is needed since |
| 9316 | * the driver may keep a list of all pending offchannel TX operations |
| 9317 | * and free up the radio only once they have expired or cancelled. |
| 9318 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9319 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 9320 | cookie = drv->send_frame_cookies[i - 1]; |
| 9321 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9322 | nl80211_frame_wait_cancel(bss, cookie); |
| 9323 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9324 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9325 | } |
| 9326 | |
| 9327 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9328 | static int nl80211_put_any_link_id(struct nl_msg *msg, |
| 9329 | struct driver_sta_mlo_info *mlo, |
| 9330 | int freq) |
| 9331 | { |
| 9332 | int i; |
| 9333 | int link_id = -1; |
| 9334 | int any_valid_link_id = -1; |
| 9335 | |
| 9336 | if (!mlo->valid_links) |
| 9337 | return 0; |
| 9338 | |
| 9339 | /* First try to pick a link that uses the same band */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9340 | for_each_link(mlo->valid_links, i) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9341 | if (any_valid_link_id == -1) |
| 9342 | any_valid_link_id = i; |
| 9343 | |
| 9344 | if (is_same_band(freq, mlo->links[i].freq)) { |
| 9345 | link_id = i; |
| 9346 | break; |
| 9347 | } |
| 9348 | } |
| 9349 | |
| 9350 | /* Use any valid link ID if no band match was found */ |
| 9351 | if (link_id == -1) |
| 9352 | link_id = any_valid_link_id; |
| 9353 | |
| 9354 | if (link_id == -1) { |
| 9355 | wpa_printf(MSG_INFO, |
| 9356 | "nl80211: No valid Link ID found for freq %u", freq); |
| 9357 | return 0; |
| 9358 | } |
| 9359 | |
| 9360 | wpa_printf(MSG_DEBUG, "nl80211: Add Link ID %d", link_id); |
| 9361 | return nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id); |
| 9362 | } |
| 9363 | |
| 9364 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9365 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 9366 | unsigned int duration) |
| 9367 | { |
| 9368 | struct i802_bss *bss = priv; |
| 9369 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9370 | struct nl_msg *msg; |
| 9371 | int ret; |
| 9372 | u64 cookie; |
| 9373 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9374 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 9375 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9376 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration) || |
| 9377 | nl80211_put_any_link_id(msg, &drv->sta_mlo_info, freq)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9378 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9379 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9380 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9381 | |
| 9382 | cookie = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9383 | ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9384 | if (ret == 0) { |
| 9385 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 9386 | "0x%llx for freq=%u MHz duration=%u", |
| 9387 | (long long unsigned int) cookie, freq, duration); |
| 9388 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9389 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9390 | return 0; |
| 9391 | } |
| 9392 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 9393 | "(freq=%d duration=%u): %d (%s)", |
| 9394 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9395 | return -1; |
| 9396 | } |
| 9397 | |
| 9398 | |
| 9399 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 9400 | { |
| 9401 | struct i802_bss *bss = priv; |
| 9402 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9403 | struct nl_msg *msg; |
| 9404 | int ret; |
| 9405 | |
| 9406 | if (!drv->pending_remain_on_chan) { |
| 9407 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 9408 | "to cancel"); |
| 9409 | return -1; |
| 9410 | } |
| 9411 | |
| 9412 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 9413 | "0x%llx", |
| 9414 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 9415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9416 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 9417 | if (!msg || |
| 9418 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 9419 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9420 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9421 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9422 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9423 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9424 | if (ret == 0) |
| 9425 | return 0; |
| 9426 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 9427 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9428 | return -1; |
| 9429 | } |
| 9430 | |
| 9431 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9432 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9433 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9434 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9435 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9436 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9437 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 9438 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 9439 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9440 | /* |
| 9441 | * Do not disable Probe Request reporting that was |
| 9442 | * enabled in nl80211_setup_ap(). |
| 9443 | */ |
| 9444 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 9445 | "Probe Request reporting nl_preq=%p while " |
| 9446 | "in AP mode", bss->nl_preq); |
| 9447 | } else if (bss->nl_preq) { |
| 9448 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 9449 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9450 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9451 | } |
| 9452 | return 0; |
| 9453 | } |
| 9454 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9455 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9456 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9457 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9458 | return 0; |
| 9459 | } |
| 9460 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9461 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 9462 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9463 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9464 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 9465 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9466 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9467 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9468 | (WLAN_FC_TYPE_MGMT << 2) | |
| 9469 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 9470 | NULL, 0, false) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9471 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 9472 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9473 | nl80211_register_eloop_read(&bss->nl_preq, |
| 9474 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9475 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9476 | |
| 9477 | return 0; |
| 9478 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9479 | out_err: |
| 9480 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9481 | return -1; |
| 9482 | } |
| 9483 | |
| 9484 | |
| 9485 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 9486 | int ifindex, int disabled) |
| 9487 | { |
| 9488 | struct nl_msg *msg; |
| 9489 | struct nlattr *bands, *band; |
| 9490 | int ret; |
| 9491 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9492 | wpa_printf(MSG_DEBUG, |
| 9493 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 9494 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 9495 | "no NL80211_TXRATE_LEGACY constraint"); |
| 9496 | |
| 9497 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 9498 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9499 | if (!msg) |
| 9500 | return -1; |
| 9501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9502 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 9503 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9504 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9505 | |
| 9506 | /* |
| 9507 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 9508 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 9509 | * rates. All 5 GHz rates are left enabled. |
| 9510 | */ |
| 9511 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9512 | if (!band || |
| 9513 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 9514 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 9515 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9516 | nla_nest_end(msg, band); |
| 9517 | |
| 9518 | nla_nest_end(msg, bands); |
| 9519 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9520 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9521 | if (ret) { |
| 9522 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 9523 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9524 | } else |
| 9525 | drv->disabled_11b_rates = disabled; |
| 9526 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9527 | return ret; |
| 9528 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9529 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9530 | nlmsg_free(msg); |
| 9531 | return -1; |
| 9532 | } |
| 9533 | |
| 9534 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9535 | static int nl80211_remove_link(struct i802_bss *bss, int link_id) |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame] | 9536 | { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 9537 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9538 | struct i802_link *link; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 9539 | struct nl_msg *msg; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9540 | size_t i; |
| 9541 | int ret; |
| 9542 | |
| 9543 | wpa_printf(MSG_DEBUG, "nl80211: Remove link (ifindex=%d link_id=%u)", |
| 9544 | bss->ifindex, link_id); |
| 9545 | |
| 9546 | if (!(bss->valid_links & BIT(link_id))) { |
| 9547 | wpa_printf(MSG_DEBUG, |
| 9548 | "nl80211: MLD: remove link: Link not found"); |
| 9549 | return -1; |
| 9550 | } |
| 9551 | |
| 9552 | link = &bss->links[link_id]; |
| 9553 | |
| 9554 | wpa_driver_nl80211_del_beacon(bss, link_id); |
| 9555 | |
| 9556 | /* First remove the link locally */ |
| 9557 | bss->valid_links &= ~BIT(link_id); |
| 9558 | os_memset(link->addr, 0, ETH_ALEN); |
| 9559 | |
| 9560 | /* Choose new deflink if we are removing that link */ |
| 9561 | if (bss->flink == link) { |
| 9562 | for_each_link_default(bss->valid_links, i, 0) { |
| 9563 | bss->flink = &bss->links[i]; |
| 9564 | break; |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | /* If this was the last link, reset default link */ |
| 9569 | if (!bss->valid_links) { |
| 9570 | /* TODO: Does keeping freq/bandwidth make sense? */ |
| 9571 | if (bss->flink != link) |
| 9572 | os_memcpy(bss->flink, link, sizeof(*link)); |
| 9573 | |
| 9574 | os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN); |
| 9575 | } |
| 9576 | |
| 9577 | /* Remove the link from the kernel */ |
| 9578 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_REMOVE_LINK); |
| 9579 | if (!msg || |
| 9580 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) { |
| 9581 | nlmsg_free(msg); |
| 9582 | wpa_printf(MSG_ERROR, |
| 9583 | "nl80211: remove link (%d) failed", link_id); |
| 9584 | return -1; |
| 9585 | } |
| 9586 | |
| 9587 | ret = send_and_recv_cmd(drv, msg); |
| 9588 | if (ret) |
| 9589 | wpa_printf(MSG_ERROR, |
| 9590 | "nl80211: remove link (%d) failed. ret=%d (%s)", |
| 9591 | link_id, ret, strerror(-ret)); |
| 9592 | |
| 9593 | return ret; |
| 9594 | } |
| 9595 | |
| 9596 | |
| 9597 | static void nl80211_remove_links(struct i802_bss *bss) |
| 9598 | { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9599 | int ret; |
| 9600 | u8 link_id; |
| 9601 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9602 | for_each_link(bss->valid_links, link_id) { |
| 9603 | ret = nl80211_remove_link(bss, link_id); |
| 9604 | if (ret) |
| 9605 | break; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 9606 | } |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9607 | |
| 9608 | if (bss->flink) |
| 9609 | os_memcpy(bss->flink->addr, bss->addr, ETH_ALEN); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9610 | } |
| 9611 | |
| 9612 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9613 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 9614 | { |
| 9615 | struct i802_bss *bss = priv; |
| 9616 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9617 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9618 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9619 | return -1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9620 | |
| 9621 | /* Stop beaconing */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9622 | wpa_driver_nl80211_del_beacon(bss, NL80211_DRV_LINK_ID_NA); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9623 | |
| 9624 | nl80211_remove_links(bss); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9625 | |
| 9626 | /* |
| 9627 | * If the P2P GO interface was dynamically added, then it is |
| 9628 | * possible that the interface change to station is not possible. |
| 9629 | */ |
| 9630 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 9631 | return 0; |
| 9632 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9633 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9634 | } |
| 9635 | |
| 9636 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9637 | static int wpa_driver_nl80211_stop_ap(void *priv, int link_id) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9638 | { |
| 9639 | struct i802_bss *bss = priv; |
| 9640 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9641 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9642 | if (!is_ap_interface(drv->nlmode)) |
| 9643 | return -1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9644 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9645 | if (link_id == -1) { |
| 9646 | wpa_driver_nl80211_del_beacon_all(bss); |
| 9647 | return 0; |
| 9648 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9649 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9650 | if (nl80211_link_valid(bss->valid_links, link_id)) { |
| 9651 | wpa_driver_nl80211_del_beacon(bss, link_id); |
| 9652 | return 0; |
| 9653 | } |
| 9654 | |
| 9655 | return -1; |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9656 | } |
| 9657 | |
| 9658 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9659 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 9660 | { |
| 9661 | struct i802_bss *bss = priv; |
| 9662 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9663 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 9664 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9665 | |
| 9666 | /* |
| 9667 | * If the P2P Client interface was dynamically added, then it is |
| 9668 | * possible that the interface change to station is not possible. |
| 9669 | */ |
| 9670 | if (bss->if_dynamic) |
| 9671 | return 0; |
| 9672 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9673 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 9674 | } |
| 9675 | |
| 9676 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9677 | static void wpa_driver_nl80211_resume(void *priv) |
| 9678 | { |
| 9679 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9680 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9681 | |
| 9682 | if (i802_set_iface_flags(bss, 1)) |
| 9683 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9684 | |
| 9685 | if (is_p2p_net_interface(nlmode)) |
| 9686 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9687 | } |
| 9688 | |
| 9689 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9690 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 9691 | { |
| 9692 | struct i802_bss *bss = priv; |
| 9693 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9694 | struct nl_msg *msg; |
| 9695 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9696 | |
| 9697 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 9698 | "hysteresis=%d", threshold, hysteresis); |
| 9699 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9700 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 9701 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 9702 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 9703 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 9704 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9705 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9706 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9707 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9708 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9709 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9710 | } |
| 9711 | |
| 9712 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9713 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 9714 | { |
| 9715 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9716 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9717 | struct wpa_signal_info *sig_change = arg; |
| 9718 | |
| 9719 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9720 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9721 | |
| 9722 | sig_change->center_frq1 = -1; |
| 9723 | sig_change->center_frq2 = -1; |
| 9724 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 9725 | |
| 9726 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 9727 | sig_change->chanwidth = convert2width( |
| 9728 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 9729 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 9730 | sig_change->center_frq1 = |
| 9731 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 9732 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 9733 | sig_change->center_frq2 = |
| 9734 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 9735 | } |
| 9736 | |
| 9737 | return NL_SKIP; |
| 9738 | } |
| 9739 | |
| 9740 | |
| 9741 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 9742 | struct wpa_signal_info *sig) |
| 9743 | { |
| 9744 | struct nl_msg *msg; |
| 9745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9746 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9747 | return send_and_recv_resp(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9748 | } |
| 9749 | |
| 9750 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9751 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 9752 | { |
| 9753 | struct i802_bss *bss = priv; |
| 9754 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9755 | int res; |
| 9756 | |
| 9757 | os_memset(si, 0, sizeof(*si)); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 9758 | res = nl80211_get_link_signal(drv, drv->bssid, &si->data); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9759 | if (res) { |
| 9760 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 9761 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 9762 | return res; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 9763 | si->data.signal = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9764 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9765 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9766 | res = nl80211_get_channel_width(drv, si); |
| 9767 | if (res != 0) |
| 9768 | return res; |
| 9769 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9770 | return nl80211_get_link_noise(drv, si); |
| 9771 | } |
| 9772 | |
| 9773 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9774 | static int get_links_noise(struct nl_msg *msg, void *arg) |
| 9775 | { |
| 9776 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9777 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9778 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 9779 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 9780 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 9781 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 9782 | }; |
| 9783 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 9784 | int i; |
| 9785 | |
| 9786 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9787 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9788 | |
| 9789 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 9790 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); |
| 9791 | return NL_SKIP; |
| 9792 | } |
| 9793 | |
| 9794 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 9795 | tb[NL80211_ATTR_SURVEY_INFO], |
| 9796 | survey_policy)) { |
| 9797 | wpa_printf(MSG_DEBUG, |
| 9798 | "nl80211: Failed to parse nested attributes"); |
| 9799 | return NL_SKIP; |
| 9800 | } |
| 9801 | |
| 9802 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 9803 | return NL_SKIP; |
| 9804 | |
| 9805 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 9806 | return NL_SKIP; |
| 9807 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9808 | for_each_link(mlo_sig->valid_links, i) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9809 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 9810 | mlo_sig->links[i].frequency) |
| 9811 | continue; |
| 9812 | |
| 9813 | mlo_sig->links[i].current_noise = |
| 9814 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 9815 | break; |
| 9816 | } |
| 9817 | |
| 9818 | return NL_SKIP; |
| 9819 | } |
| 9820 | |
| 9821 | |
| 9822 | static int nl80211_get_links_noise(struct wpa_driver_nl80211_data *drv, |
| 9823 | struct wpa_mlo_signal_info *mlo_sig) |
| 9824 | { |
| 9825 | struct nl_msg *msg; |
| 9826 | |
| 9827 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9828 | return send_and_recv_resp(drv, msg, get_links_noise, mlo_sig); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9829 | } |
| 9830 | |
| 9831 | |
| 9832 | static int get_links_channel_width(struct nl_msg *msg, void *arg) |
| 9833 | { |
| 9834 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9835 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9836 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 9837 | struct nlattr *link; |
| 9838 | int rem_links; |
| 9839 | |
| 9840 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9841 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9842 | |
| 9843 | if (!tb[NL80211_ATTR_MLO_LINKS]) |
| 9844 | return NL_SKIP; |
| 9845 | |
| 9846 | nla_for_each_nested(link, tb[NL80211_ATTR_MLO_LINKS], rem_links) { |
| 9847 | struct nlattr *tb2[NL80211_ATTR_MAX + 1]; |
| 9848 | int link_id; |
| 9849 | |
| 9850 | nla_parse(tb2, NL80211_ATTR_MAX, nla_data(link), nla_len(link), |
| 9851 | NULL); |
| 9852 | |
| 9853 | if (!tb2[NL80211_ATTR_MLO_LINK_ID]) |
| 9854 | continue; |
| 9855 | |
| 9856 | link_id = nla_get_u8(tb2[NL80211_ATTR_MLO_LINK_ID]); |
| 9857 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 9858 | continue; |
| 9859 | |
| 9860 | if (!tb2[NL80211_ATTR_CHANNEL_WIDTH]) |
| 9861 | continue; |
| 9862 | mlo_sig->links[link_id].chanwidth = convert2width( |
| 9863 | nla_get_u32(tb2[NL80211_ATTR_CHANNEL_WIDTH])); |
| 9864 | if (tb2[NL80211_ATTR_CENTER_FREQ1]) |
| 9865 | mlo_sig->links[link_id].center_frq1 = |
| 9866 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ1]); |
| 9867 | if (tb2[NL80211_ATTR_CENTER_FREQ2]) |
| 9868 | mlo_sig->links[link_id].center_frq2 = |
| 9869 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ2]); |
| 9870 | } |
| 9871 | |
| 9872 | return NL_SKIP; |
| 9873 | } |
| 9874 | |
| 9875 | |
| 9876 | static int nl80211_get_links_channel_width(struct wpa_driver_nl80211_data *drv, |
| 9877 | struct wpa_mlo_signal_info *mlo_sig) |
| 9878 | { |
| 9879 | struct nl_msg *msg; |
| 9880 | |
| 9881 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9882 | return send_and_recv_resp(drv, msg, get_links_channel_width, mlo_sig); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9883 | } |
| 9884 | |
| 9885 | |
| 9886 | static int nl80211_mlo_signal_poll(void *priv, |
| 9887 | struct wpa_mlo_signal_info *mlo_si) |
| 9888 | { |
| 9889 | struct i802_bss *bss = priv; |
| 9890 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9891 | int res; |
| 9892 | int i; |
| 9893 | |
| 9894 | if (drv->nlmode != NL80211_IFTYPE_STATION || |
| 9895 | !drv->sta_mlo_info.valid_links) |
| 9896 | return -1; |
| 9897 | |
| 9898 | os_memset(mlo_si, 0, sizeof(*mlo_si)); |
| 9899 | mlo_si->valid_links = drv->sta_mlo_info.valid_links; |
| 9900 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9901 | for_each_link(mlo_si->valid_links, i) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9902 | res = nl80211_get_link_signal(drv, |
| 9903 | drv->sta_mlo_info.links[i].bssid, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 9904 | &mlo_si->links[i].data); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9905 | if (res != 0) |
| 9906 | return res; |
| 9907 | |
| 9908 | mlo_si->links[i].center_frq1 = -1; |
| 9909 | mlo_si->links[i].center_frq2 = -1; |
| 9910 | mlo_si->links[i].chanwidth = CHAN_WIDTH_UNKNOWN; |
| 9911 | mlo_si->links[i].current_noise = WPA_INVALID_NOISE; |
| 9912 | mlo_si->links[i].frequency = drv->sta_mlo_info.links[i].freq; |
| 9913 | } |
| 9914 | |
| 9915 | res = nl80211_get_links_channel_width(drv, mlo_si); |
| 9916 | if (res != 0) |
| 9917 | return res; |
| 9918 | |
| 9919 | return nl80211_get_links_noise(drv, mlo_si); |
| 9920 | } |
| 9921 | |
| 9922 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9923 | static int nl80211_set_param(void *priv, const char *param) |
| 9924 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9925 | struct i802_bss *bss = priv; |
| 9926 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9927 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9928 | if (param == NULL) |
| 9929 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9930 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9931 | |
| 9932 | #ifdef CONFIG_P2P |
| 9933 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9934 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 9935 | "interface"); |
| 9936 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 9937 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 9938 | } |
| 9939 | #endif /* CONFIG_P2P */ |
| 9940 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9941 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9942 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9943 | |
| 9944 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9945 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9946 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9947 | } |
| 9948 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9949 | if (os_strstr(param, "force_bss_selection=1")) |
| 9950 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 9951 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9952 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9953 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 9954 | drv->test_use_roc_tx = 1; |
| 9955 | } |
| 9956 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9957 | if (os_strstr(param, "control_port=0")) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9958 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9959 | drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX | |
| 9960 | WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS); |
| 9961 | drv->control_port_ap = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9962 | } |
| 9963 | |
| 9964 | if (os_strstr(param, "control_port_ap=1")) |
| 9965 | drv->control_port_ap = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9966 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9967 | if (os_strstr(param, "control_port_ap=0")) { |
| 9968 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS; |
| 9969 | drv->control_port_ap = 0; |
| 9970 | } |
| 9971 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9972 | if (os_strstr(param, "full_ap_client_state=0")) |
| 9973 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 9974 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9975 | if (os_strstr(param, "no_rrm=1")) { |
| 9976 | drv->no_rrm = 1; |
| 9977 | |
| 9978 | if (!bss->in_deinit && !is_ap_interface(drv->nlmode) && |
| 9979 | !is_mesh_interface(drv->nlmode)) { |
| 9980 | nl80211_mgmt_unsubscribe(bss, "no_rrm=1"); |
| 9981 | if (nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 9982 | wpa_printf(MSG_DEBUG, |
| 9983 | "nl80211: Failed to re-register Action frame processing - ignore for now"); |
| 9984 | } |
| 9985 | } |
| 9986 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 9987 | if (os_strstr(param, "secure_ltf=1")) { |
| 9988 | drv->capa.flags2 |= WPA_DRIVER_FLAGS2_SEC_LTF_STA | |
| 9989 | WPA_DRIVER_FLAGS2_SEC_LTF_AP; |
| 9990 | } |
| 9991 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 9992 | if (os_strstr(param, "rsn_override_in_driver=1")) |
| 9993 | drv->capa.flags2 |= WPA_DRIVER_FLAGS2_RSN_OVERRIDE_STA; |
| 9994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9995 | return 0; |
| 9996 | } |
| 9997 | |
| 9998 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9999 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10000 | { |
| 10001 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10002 | struct netlink_config *cfg; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10003 | struct utsname name; |
| 10004 | |
| 10005 | if (uname(&name) == 0) { |
| 10006 | wpa_printf(MSG_DEBUG, "nl80211: Kernel version: %s %s (%s; %s)", |
| 10007 | name.sysname, name.release, |
| 10008 | name.version, name.machine); |
| 10009 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10011 | global = os_zalloc(sizeof(*global)); |
| 10012 | if (global == NULL) |
| 10013 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10014 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10015 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10016 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10017 | global->if_add_ifindex = -1; |
| 10018 | |
| 10019 | cfg = os_zalloc(sizeof(*cfg)); |
| 10020 | if (cfg == NULL) |
| 10021 | goto err; |
| 10022 | |
| 10023 | cfg->ctx = global; |
| 10024 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 10025 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 10026 | global->netlink = netlink_init(cfg); |
| 10027 | if (global->netlink == NULL) { |
| 10028 | os_free(cfg); |
| 10029 | goto err; |
| 10030 | } |
| 10031 | |
| 10032 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 10033 | goto err; |
| 10034 | |
| 10035 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 10036 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10037 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 10038 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10039 | goto err; |
| 10040 | } |
| 10041 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10042 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10043 | |
| 10044 | err: |
| 10045 | nl80211_global_deinit(global); |
| 10046 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10047 | } |
| 10048 | |
| 10049 | |
| 10050 | static void nl80211_global_deinit(void *priv) |
| 10051 | { |
| 10052 | struct nl80211_global *global = priv; |
| 10053 | if (global == NULL) |
| 10054 | return; |
| 10055 | if (!dl_list_empty(&global->interfaces)) { |
| 10056 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 10057 | "nl80211_global_deinit", |
| 10058 | dl_list_len(&global->interfaces)); |
| 10059 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10060 | |
| 10061 | if (global->netlink) |
| 10062 | netlink_deinit(global->netlink); |
| 10063 | |
| 10064 | nl_destroy_handles(&global->nl); |
| 10065 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10066 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10067 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10068 | |
| 10069 | nl_cb_put(global->nl_cb); |
| 10070 | |
| 10071 | if (global->ioctl_sock >= 0) |
| 10072 | close(global->ioctl_sock); |
| 10073 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10074 | os_free(global); |
| 10075 | } |
| 10076 | |
| 10077 | |
| 10078 | static const char * nl80211_get_radio_name(void *priv) |
| 10079 | { |
| 10080 | struct i802_bss *bss = priv; |
| 10081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10082 | return drv->phyname; |
| 10083 | } |
| 10084 | |
| 10085 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10086 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10087 | struct wpa_pmkid_params *params, bool skip_pmk) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10088 | { |
| 10089 | struct nl_msg *msg; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10090 | |
| 10091 | if (cmd == NL80211_CMD_SET_PMKSA) |
| 10092 | wpa_printf(MSG_DEBUG, |
| 10093 | "nl80211: NL80211_CMD_SET_PMKSA with skip_pmk=%s pmk_len=%zu", |
| 10094 | skip_pmk ? "true" : "false", params->pmk_len); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10095 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10096 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10097 | (params->pmkid && |
| 10098 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 10099 | (params->bssid && |
| 10100 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 10101 | (params->ssid_len && |
| 10102 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 10103 | (params->fils_cache_id && |
| 10104 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 10105 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10106 | (params->pmk_lifetime && |
| 10107 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 10108 | params->pmk_lifetime)) || |
| 10109 | (params->pmk_reauth_threshold && |
| 10110 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 10111 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 10112 | (cmd != NL80211_CMD_DEL_PMKSA && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10113 | params->pmk_len && !skip_pmk && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10114 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10115 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10116 | nlmsg_free(msg); |
| 10117 | return -ENOBUFS; |
| 10118 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10119 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10120 | return send_and_recv_cmd(bss->drv, msg); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10121 | } |
| 10122 | |
| 10123 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10124 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10125 | { |
| 10126 | struct i802_bss *bss = priv; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10127 | const size_t PMK_MAX_LEN = 64; /* current cfg80211 limit */ |
| 10128 | const size_t LEGACY_PMK_MAX_LEN = 48; /* old cfg80211 limit */ |
| 10129 | bool skip_pmk = params->pmk_len > PMK_MAX_LEN; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10130 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10131 | |
| 10132 | if (params->bssid) |
| 10133 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 10134 | MAC2STR(params->bssid)); |
| 10135 | else if (params->fils_cache_id && params->ssid_len) { |
| 10136 | wpa_printf(MSG_DEBUG, |
| 10137 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 10138 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 10139 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 10140 | } |
| 10141 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10142 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, skip_pmk); |
| 10143 | /* |
| 10144 | * Try again by skipping PMK if the first attempt failed with ERANGE |
| 10145 | * error, PMK was not skipped, and PMK length is greater than the |
| 10146 | * legacy kernel maximum allowed limit. |
| 10147 | */ |
| 10148 | if (ret == -ERANGE && !skip_pmk && |
| 10149 | params->pmk_len > LEGACY_PMK_MAX_LEN) |
| 10150 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, true); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10151 | if (ret < 0) { |
| 10152 | wpa_printf(MSG_DEBUG, |
| 10153 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 10154 | ret, strerror(-ret)); |
| 10155 | } |
| 10156 | |
| 10157 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10158 | } |
| 10159 | |
| 10160 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10161 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10162 | { |
| 10163 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10164 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10165 | |
| 10166 | if (params->bssid) |
| 10167 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 10168 | MAC2STR(params->bssid)); |
| 10169 | else if (params->fils_cache_id && params->ssid_len) { |
| 10170 | wpa_printf(MSG_DEBUG, |
| 10171 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 10172 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 10173 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 10174 | } |
| 10175 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10176 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params, true); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10177 | if (ret < 0) { |
| 10178 | wpa_printf(MSG_DEBUG, |
| 10179 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 10180 | ret, strerror(-ret)); |
| 10181 | } |
| 10182 | |
| 10183 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10184 | } |
| 10185 | |
| 10186 | |
| 10187 | static int nl80211_flush_pmkid(void *priv) |
| 10188 | { |
| 10189 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10190 | struct nl_msg *msg; |
| 10191 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10192 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10193 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 10194 | if (!msg) |
| 10195 | return -ENOBUFS; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10196 | return send_and_recv_cmd(bss->drv, msg); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10197 | } |
| 10198 | |
| 10199 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10200 | static void clean_survey_results(struct survey_results *survey_results) |
| 10201 | { |
| 10202 | struct freq_survey *survey, *tmp; |
| 10203 | |
| 10204 | if (dl_list_empty(&survey_results->survey_list)) |
| 10205 | return; |
| 10206 | |
| 10207 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 10208 | struct freq_survey, list) { |
| 10209 | dl_list_del(&survey->list); |
| 10210 | os_free(survey); |
| 10211 | } |
| 10212 | } |
| 10213 | |
| 10214 | |
| 10215 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 10216 | struct dl_list *survey_list) |
| 10217 | { |
| 10218 | struct freq_survey *survey; |
| 10219 | |
| 10220 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 10221 | if (!survey) |
| 10222 | return; |
| 10223 | |
| 10224 | survey->ifidx = ifidx; |
| 10225 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10226 | survey->filled = 0; |
| 10227 | |
| 10228 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 10229 | survey->nf = (int8_t) |
| 10230 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 10231 | survey->filled |= SURVEY_HAS_NF; |
| 10232 | } |
| 10233 | |
| 10234 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 10235 | survey->channel_time = |
| 10236 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 10237 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 10238 | } |
| 10239 | |
| 10240 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 10241 | survey->channel_time_busy = |
| 10242 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 10243 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 10244 | } |
| 10245 | |
| 10246 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 10247 | survey->channel_time_rx = |
| 10248 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 10249 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 10250 | } |
| 10251 | |
| 10252 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 10253 | survey->channel_time_tx = |
| 10254 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 10255 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 10256 | } |
| 10257 | |
| 10258 | 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)", |
| 10259 | survey->freq, |
| 10260 | survey->nf, |
| 10261 | (unsigned long int) survey->channel_time, |
| 10262 | (unsigned long int) survey->channel_time_busy, |
| 10263 | (unsigned long int) survey->channel_time_tx, |
| 10264 | (unsigned long int) survey->channel_time_rx, |
| 10265 | survey->filled); |
| 10266 | |
| 10267 | dl_list_add_tail(survey_list, &survey->list); |
| 10268 | } |
| 10269 | |
| 10270 | |
| 10271 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 10272 | unsigned int freq_filter) |
| 10273 | { |
| 10274 | if (!freq_filter) |
| 10275 | return 1; |
| 10276 | |
| 10277 | return freq_filter == surveyed_freq; |
| 10278 | } |
| 10279 | |
| 10280 | |
| 10281 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 10282 | { |
| 10283 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10284 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10285 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 10286 | struct survey_results *survey_results; |
| 10287 | u32 surveyed_freq = 0; |
| 10288 | u32 ifidx; |
| 10289 | |
| 10290 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 10291 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 10292 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 10293 | }; |
| 10294 | |
| 10295 | survey_results = (struct survey_results *) arg; |
| 10296 | |
| 10297 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10298 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10299 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 10300 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 10301 | return NL_SKIP; |
| 10302 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10303 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 10304 | |
| 10305 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 10306 | return NL_SKIP; |
| 10307 | |
| 10308 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 10309 | tb[NL80211_ATTR_SURVEY_INFO], |
| 10310 | survey_policy)) |
| 10311 | return NL_SKIP; |
| 10312 | |
| 10313 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 10314 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 10315 | return NL_SKIP; |
| 10316 | } |
| 10317 | |
| 10318 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10319 | |
| 10320 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 10321 | survey_results->freq_filter)) |
| 10322 | return NL_SKIP; |
| 10323 | |
| 10324 | if (survey_results->freq_filter && |
| 10325 | survey_results->freq_filter != surveyed_freq) { |
| 10326 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 10327 | surveyed_freq); |
| 10328 | return NL_SKIP; |
| 10329 | } |
| 10330 | |
| 10331 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 10332 | |
| 10333 | return NL_SKIP; |
| 10334 | } |
| 10335 | |
| 10336 | |
| 10337 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 10338 | { |
| 10339 | struct i802_bss *bss = priv; |
| 10340 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10341 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10342 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10343 | union wpa_event_data data; |
| 10344 | struct survey_results *survey_results; |
| 10345 | |
| 10346 | os_memset(&data, 0, sizeof(data)); |
| 10347 | survey_results = &data.survey_results; |
| 10348 | |
| 10349 | dl_list_init(&survey_results->survey_list); |
| 10350 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10351 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10352 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10353 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10354 | |
| 10355 | if (freq) |
| 10356 | data.survey_results.freq_filter = freq; |
| 10357 | |
| 10358 | do { |
| 10359 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10360 | err = send_and_recv_resp(drv, msg, survey_handler, |
| 10361 | survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10362 | } while (err > 0); |
| 10363 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10364 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10365 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10366 | else |
| 10367 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10368 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10369 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10370 | return err; |
| 10371 | } |
| 10372 | |
| 10373 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 10374 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 10375 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10376 | const u8 *replay_ctr) |
| 10377 | { |
| 10378 | struct i802_bss *bss = priv; |
| 10379 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10380 | struct nlattr *replay_nested; |
| 10381 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10382 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10383 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10384 | if (!drv->set_rekey_offload) |
| 10385 | return; |
| 10386 | |
| 10387 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10388 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 10389 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 10390 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10391 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10392 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 10393 | replay_ctr)) { |
| 10394 | nl80211_nlmsg_clear(msg); |
| 10395 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10396 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10397 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10398 | |
| 10399 | nla_nest_end(msg, replay_nested); |
| 10400 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10401 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10402 | if (ret == -EOPNOTSUPP) { |
| 10403 | wpa_printf(MSG_DEBUG, |
| 10404 | "nl80211: Driver does not support rekey offload"); |
| 10405 | drv->set_rekey_offload = 0; |
| 10406 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10407 | } |
| 10408 | |
| 10409 | |
| 10410 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 10411 | const u8 *addr, int qos) |
| 10412 | { |
| 10413 | /* send data frame to poll STA and check whether |
| 10414 | * this frame is ACKed */ |
| 10415 | struct { |
| 10416 | struct ieee80211_hdr hdr; |
| 10417 | u16 qos_ctl; |
| 10418 | } STRUCT_PACKED nulldata; |
| 10419 | size_t size; |
| 10420 | |
| 10421 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 10422 | |
| 10423 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 10424 | |
| 10425 | if (qos) { |
| 10426 | nulldata.hdr.frame_control = |
| 10427 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10428 | WLAN_FC_STYPE_QOS_NULL); |
| 10429 | size = sizeof(nulldata); |
| 10430 | } else { |
| 10431 | nulldata.hdr.frame_control = |
| 10432 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10433 | WLAN_FC_STYPE_NULLFUNC); |
| 10434 | size = sizeof(struct ieee80211_hdr); |
| 10435 | } |
| 10436 | |
| 10437 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 10438 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 10439 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 10440 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 10441 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10442 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10443 | 0, 0, NULL, 0, 0, -1) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10444 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 10445 | "send poll frame"); |
| 10446 | } |
| 10447 | |
| 10448 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 10449 | int qos) |
| 10450 | { |
| 10451 | struct i802_bss *bss = priv; |
| 10452 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10453 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 10454 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10455 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10456 | |
| 10457 | if (!drv->poll_command_supported) { |
| 10458 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 10459 | return; |
| 10460 | } |
| 10461 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10462 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 10463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10464 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10465 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10466 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10467 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10468 | ret = send_and_recv_resp(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10469 | if (ret < 0) { |
| 10470 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 10471 | MACSTR " failed: ret=%d (%s)", |
| 10472 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 10473 | } else { |
| 10474 | wpa_printf(MSG_DEBUG, |
| 10475 | "nl80211: Client probe request addr=" MACSTR |
| 10476 | " cookie=%llu", MAC2STR(addr), |
| 10477 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10478 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10479 | } |
| 10480 | |
| 10481 | |
| 10482 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 10483 | { |
| 10484 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10485 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10486 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10487 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 10488 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 10489 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 10490 | nlmsg_free(msg); |
| 10491 | return -ENOBUFS; |
| 10492 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10493 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10494 | ret = send_and_recv_cmd(bss->drv, msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10495 | if (ret < 0) { |
| 10496 | wpa_printf(MSG_DEBUG, |
| 10497 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 10498 | enabled ? "enabled" : "disabled", |
| 10499 | ret, strerror(-ret)); |
| 10500 | } |
| 10501 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10502 | } |
| 10503 | |
| 10504 | |
| 10505 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 10506 | int ctwindow) |
| 10507 | { |
| 10508 | struct i802_bss *bss = priv; |
| 10509 | |
| 10510 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 10511 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 10512 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10513 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10514 | #ifdef ANDROID_P2P |
| 10515 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10516 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10517 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10518 | #endif /* ANDROID_P2P */ |
| 10519 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10520 | |
| 10521 | if (legacy_ps == -1) |
| 10522 | return 0; |
| 10523 | if (legacy_ps != 0 && legacy_ps != 1) |
| 10524 | return -1; /* Not yet supported */ |
| 10525 | |
| 10526 | return nl80211_set_power_save(bss, legacy_ps); |
| 10527 | } |
| 10528 | |
| 10529 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 10530 | static int nl80211_start_radar_detection(void *priv, |
| 10531 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10532 | { |
| 10533 | struct i802_bss *bss = priv; |
| 10534 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10535 | struct nl_msg *msg; |
| 10536 | int ret; |
| 10537 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10538 | 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)", |
| 10539 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 10540 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 10541 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10542 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 10543 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 10544 | "detection"); |
| 10545 | return -1; |
| 10546 | } |
| 10547 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10548 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 10549 | nl80211_put_freq_params(msg, freq) < 0) { |
| 10550 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10551 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10552 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10553 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10554 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10555 | if (ret == 0) |
| 10556 | return 0; |
| 10557 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 10558 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10559 | return -1; |
| 10560 | } |
| 10561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10562 | #ifdef CONFIG_TDLS |
| 10563 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10564 | static int nl80211_add_peer_capab(struct nl_msg *msg, |
| 10565 | enum tdls_peer_capability capa) |
| 10566 | { |
| 10567 | u32 peer_capab = 0; |
| 10568 | |
| 10569 | if (!capa) |
| 10570 | return 0; |
| 10571 | |
| 10572 | if (capa & TDLS_PEER_HT) |
| 10573 | peer_capab |= NL80211_TDLS_PEER_HT; |
| 10574 | if (capa & TDLS_PEER_VHT) |
| 10575 | peer_capab |= NL80211_TDLS_PEER_VHT; |
| 10576 | if (capa & TDLS_PEER_WMM) |
| 10577 | peer_capab |= NL80211_TDLS_PEER_WMM; |
| 10578 | if (capa & TDLS_PEER_HE) |
| 10579 | peer_capab |= NL80211_TDLS_PEER_HE; |
| 10580 | |
| 10581 | return nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 10582 | peer_capab); |
| 10583 | } |
| 10584 | |
| 10585 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10586 | static int |
| 10587 | nl80211_tdls_set_discovery_resp_link(struct wpa_driver_nl80211_data *drv, |
| 10588 | int link_id) |
| 10589 | { |
| 10590 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10591 | struct nl_msg *msg; |
| 10592 | struct nlattr *params; |
| 10593 | |
| 10594 | wpa_printf(MSG_DEBUG, "nl80211: TDLS Discovery Response Tx link ID %u", |
| 10595 | link_id); |
| 10596 | |
| 10597 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10598 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 10599 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10600 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10601 | QCA_NL80211_VENDOR_SUBCMD_TDLS_DISC_RSP_EXT) || |
| 10602 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10603 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TDLS_DISC_RSP_EXT_TX_LINK, |
| 10604 | link_id)) { |
| 10605 | wpa_printf(MSG_ERROR, |
| 10606 | "%s: err in adding vendor_cmd and vendor_data", |
| 10607 | __func__); |
| 10608 | nlmsg_free(msg); |
| 10609 | return -1; |
| 10610 | } |
| 10611 | nla_nest_end(msg, params); |
| 10612 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10613 | return send_and_recv_cmd(drv, msg); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10614 | #else /* CONFIG_DRIVER_NL80211_QCA */ |
| 10615 | wpa_printf(MSG_ERROR, |
| 10616 | "nl80211: Setting TX link for TDLS Discovery Response not supported"); |
| 10617 | return -1; |
| 10618 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 10619 | } |
| 10620 | |
| 10621 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10622 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 10623 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 10624 | u32 peer_capab, int initiator, const u8 *buf, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10625 | size_t len, int link_id) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10626 | { |
| 10627 | struct i802_bss *bss = priv; |
| 10628 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10629 | struct nl_msg *msg; |
| 10630 | |
| 10631 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 10632 | return -EOPNOTSUPP; |
| 10633 | |
| 10634 | if (!dst) |
| 10635 | return -EINVAL; |
| 10636 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10637 | if (link_id >= 0 && |
| 10638 | nl80211_tdls_set_discovery_resp_link(drv, link_id) < 0) |
| 10639 | return -EOPNOTSUPP; |
| 10640 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 10641 | if (link_id < 0 && drv->sta_mlo_info.valid_links) |
| 10642 | link_id = drv->sta_mlo_info.assoc_link_id; |
| 10643 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10644 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 10645 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 10646 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 10647 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10648 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code) || |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 10649 | (link_id >= 0 && |
| 10650 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10651 | nl80211_add_peer_capab(msg, peer_capab) || |
| 10652 | (initiator && nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10653 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 10654 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10655 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10656 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10657 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10658 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10659 | nlmsg_free(msg); |
| 10660 | return -ENOBUFS; |
| 10661 | } |
| 10662 | |
| 10663 | |
| 10664 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 10665 | { |
| 10666 | struct i802_bss *bss = priv; |
| 10667 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10668 | struct nl_msg *msg; |
| 10669 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10670 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10671 | |
| 10672 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 10673 | return -EOPNOTSUPP; |
| 10674 | |
| 10675 | switch (oper) { |
| 10676 | case TDLS_DISCOVERY_REQ: |
| 10677 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 10678 | break; |
| 10679 | case TDLS_SETUP: |
| 10680 | nl80211_oper = NL80211_TDLS_SETUP; |
| 10681 | break; |
| 10682 | case TDLS_TEARDOWN: |
| 10683 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 10684 | break; |
| 10685 | case TDLS_ENABLE_LINK: |
| 10686 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 10687 | break; |
| 10688 | case TDLS_DISABLE_LINK: |
| 10689 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 10690 | break; |
| 10691 | case TDLS_ENABLE: |
| 10692 | return 0; |
| 10693 | case TDLS_DISABLE: |
| 10694 | return 0; |
| 10695 | default: |
| 10696 | return -EINVAL; |
| 10697 | } |
| 10698 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10699 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 10700 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 10701 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 10702 | nlmsg_free(msg); |
| 10703 | return -ENOBUFS; |
| 10704 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10705 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10706 | res = send_and_recv_cmd(drv, msg); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10707 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 10708 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 10709 | strerror(-res)); |
| 10710 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10711 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10712 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10713 | |
| 10714 | static int |
| 10715 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 10716 | const struct hostapd_freq_params *params) |
| 10717 | { |
| 10718 | struct i802_bss *bss = priv; |
| 10719 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10720 | struct nl_msg *msg; |
| 10721 | int ret = -ENOBUFS; |
| 10722 | |
| 10723 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 10724 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 10725 | return -EOPNOTSUPP; |
| 10726 | |
| 10727 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 10728 | " oper_class=%u freq=%u", |
| 10729 | MAC2STR(addr), oper_class, params->freq); |
| 10730 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 10731 | if (!msg || |
| 10732 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10733 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 10734 | (ret = nl80211_put_freq_params(msg, params))) { |
| 10735 | nlmsg_free(msg); |
| 10736 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 10737 | return ret; |
| 10738 | } |
| 10739 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10740 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10741 | } |
| 10742 | |
| 10743 | |
| 10744 | static int |
| 10745 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 10746 | { |
| 10747 | struct i802_bss *bss = priv; |
| 10748 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10749 | struct nl_msg *msg; |
| 10750 | |
| 10751 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 10752 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 10753 | return -EOPNOTSUPP; |
| 10754 | |
| 10755 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 10756 | MAC2STR(addr)); |
| 10757 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 10758 | if (!msg || |
| 10759 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10760 | nlmsg_free(msg); |
| 10761 | wpa_printf(MSG_DEBUG, |
| 10762 | "nl80211: Could not build TDLS cancel chan switch"); |
| 10763 | return -ENOBUFS; |
| 10764 | } |
| 10765 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10766 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10767 | } |
| 10768 | |
| 10769 | #endif /* CONFIG TDLS */ |
| 10770 | |
| 10771 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10772 | static int driver_nl80211_set_key(void *priv, |
| 10773 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10774 | { |
| 10775 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10776 | |
| 10777 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10778 | } |
| 10779 | |
| 10780 | |
| 10781 | static int driver_nl80211_scan2(void *priv, |
| 10782 | struct wpa_driver_scan_params *params) |
| 10783 | { |
| 10784 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10785 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10786 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10787 | |
| 10788 | /* |
| 10789 | * Do a vendor specific scan if possible. If only_new_results is |
| 10790 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 10791 | * cannot be achieved through a vendor scan. The below condition may |
| 10792 | * need to be modified if new scan flags are added in the future whose |
| 10793 | * functionality can only be achieved through a normal scan. |
| 10794 | */ |
| 10795 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 10796 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 10797 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10798 | return wpa_driver_nl80211_scan(bss, params); |
| 10799 | } |
| 10800 | |
| 10801 | |
| 10802 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10803 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10804 | { |
| 10805 | struct i802_bss *bss = priv; |
| 10806 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 10807 | } |
| 10808 | |
| 10809 | |
| 10810 | static int driver_nl80211_authenticate(void *priv, |
| 10811 | struct wpa_driver_auth_params *params) |
| 10812 | { |
| 10813 | struct i802_bss *bss = priv; |
| 10814 | return wpa_driver_nl80211_authenticate(bss, params); |
| 10815 | } |
| 10816 | |
| 10817 | |
| 10818 | static void driver_nl80211_deinit(void *priv) |
| 10819 | { |
| 10820 | struct i802_bss *bss = priv; |
| 10821 | wpa_driver_nl80211_deinit(bss); |
| 10822 | } |
| 10823 | |
| 10824 | |
| 10825 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 10826 | const char *ifname) |
| 10827 | { |
| 10828 | struct i802_bss *bss = priv; |
| 10829 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 10830 | } |
| 10831 | |
| 10832 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10833 | #ifdef CONFIG_IEEE80211BE |
| 10834 | |
| 10835 | static int driver_nl80211_link_remove(void *priv, enum wpa_driver_if_type type, |
| 10836 | const char *ifname, u8 link_id) |
| 10837 | { |
| 10838 | struct i802_bss *bss = priv; |
| 10839 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10840 | |
| 10841 | if (type != WPA_IF_AP_BSS || |
| 10842 | !nl80211_link_valid(bss->valid_links, link_id)) |
| 10843 | return -1; |
| 10844 | |
| 10845 | wpa_printf(MSG_DEBUG, |
| 10846 | "nl80211: Teardown AP(%s) link %d (type=%d ifname=%s links=0x%x)", |
| 10847 | bss->ifname, link_id, type, ifname, bss->valid_links); |
| 10848 | |
| 10849 | nl80211_remove_link(bss, link_id); |
| 10850 | |
| 10851 | bss->ctx = bss->flink->ctx; |
| 10852 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 10853 | if (drv->first_bss == bss && bss->valid_links) |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10854 | drv->ctx = bss->ctx; |
| 10855 | |
| 10856 | if (!bss->valid_links) { |
| 10857 | wpa_printf(MSG_DEBUG, |
| 10858 | "nl80211: No more links remaining, so remove interface"); |
| 10859 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 10860 | } |
| 10861 | |
| 10862 | return 0; |
| 10863 | } |
| 10864 | |
| 10865 | |
| 10866 | static bool nl80211_is_drv_shared(void *priv, void *bss_ctx) |
| 10867 | { |
| 10868 | struct i802_bss *bss = priv; |
| 10869 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10870 | unsigned int num_bss = 0; |
| 10871 | |
| 10872 | /* If any other BSS exist, someone else is using this since at this |
| 10873 | * time, we would have removed all BSSs created by this driver and only |
| 10874 | * this BSS should be remaining if the driver is not shared by anyone. |
| 10875 | */ |
| 10876 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 10877 | num_bss++; |
| 10878 | if (num_bss > 1) |
| 10879 | return true; |
| 10880 | } |
| 10881 | |
| 10882 | /* This is the only BSS present */ |
| 10883 | bss = priv; |
| 10884 | |
| 10885 | /* If only one/no link is there no one is sharing */ |
| 10886 | if (bss->valid_links <= 1) |
| 10887 | return false; |
| 10888 | |
| 10889 | /* More than one link means someone is still using. To check if |
| 10890 | * only 1 bit is set, power of 2 condition can be checked. */ |
| 10891 | if (!(bss->valid_links & (bss->valid_links - 1))) |
| 10892 | return false; |
| 10893 | |
| 10894 | return true; |
| 10895 | } |
| 10896 | |
| 10897 | #endif /* CONFIG_IEEE80211BE */ |
| 10898 | |
| 10899 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10900 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 10901 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10902 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10903 | const u16 *csa_offs, size_t csa_offs_len, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10904 | int no_encrypt, unsigned int wait, |
| 10905 | int link_id) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10906 | { |
| 10907 | struct i802_bss *bss = priv; |
| 10908 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10909 | freq, 0, 0, wait, csa_offs, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10910 | csa_offs_len, no_encrypt, link_id); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10911 | } |
| 10912 | |
| 10913 | |
| 10914 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 10915 | { |
| 10916 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10917 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10918 | } |
| 10919 | |
| 10920 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10921 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10922 | const char *ifname, int vlan_id, |
| 10923 | int link_id) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10924 | { |
| 10925 | struct i802_bss *bss = priv; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 10926 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id, link_id); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10927 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10928 | |
| 10929 | |
| 10930 | static int driver_nl80211_read_sta_data(void *priv, |
| 10931 | struct hostap_sta_driver_data *data, |
| 10932 | const u8 *addr) |
| 10933 | { |
| 10934 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 10935 | |
| 10936 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10937 | return i802_read_sta_data(bss, data, addr); |
| 10938 | } |
| 10939 | |
| 10940 | |
| 10941 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 10942 | unsigned int wait_time, |
| 10943 | const u8 *dst, const u8 *src, |
| 10944 | const u8 *bssid, |
| 10945 | const u8 *data, size_t data_len, |
| 10946 | int no_cck) |
| 10947 | { |
| 10948 | struct i802_bss *bss = priv; |
| 10949 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 10950 | bssid, data, data_len, no_cck); |
| 10951 | } |
| 10952 | |
| 10953 | |
| 10954 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 10955 | { |
| 10956 | struct i802_bss *bss = priv; |
| 10957 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 10958 | } |
| 10959 | |
| 10960 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10961 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 10962 | const u8 *ies, size_t ies_len) |
| 10963 | { |
| 10964 | int ret; |
| 10965 | struct nl_msg *msg; |
| 10966 | struct i802_bss *bss = priv; |
| 10967 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10968 | u16 mdid = WPA_GET_LE16(md); |
| 10969 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10970 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10971 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 10972 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 10973 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 10974 | nlmsg_free(msg); |
| 10975 | return -ENOBUFS; |
| 10976 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10977 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10978 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10979 | if (ret) { |
| 10980 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 10981 | "err=%d (%s)", ret, strerror(-ret)); |
| 10982 | } |
| 10983 | |
| 10984 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10985 | } |
| 10986 | |
| 10987 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10988 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 10989 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 10990 | { |
| 10991 | int ret; |
| 10992 | struct nl_msg *msg; |
| 10993 | struct i802_bss *bss = priv; |
| 10994 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10995 | |
| 10996 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 10997 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 10998 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 10999 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 11000 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 11001 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 11002 | nlmsg_free(msg); |
| 11003 | return -ENOBUFS; |
| 11004 | } |
| 11005 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11006 | ret = send_and_recv_cmd(drv, msg); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11007 | if (ret) { |
| 11008 | wpa_printf(MSG_DEBUG, |
| 11009 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 11010 | ret, strerror(-ret)); |
| 11011 | } |
| 11012 | |
| 11013 | return ret; |
| 11014 | } |
| 11015 | |
| 11016 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 11017 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11018 | { |
| 11019 | struct i802_bss *bss = priv; |
| 11020 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11021 | |
| 11022 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 11023 | return NULL; |
| 11024 | |
| 11025 | return bss->addr; |
| 11026 | } |
| 11027 | |
| 11028 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11029 | static const char * scan_state_str(enum scan_states scan_state) |
| 11030 | { |
| 11031 | switch (scan_state) { |
| 11032 | case NO_SCAN: |
| 11033 | return "NO_SCAN"; |
| 11034 | case SCAN_REQUESTED: |
| 11035 | return "SCAN_REQUESTED"; |
| 11036 | case SCAN_STARTED: |
| 11037 | return "SCAN_STARTED"; |
| 11038 | case SCAN_COMPLETED: |
| 11039 | return "SCAN_COMPLETED"; |
| 11040 | case SCAN_ABORTED: |
| 11041 | return "SCAN_ABORTED"; |
| 11042 | case SCHED_SCAN_STARTED: |
| 11043 | return "SCHED_SCAN_STARTED"; |
| 11044 | case SCHED_SCAN_STOPPED: |
| 11045 | return "SCHED_SCAN_STOPPED"; |
| 11046 | case SCHED_SCAN_RESULTS: |
| 11047 | return "SCHED_SCAN_RESULTS"; |
| 11048 | } |
| 11049 | |
| 11050 | return "??"; |
| 11051 | } |
| 11052 | |
| 11053 | |
| 11054 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 11055 | { |
| 11056 | struct i802_bss *bss = priv; |
| 11057 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11058 | int res; |
| 11059 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11060 | struct nl_msg *msg; |
| 11061 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11062 | |
| 11063 | pos = buf; |
| 11064 | end = buf + buflen; |
| 11065 | |
| 11066 | res = os_snprintf(pos, end - pos, |
| 11067 | "ifindex=%d\n" |
| 11068 | "ifname=%s\n" |
| 11069 | "brname=%s\n" |
| 11070 | "addr=" MACSTR "\n" |
| 11071 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 11072 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11073 | bss->ifindex, |
| 11074 | bss->ifname, |
| 11075 | bss->brname, |
| 11076 | MAC2STR(bss->addr), |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 11077 | bss->flink->freq, |
| 11078 | bss->flink->beacon_set ? "beacon_set=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11079 | bss->added_if_into_bridge ? |
| 11080 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 11081 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11082 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 11083 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 11084 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11085 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11086 | return pos - buf; |
| 11087 | pos += res; |
| 11088 | |
| 11089 | if (bss->wdev_id_set) { |
| 11090 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 11091 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11092 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11093 | return pos - buf; |
| 11094 | pos += res; |
| 11095 | } |
| 11096 | |
| 11097 | res = os_snprintf(pos, end - pos, |
| 11098 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11099 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11100 | "drv_ifindex=%d\n" |
| 11101 | "operstate=%d\n" |
| 11102 | "scan_state=%s\n" |
| 11103 | "auth_bssid=" MACSTR "\n" |
| 11104 | "auth_attempt_bssid=" MACSTR "\n" |
| 11105 | "bssid=" MACSTR "\n" |
| 11106 | "prev_bssid=" MACSTR "\n" |
| 11107 | "associated=%d\n" |
| 11108 | "assoc_freq=%u\n" |
| 11109 | "monitor_sock=%d\n" |
| 11110 | "monitor_ifidx=%d\n" |
| 11111 | "monitor_refcount=%d\n" |
| 11112 | "last_mgmt_freq=%u\n" |
| 11113 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11114 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11115 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11116 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11117 | drv->ifindex, |
| 11118 | drv->operstate, |
| 11119 | scan_state_str(drv->scan_state), |
| 11120 | MAC2STR(drv->auth_bssid), |
| 11121 | MAC2STR(drv->auth_attempt_bssid), |
| 11122 | MAC2STR(drv->bssid), |
| 11123 | MAC2STR(drv->prev_bssid), |
| 11124 | drv->associated, |
| 11125 | drv->assoc_freq, |
| 11126 | drv->monitor_sock, |
| 11127 | drv->monitor_ifidx, |
| 11128 | drv->monitor_refcount, |
| 11129 | drv->last_mgmt_freq, |
| 11130 | drv->eapol_tx_sock, |
| 11131 | drv->ignore_if_down_event ? |
| 11132 | "ignore_if_down_event=1\n" : "", |
| 11133 | drv->scan_complete_events ? |
| 11134 | "scan_complete_events=1\n" : "", |
| 11135 | drv->disabled_11b_rates ? |
| 11136 | "disabled_11b_rates=1\n" : "", |
| 11137 | drv->pending_remain_on_chan ? |
| 11138 | "pending_remain_on_chan=1\n" : "", |
| 11139 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 11140 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 11141 | drv->poll_command_supported ? |
| 11142 | "poll_command_supported=1\n" : "", |
| 11143 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 11144 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 11145 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 11146 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 11147 | drv->ignore_next_local_disconnect ? |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11148 | "ignore_next_local_disconnect\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 11149 | drv->ignore_next_local_deauth ? |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11150 | "ignore_next_local_deauth\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11151 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11152 | return pos - buf; |
| 11153 | pos += res; |
| 11154 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 11155 | if (drv->sta_mlo_info.valid_links) { |
| 11156 | int i; |
| 11157 | struct driver_sta_mlo_info *mlo = &drv->sta_mlo_info; |
| 11158 | |
| 11159 | res = os_snprintf(pos, end - pos, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 11160 | "ap_mld_addr=" MACSTR "\n" |
| 11161 | "default_map=%d\n", |
| 11162 | MAC2STR(mlo->ap_mld_addr), |
| 11163 | mlo->default_map); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 11164 | if (os_snprintf_error(end - pos, res)) |
| 11165 | return pos - buf; |
| 11166 | pos += res; |
| 11167 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11168 | for_each_link(mlo->valid_links, i) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 11169 | res = os_snprintf(pos, end - pos, |
| 11170 | "link_addr[%u]=" MACSTR "\n" |
| 11171 | "link_bssid[%u]=" MACSTR "\n" |
| 11172 | "link_freq[%u]=%u\n", |
| 11173 | i, MAC2STR(mlo->links[i].addr), |
| 11174 | i, MAC2STR(mlo->links[i].bssid), |
| 11175 | i, mlo->links[i].freq); |
| 11176 | if (os_snprintf_error(end - pos, res)) |
| 11177 | return pos - buf; |
| 11178 | pos += res; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 11179 | |
| 11180 | if (!mlo->default_map) { |
| 11181 | res = os_snprintf( |
| 11182 | pos, end - pos, |
| 11183 | "uplink_map[%u]=%x\n" |
| 11184 | "downlink_map[%u]=%x\n", |
| 11185 | i, mlo->links[i].t2lmap.uplink, |
| 11186 | i, mlo->links[i].t2lmap.downlink); |
| 11187 | if (os_snprintf_error(end - pos, res)) |
| 11188 | return pos - buf; |
| 11189 | pos += res; |
| 11190 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 11191 | } |
| 11192 | } |
| 11193 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11194 | if (drv->has_capability) { |
| 11195 | res = os_snprintf(pos, end - pos, |
| 11196 | "capa.key_mgmt=0x%x\n" |
| 11197 | "capa.enc=0x%x\n" |
| 11198 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11199 | "capa.flags=0x%llx\n" |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 11200 | "capa.flags2=0x%llx\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11201 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11202 | "capa.max_scan_ssids=%d\n" |
| 11203 | "capa.max_sched_scan_ssids=%d\n" |
| 11204 | "capa.sched_scan_supported=%d\n" |
| 11205 | "capa.max_match_sets=%d\n" |
| 11206 | "capa.max_remain_on_chan=%u\n" |
| 11207 | "capa.max_stations=%u\n" |
| 11208 | "capa.probe_resp_offloads=0x%x\n" |
| 11209 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11210 | "capa.num_multichan_concurrent=%u\n" |
| 11211 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11212 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 11213 | "capa.conc_capab=%u\n" |
| 11214 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11215 | "capa.max_conc_chan_5_0=%u\n" |
| 11216 | "capa.max_sched_scan_plans=%u\n" |
| 11217 | "capa.max_sched_scan_plan_interval=%u\n" |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 11218 | "capa.max_sched_scan_plan_iterations=%u\n" |
| 11219 | "capa.mbssid_max_interfaces=%u\n" |
| 11220 | "capa.ema_max_periodicity=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11221 | drv->capa.key_mgmt, |
| 11222 | drv->capa.enc, |
| 11223 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11224 | (unsigned long long) drv->capa.flags, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 11225 | (unsigned long long) drv->capa.flags2, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11226 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11227 | drv->capa.max_scan_ssids, |
| 11228 | drv->capa.max_sched_scan_ssids, |
| 11229 | drv->capa.sched_scan_supported, |
| 11230 | drv->capa.max_match_sets, |
| 11231 | drv->capa.max_remain_on_chan, |
| 11232 | drv->capa.max_stations, |
| 11233 | drv->capa.probe_resp_offloads, |
| 11234 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11235 | drv->capa.num_multichan_concurrent, |
| 11236 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11237 | drv->capa.mac_addr_rand_scan_supported, |
| 11238 | drv->capa.conc_capab, |
| 11239 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11240 | drv->capa.max_conc_chan_5_0, |
| 11241 | drv->capa.max_sched_scan_plans, |
| 11242 | drv->capa.max_sched_scan_plan_interval, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 11243 | drv->capa.max_sched_scan_plan_iterations, |
| 11244 | drv->capa.mbssid_max_interfaces, |
| 11245 | drv->capa.ema_max_periodicity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11246 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11247 | return pos - buf; |
| 11248 | pos += res; |
| 11249 | } |
| 11250 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11251 | msg = nlmsg_alloc(); |
| 11252 | if (msg && |
| 11253 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 11254 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11255 | if (send_and_recv_resp(drv, msg, nl80211_get_country, |
| 11256 | alpha2) == 0 && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11257 | alpha2[0]) { |
| 11258 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 11259 | alpha2); |
| 11260 | if (os_snprintf_error(end - pos, res)) |
| 11261 | return pos - buf; |
| 11262 | pos += res; |
| 11263 | } |
| 11264 | } else { |
| 11265 | nlmsg_free(msg); |
| 11266 | } |
| 11267 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11268 | return pos - buf; |
| 11269 | } |
| 11270 | |
| 11271 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11272 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 11273 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11274 | if ((settings->head && |
| 11275 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 11276 | settings->head_len, settings->head)) || |
| 11277 | (settings->tail && |
| 11278 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 11279 | settings->tail_len, settings->tail)) || |
| 11280 | (settings->beacon_ies && |
| 11281 | nla_put(msg, NL80211_ATTR_IE, |
| 11282 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 11283 | (settings->proberesp_ies && |
| 11284 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 11285 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 11286 | (settings->assocresp_ies && |
| 11287 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 11288 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 11289 | (settings->probe_resp && |
| 11290 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 11291 | settings->probe_resp_len, settings->probe_resp))) |
| 11292 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11293 | |
| 11294 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11295 | } |
| 11296 | |
| 11297 | |
| 11298 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 11299 | { |
| 11300 | struct nl_msg *msg; |
| 11301 | struct i802_bss *bss = priv; |
| 11302 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11303 | struct nlattr *beacon_csa; |
| 11304 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11305 | int csa_off_len = 0; |
| 11306 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11307 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11308 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11309 | "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 Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11310 | settings->cs_count, settings->block_tx, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11311 | settings->freq_params.freq, |
| 11312 | settings->freq_params.channel, |
| 11313 | settings->freq_params.sec_channel_offset, |
| 11314 | settings->freq_params.bandwidth, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 11315 | settings->freq_params.center_freq1, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11316 | settings->freq_params.center_freq2, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 11317 | settings->punct_bitmap, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11318 | settings->link_id, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11319 | settings->freq_params.ht_enabled ? " ht" : "", |
| 11320 | settings->freq_params.vht_enabled ? " vht" : "", |
| 11321 | settings->freq_params.he_enabled ? " he" : ""); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11322 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11323 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11324 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 11325 | return -EOPNOTSUPP; |
| 11326 | } |
| 11327 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11328 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 11329 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 11330 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11331 | return -EOPNOTSUPP; |
| 11332 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11333 | /* |
| 11334 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 11335 | * counters match. This implementation assumes that there are only two |
| 11336 | * counters. |
| 11337 | */ |
| 11338 | if (settings->counter_offset_beacon[0] && |
| 11339 | !settings->counter_offset_beacon[1]) { |
| 11340 | csa_off_len = 1; |
| 11341 | } else if (settings->counter_offset_beacon[1] && |
| 11342 | !settings->counter_offset_beacon[0]) { |
| 11343 | csa_off_len = 1; |
| 11344 | settings->counter_offset_beacon[0] = |
| 11345 | settings->counter_offset_beacon[1]; |
| 11346 | settings->counter_offset_presp[0] = |
| 11347 | settings->counter_offset_presp[1]; |
| 11348 | } else if (settings->counter_offset_beacon[1] && |
| 11349 | settings->counter_offset_beacon[0]) { |
| 11350 | csa_off_len = 2; |
| 11351 | } else { |
| 11352 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 11353 | return -EINVAL; |
| 11354 | } |
| 11355 | |
| 11356 | /* Check CSA counters validity */ |
| 11357 | if (drv->capa.max_csa_counters && |
| 11358 | csa_off_len > drv->capa.max_csa_counters) { |
| 11359 | wpa_printf(MSG_ERROR, |
| 11360 | "nl80211: Too many CSA counters provided"); |
| 11361 | return -EINVAL; |
| 11362 | } |
| 11363 | |
| 11364 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11365 | return -EINVAL; |
| 11366 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11367 | for (i = 0; i < csa_off_len; i++) { |
| 11368 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 11369 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 11370 | |
| 11371 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 11372 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 11373 | settings->cs_count)) |
| 11374 | return -EINVAL; |
| 11375 | |
| 11376 | if (settings->beacon_csa.probe_resp && |
| 11377 | ((settings->beacon_csa.probe_resp_len <= |
| 11378 | csa_c_off_presp) || |
| 11379 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 11380 | settings->cs_count))) |
| 11381 | return -EINVAL; |
| 11382 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11383 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11384 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 11385 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 11386 | settings->cs_count) || |
| 11387 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 11388 | (settings->block_tx && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 11389 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) || |
| 11390 | (settings->punct_bitmap && |
| 11391 | nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11392 | settings->punct_bitmap)) || |
| 11393 | (settings->link_id != NL80211_DRV_LINK_ID_NA && |
| 11394 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, settings->link_id))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11395 | goto error; |
| 11396 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11397 | /* beacon_after params */ |
| 11398 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 11399 | if (ret) |
| 11400 | goto error; |
| 11401 | |
| 11402 | /* beacon_csa params */ |
| 11403 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 11404 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11405 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11406 | |
| 11407 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 11408 | if (ret) |
| 11409 | goto error; |
| 11410 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11411 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 11412 | csa_off_len * sizeof(u16), |
| 11413 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11414 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11415 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 11416 | csa_off_len * sizeof(u16), |
| 11417 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11418 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11419 | |
| 11420 | nla_nest_end(msg, beacon_csa); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 11421 | |
| 11422 | #ifdef CONFIG_IEEE80211AX |
| 11423 | if (settings->ubpr.unsol_bcast_probe_resp_interval && |
| 11424 | nl80211_unsol_bcast_probe_resp(bss, msg, &settings->ubpr) < 0) |
| 11425 | goto fail; |
| 11426 | #endif /* CONFIG_IEEE80211AX */ |
| 11427 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11428 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11429 | if (ret) { |
| 11430 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 11431 | ret, strerror(-ret)); |
| 11432 | } |
| 11433 | return ret; |
| 11434 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11435 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11436 | ret = -ENOBUFS; |
| 11437 | error: |
| 11438 | nlmsg_free(msg); |
| 11439 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 11440 | return ret; |
| 11441 | } |
| 11442 | |
| 11443 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11444 | #ifdef CONFIG_IEEE80211AX |
| 11445 | static int nl80211_switch_color(void *priv, struct cca_settings *settings) |
| 11446 | { |
| 11447 | struct i802_bss *bss = priv; |
| 11448 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11449 | struct nlattr *beacon_cca; |
| 11450 | struct nl_msg *msg; |
| 11451 | int ret = -ENOBUFS; |
| 11452 | |
| 11453 | wpa_printf(MSG_DEBUG, |
| 11454 | "nl80211: Color change request (cca_count=%u color=%d)", |
| 11455 | settings->cca_count, settings->cca_color); |
| 11456 | |
| 11457 | if (drv->nlmode != NL80211_IFTYPE_AP) |
| 11458 | return -EOPNOTSUPP; |
| 11459 | |
| 11460 | if (!settings->beacon_cca.tail) |
| 11461 | return -EINVAL; |
| 11462 | |
| 11463 | if (settings->beacon_cca.tail_len <= settings->counter_offset_beacon || |
| 11464 | settings->beacon_cca.tail[settings->counter_offset_beacon] != |
| 11465 | settings->cca_count) |
| 11466 | return -EINVAL; |
| 11467 | |
| 11468 | if (settings->beacon_cca.probe_resp && |
| 11469 | (settings->beacon_cca.probe_resp_len <= |
| 11470 | settings->counter_offset_presp || |
| 11471 | settings->beacon_cca.probe_resp[settings->counter_offset_presp] != |
| 11472 | settings->cca_count)) |
| 11473 | return -EINVAL; |
| 11474 | |
| 11475 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_COLOR_CHANGE_REQUEST); |
| 11476 | if (!msg || |
| 11477 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, |
| 11478 | settings->cca_count) || |
| 11479 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COLOR, |
| 11480 | settings->cca_color)) |
| 11481 | goto error; |
| 11482 | |
| 11483 | /* beacon_after params */ |
| 11484 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 11485 | if (ret) |
| 11486 | goto error; |
| 11487 | |
| 11488 | /* beacon_csa params */ |
| 11489 | beacon_cca = nla_nest_start(msg, NL80211_ATTR_COLOR_CHANGE_ELEMS); |
| 11490 | if (!beacon_cca) { |
| 11491 | ret = -ENOBUFS; |
| 11492 | goto error; |
| 11493 | } |
| 11494 | |
| 11495 | ret = set_beacon_data(msg, &settings->beacon_cca); |
| 11496 | if (ret) |
| 11497 | goto error; |
| 11498 | |
| 11499 | if (nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_BEACON, |
| 11500 | settings->counter_offset_beacon) || |
| 11501 | (settings->beacon_cca.probe_resp && |
| 11502 | nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_PRESP, |
| 11503 | settings->counter_offset_presp))) { |
| 11504 | ret = -ENOBUFS; |
| 11505 | goto error; |
| 11506 | } |
| 11507 | |
| 11508 | nla_nest_end(msg, beacon_cca); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 11509 | |
| 11510 | if (settings->ubpr.unsol_bcast_probe_resp_interval && |
| 11511 | nl80211_unsol_bcast_probe_resp(bss, msg, &settings->ubpr) < 0) { |
| 11512 | ret = -ENOBUFS; |
| 11513 | goto error; |
| 11514 | } |
| 11515 | |
| 11516 | #ifdef CONFIG_IEEE80211BE |
| 11517 | if (nl80211_link_valid(bss->valid_links, settings->link_id)) { |
| 11518 | wpa_printf(MSG_DEBUG, |
| 11519 | "nl80211: Color change request on link_id=%d", |
| 11520 | settings->link_id); |
| 11521 | |
| 11522 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 11523 | settings->link_id)) { |
| 11524 | nlmsg_free(msg); |
| 11525 | return -1; |
| 11526 | } |
| 11527 | } |
| 11528 | #endif /* CONFIG_IEEE80211BE */ |
| 11529 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11530 | ret = send_and_recv_cmd(drv, msg); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11531 | if (ret) { |
| 11532 | wpa_printf(MSG_DEBUG, |
| 11533 | "nl80211: switch_color failed err=%d (%s)", |
| 11534 | ret, strerror(-ret)); |
| 11535 | } |
| 11536 | return ret; |
| 11537 | |
| 11538 | error: |
| 11539 | nlmsg_free(msg); |
| 11540 | wpa_printf(MSG_DEBUG, "nl80211: Could not build color switch request"); |
| 11541 | return ret; |
| 11542 | } |
| 11543 | #endif /* CONFIG_IEEE80211AX */ |
| 11544 | |
| 11545 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11546 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 11547 | u8 user_priority, u16 admitted_time) |
| 11548 | { |
| 11549 | struct i802_bss *bss = priv; |
| 11550 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11551 | struct nl_msg *msg; |
| 11552 | int ret; |
| 11553 | |
| 11554 | wpa_printf(MSG_DEBUG, |
| 11555 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 11556 | tsid, admitted_time, user_priority); |
| 11557 | |
| 11558 | if (!is_sta_interface(drv->nlmode)) |
| 11559 | return -ENOTSUP; |
| 11560 | |
| 11561 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 11562 | if (!msg || |
| 11563 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 11564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11565 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 11566 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 11567 | nlmsg_free(msg); |
| 11568 | return -ENOBUFS; |
| 11569 | } |
| 11570 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11571 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11572 | if (ret) |
| 11573 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 11574 | ret, strerror(-ret)); |
| 11575 | return ret; |
| 11576 | } |
| 11577 | |
| 11578 | |
| 11579 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 11580 | { |
| 11581 | struct i802_bss *bss = priv; |
| 11582 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11583 | struct nl_msg *msg; |
| 11584 | int ret; |
| 11585 | |
| 11586 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 11587 | |
| 11588 | if (!is_sta_interface(drv->nlmode)) |
| 11589 | return -ENOTSUP; |
| 11590 | |
| 11591 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 11592 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 11593 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 11594 | nlmsg_free(msg); |
| 11595 | return -ENOBUFS; |
| 11596 | } |
| 11597 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11598 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11599 | if (ret) |
| 11600 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 11601 | ret, strerror(-ret)); |
| 11602 | return ret; |
| 11603 | } |
| 11604 | |
| 11605 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11606 | #ifdef CONFIG_TESTING_OPTIONS |
| 11607 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 11608 | { |
| 11609 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11610 | struct wpabuf *buf = arg; |
| 11611 | |
| 11612 | if (!buf) |
| 11613 | return NL_SKIP; |
| 11614 | |
| 11615 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 11616 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 11617 | return NL_SKIP; |
| 11618 | } |
| 11619 | |
| 11620 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 11621 | genlmsg_attrlen(gnlh, 0)); |
| 11622 | |
| 11623 | return NL_SKIP; |
| 11624 | } |
| 11625 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11626 | |
| 11627 | |
| 11628 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 11629 | { |
| 11630 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11631 | struct nlattr *nl_vendor_reply, *nl; |
| 11632 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11633 | struct wpabuf *buf = arg; |
| 11634 | int rem; |
| 11635 | |
| 11636 | if (!buf) |
| 11637 | return NL_SKIP; |
| 11638 | |
| 11639 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11640 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11641 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 11642 | |
| 11643 | if (!nl_vendor_reply) |
| 11644 | return NL_SKIP; |
| 11645 | |
| 11646 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 11647 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 11648 | return NL_SKIP; |
| 11649 | } |
| 11650 | |
| 11651 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 11652 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 11653 | } |
| 11654 | |
| 11655 | return NL_SKIP; |
| 11656 | } |
| 11657 | |
| 11658 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11659 | static bool is_cmd_with_nested_attrs(unsigned int vendor_id, |
| 11660 | unsigned int subcmd) |
| 11661 | { |
| 11662 | if (vendor_id != OUI_QCA) |
| 11663 | return true; |
| 11664 | |
| 11665 | switch (subcmd) { |
| 11666 | case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY: |
| 11667 | case QCA_NL80211_VENDOR_SUBCMD_STATS_EXT: |
| 11668 | case QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI: |
| 11669 | case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY: |
| 11670 | case QCA_NL80211_VENDOR_SUBCMD_SPECTRAL_SCAN_GET_STATUS: |
| 11671 | case QCA_NL80211_VENDOR_SUBCMD_NAN: |
| 11672 | return false; |
| 11673 | default: |
| 11674 | return true; |
| 11675 | } |
| 11676 | } |
| 11677 | |
| 11678 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11679 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 11680 | unsigned int subcmd, const u8 *data, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11681 | size_t data_len, enum nested_attr nested_attr, |
| 11682 | struct wpabuf *buf) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11683 | { |
| 11684 | struct i802_bss *bss = priv; |
| 11685 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11686 | struct nl_msg *msg; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11687 | int ret, nla_flag; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11688 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11689 | #ifdef CONFIG_TESTING_OPTIONS |
| 11690 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11691 | msg = nlmsg_alloc(); |
| 11692 | if (!msg) |
| 11693 | return -ENOMEM; |
| 11694 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11695 | nl80211_cmd(drv, msg, 0, subcmd); |
| 11696 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 11697 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11698 | goto fail; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 11699 | /* This test vendor_cmd can be used with nl80211 commands that |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11700 | * need the connect nl_sock, so use the variant that takes in |
| 11701 | * bss->nl_connect as the handle. */ |
| 11702 | ret = send_and_recv(drv->global, bss->nl_connect, msg, |
| 11703 | cmd_reply_handler, buf, NULL, NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11704 | if (ret) |
| 11705 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 11706 | ret); |
| 11707 | return ret; |
| 11708 | } |
| 11709 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11710 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11711 | if (nested_attr == NESTED_ATTR_USED) |
| 11712 | nla_flag = NLA_F_NESTED; |
| 11713 | else if (nested_attr == NESTED_ATTR_UNSPECIFIED && |
| 11714 | is_cmd_with_nested_attrs(vendor_id, subcmd)) |
| 11715 | nla_flag = NLA_F_NESTED; |
| 11716 | else |
| 11717 | nla_flag = 0; |
| 11718 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11719 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 11720 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 11721 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 11722 | (data && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11723 | nla_put(msg, nla_flag | NL80211_ATTR_VENDOR_DATA, |
| 11724 | data_len, data))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11725 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11726 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11727 | ret = send_and_recv_resp(drv, msg, vendor_reply_handler, buf); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11728 | if (ret) |
| 11729 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 11730 | ret); |
| 11731 | return ret; |
| 11732 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11733 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11734 | nlmsg_free(msg); |
| 11735 | return -ENOBUFS; |
| 11736 | } |
| 11737 | |
| 11738 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11739 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 11740 | u8 qos_map_set_len) |
| 11741 | { |
| 11742 | struct i802_bss *bss = priv; |
| 11743 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11744 | struct nl_msg *msg; |
| 11745 | int ret; |
| 11746 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11747 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 11748 | qos_map_set, qos_map_set_len); |
| 11749 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 11750 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_QOS_MAP)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11751 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 11752 | nlmsg_free(msg); |
| 11753 | return -ENOBUFS; |
| 11754 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11755 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11756 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11757 | if (ret) |
| 11758 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 11759 | |
| 11760 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11761 | } |
| 11762 | |
| 11763 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11764 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 11765 | { |
| 11766 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11767 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11768 | int *wowlan_enabled = arg; |
| 11769 | |
| 11770 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11771 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11772 | |
| 11773 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 11774 | |
| 11775 | return NL_SKIP; |
| 11776 | } |
| 11777 | |
| 11778 | |
| 11779 | static int nl80211_get_wowlan(void *priv) |
| 11780 | { |
| 11781 | struct i802_bss *bss = priv; |
| 11782 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11783 | struct nl_msg *msg; |
| 11784 | int wowlan_enabled; |
| 11785 | int ret; |
| 11786 | |
| 11787 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 11788 | |
| 11789 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 11790 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11791 | ret = send_and_recv_resp(drv, msg, get_wowlan_handler, &wowlan_enabled); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11792 | if (ret) { |
| 11793 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 11794 | return 0; |
| 11795 | } |
| 11796 | |
| 11797 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 11798 | wowlan_enabled ? "enabled" : "disabled"); |
| 11799 | |
| 11800 | return wowlan_enabled; |
| 11801 | } |
| 11802 | |
| 11803 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11804 | static int nl80211_set_wowlan(void *priv, |
| 11805 | const struct wowlan_triggers *triggers) |
| 11806 | { |
| 11807 | struct i802_bss *bss = priv; |
| 11808 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11809 | struct nl_msg *msg; |
| 11810 | struct nlattr *wowlan_triggers; |
| 11811 | int ret; |
| 11812 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11813 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 11814 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 11815 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11816 | !(wowlan_triggers = nla_nest_start(msg, |
| 11817 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 11818 | (triggers->any && |
| 11819 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 11820 | (triggers->disconnect && |
| 11821 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 11822 | (triggers->magic_pkt && |
| 11823 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 11824 | (triggers->gtk_rekey_failure && |
| 11825 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 11826 | (triggers->eap_identity_req && |
| 11827 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 11828 | (triggers->four_way_handshake && |
| 11829 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 11830 | (triggers->rfkill_release && |
| 11831 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 11832 | nlmsg_free(msg); |
| 11833 | return -ENOBUFS; |
| 11834 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11835 | |
| 11836 | nla_nest_end(msg, wowlan_triggers); |
| 11837 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11838 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11839 | if (ret) |
| 11840 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 11841 | |
| 11842 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11843 | } |
| 11844 | |
| 11845 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11846 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11847 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 11848 | { |
| 11849 | struct i802_bss *bss = priv; |
| 11850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11851 | struct nl_msg *msg; |
| 11852 | struct nlattr *params; |
| 11853 | |
| 11854 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 11855 | |
| 11856 | if (!drv->roaming_vendor_cmd_avail) { |
| 11857 | wpa_printf(MSG_DEBUG, |
| 11858 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 11859 | return -1; |
| 11860 | } |
| 11861 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11862 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11863 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11864 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11865 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 11866 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11867 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 11868 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 11869 | QCA_ROAMING_NOT_ALLOWED) || |
| 11870 | (bssid && |
| 11871 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 11872 | nlmsg_free(msg); |
| 11873 | return -1; |
| 11874 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11875 | nla_nest_end(msg, params); |
| 11876 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11877 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11878 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11879 | |
| 11880 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11881 | static int nl80211_disable_fils(void *priv, int disable) |
| 11882 | { |
| 11883 | struct i802_bss *bss = priv; |
| 11884 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11885 | struct nl_msg *msg; |
| 11886 | struct nlattr *params; |
| 11887 | |
| 11888 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 11889 | |
| 11890 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 11891 | return -1; |
| 11892 | |
| 11893 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11894 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11895 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11896 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 11897 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11898 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 11899 | disable)) { |
| 11900 | nlmsg_free(msg); |
| 11901 | return -1; |
| 11902 | } |
| 11903 | nla_nest_end(msg, params); |
| 11904 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11905 | return send_and_recv_cmd(drv, msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11906 | } |
| 11907 | |
| 11908 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11909 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 11910 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 11911 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11912 | static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid, |
| 11913 | const u8 *bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11914 | { |
| 11915 | struct i802_bss *bss = priv; |
| 11916 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11917 | struct nl_msg *msg; |
| 11918 | struct nlattr *params, *nlbssids, *attr; |
| 11919 | unsigned int i; |
| 11920 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11921 | wpa_printf(MSG_DEBUG, |
| 11922 | "nl80211: Set temporarily disallowed BSSIDs (num=%u)", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11923 | num_bssid); |
| 11924 | |
| 11925 | if (!drv->roam_vendor_cmd_avail) |
| 11926 | return -1; |
| 11927 | |
| 11928 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11929 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11930 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11931 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 11932 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11933 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11934 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11935 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 11936 | WPA_SUPPLICANT_CLIENT_ID) || |
| 11937 | nla_put_u32(msg, |
| 11938 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 11939 | num_bssid)) |
| 11940 | goto fail; |
| 11941 | |
| 11942 | nlbssids = nla_nest_start( |
| 11943 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 11944 | if (!nlbssids) |
| 11945 | goto fail; |
| 11946 | |
| 11947 | for (i = 0; i < num_bssid; i++) { |
| 11948 | attr = nla_nest_start(msg, i); |
| 11949 | if (!attr) |
| 11950 | goto fail; |
| 11951 | if (nla_put(msg, |
| 11952 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 11953 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 11954 | goto fail; |
| 11955 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 11956 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 11957 | nla_nest_end(msg, attr); |
| 11958 | } |
| 11959 | nla_nest_end(msg, nlbssids); |
| 11960 | nla_nest_end(msg, params); |
| 11961 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 11962 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11963 | |
| 11964 | fail: |
| 11965 | nlmsg_free(msg); |
| 11966 | return -1; |
| 11967 | } |
| 11968 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11969 | |
| 11970 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 11971 | { |
| 11972 | struct i802_bss *bss = priv; |
| 11973 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11974 | struct nl_msg *msg; |
| 11975 | struct nlattr *params; |
| 11976 | |
| 11977 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 11978 | return -EOPNOTSUPP; |
| 11979 | |
| 11980 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 11981 | |
| 11982 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11983 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11984 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11985 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 11986 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11987 | (addr && |
| 11988 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 11989 | addr)) || |
| 11990 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 11991 | auth_alg)) { |
| 11992 | nlmsg_free(msg); |
| 11993 | wpa_printf(MSG_ERROR, |
| 11994 | "%s: err in adding vendor_cmd and vendor_data", |
| 11995 | __func__); |
| 11996 | return -1; |
| 11997 | } |
| 11998 | nla_nest_end(msg, params); |
| 11999 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12000 | return send_and_recv_cmd(drv, msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12001 | } |
| 12002 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12003 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12004 | |
| 12005 | |
| 12006 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 12007 | { |
| 12008 | struct i802_bss *bss = priv; |
| 12009 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12010 | int new_addr = addr != NULL; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12011 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12012 | struct nl_msg *msg; |
| 12013 | struct nlattr *params; |
| 12014 | int ret; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12015 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12016 | wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12017 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12018 | if (TEST_FAIL()) |
| 12019 | return -1; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12020 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12021 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12022 | if (!addr ) { |
| 12023 | addr = drv->global->p2p_perm_addr; |
| 12024 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12025 | |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12026 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 12027 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 12028 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12029 | BRCM_VENDOR_SCMD_SET_MAC) || |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12030 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12031 | nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) { |
| 12032 | wpa_printf(MSG_ERROR, "failed to put p2p randmac"); |
| 12033 | nl80211_nlmsg_clear(msg); |
| 12034 | nlmsg_free(msg); |
| 12035 | return -ENOBUFS; |
| 12036 | } |
| 12037 | nla_nest_end(msg, params); |
| 12038 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12039 | ret = send_and_recv_cmd(drv, msg); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12040 | if (ret) { |
| 12041 | wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)", |
| 12042 | ret, strerror(-ret)); |
| 12043 | } |
| 12044 | memcpy(bss->addr, addr, ETH_ALEN); |
| 12045 | return ret; |
| 12046 | #else |
| 12047 | return -ENOTSUP; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12048 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12049 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12050 | if (!addr) |
| 12051 | addr = drv->perm_addr; |
| 12052 | |
| 12053 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 12054 | return -1; |
| 12055 | |
| 12056 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 12057 | { |
| 12058 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12059 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 12060 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12061 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12062 | 1) < 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12063 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 12064 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12065 | } |
| 12066 | return -1; |
| 12067 | } |
| 12068 | |
| 12069 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 12070 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12071 | drv->addr_changed = new_addr; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 12072 | os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12073 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 12074 | |
Hsiu-Chang Chen | 289286d | 2024-01-24 18:00:43 +0800 | [diff] [blame] | 12075 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 12076 | { |
| 12077 | wpa_printf(MSG_DEBUG, |
| 12078 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 12079 | } |
| 12080 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12081 | return 0; |
| 12082 | } |
| 12083 | |
| 12084 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12085 | #ifdef CONFIG_MESH |
| 12086 | |
| 12087 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 12088 | { |
| 12089 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 12090 | wpa_printf(MSG_INFO, |
| 12091 | "nl80211: Failed to set interface into mesh mode"); |
| 12092 | return -1; |
| 12093 | } |
| 12094 | return 0; |
| 12095 | } |
| 12096 | |
| 12097 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 12098 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 12099 | size_t mesh_id_len) |
| 12100 | { |
| 12101 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12102 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 12103 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 12104 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 12105 | } |
| 12106 | |
| 12107 | return 0; |
| 12108 | } |
| 12109 | |
| 12110 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 12111 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 12112 | struct wpa_driver_mesh_bss_params *params) |
| 12113 | { |
| 12114 | struct nlattr *container; |
| 12115 | |
| 12116 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 12117 | if (!container) |
| 12118 | return -1; |
| 12119 | |
| 12120 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12121 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 12122 | params->auto_plinks)) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12123 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) && |
| 12124 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 12125 | params->forwarding)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 12126 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 12127 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12128 | params->max_peer_links)) || |
| 12129 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 12130 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 12131 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 12132 | return -1; |
| 12133 | |
| 12134 | /* |
| 12135 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 12136 | * the timer could disconnect stations even in that case. |
| 12137 | */ |
| 12138 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 12139 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 12140 | params->peer_link_timeout)) { |
| 12141 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 12142 | return -1; |
| 12143 | } |
| 12144 | |
| 12145 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 12146 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 12147 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 12148 | return -1; |
| 12149 | } |
| 12150 | |
| 12151 | nla_nest_end(msg, container); |
| 12152 | |
| 12153 | return 0; |
| 12154 | } |
| 12155 | |
| 12156 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12157 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12158 | struct wpa_driver_mesh_join_params *params) |
| 12159 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12160 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12161 | struct nl_msg *msg; |
| 12162 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 12163 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12164 | |
| 12165 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 12166 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 12167 | if (!msg || |
| 12168 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 12169 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 12170 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12171 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 12172 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12173 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12174 | |
| 12175 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 12176 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12177 | if (params->handle_dfs && nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS)) |
| 12178 | goto fail; |
| 12179 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12180 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 12181 | if (!container) |
| 12182 | goto fail; |
| 12183 | |
| 12184 | if (params->ies) { |
| 12185 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 12186 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 12187 | params->ies)) |
| 12188 | goto fail; |
| 12189 | } |
| 12190 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 12191 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 12192 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 12193 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 12194 | goto fail; |
| 12195 | } |
| 12196 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 12197 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 12198 | goto fail; |
| 12199 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 12200 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 12201 | goto fail; |
| 12202 | nla_nest_end(msg, container); |
| 12203 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 12204 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 12205 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 12206 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 12207 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12208 | goto fail; |
| 12209 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12210 | if (nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER)) |
| 12211 | return -1; |
| 12212 | ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL, |
| 12213 | NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12214 | msg = NULL; |
| 12215 | if (ret) { |
| 12216 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 12217 | ret, strerror(-ret)); |
| 12218 | goto fail; |
| 12219 | } |
| 12220 | ret = 0; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 12221 | drv->assoc_freq = bss->flink->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12222 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 12223 | |
| 12224 | fail: |
| 12225 | nlmsg_free(msg); |
| 12226 | return ret; |
| 12227 | } |
| 12228 | |
| 12229 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12230 | static int |
| 12231 | wpa_driver_nl80211_join_mesh(void *priv, |
| 12232 | struct wpa_driver_mesh_join_params *params) |
| 12233 | { |
| 12234 | struct i802_bss *bss = priv; |
| 12235 | int ret, timeout; |
| 12236 | |
| 12237 | timeout = params->conf.peer_link_timeout; |
| 12238 | |
| 12239 | /* Disable kernel inactivity timer */ |
| 12240 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 12241 | params->conf.peer_link_timeout = 0; |
| 12242 | |
| 12243 | ret = nl80211_join_mesh(bss, params); |
| 12244 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 12245 | wpa_printf(MSG_DEBUG, |
| 12246 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 12247 | /* |
| 12248 | * Old kernel does not support setting |
| 12249 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 12250 | * into future from peer_link_timeout. |
| 12251 | */ |
| 12252 | params->conf.peer_link_timeout = timeout + 60; |
| 12253 | ret = nl80211_join_mesh(priv, params); |
| 12254 | } |
| 12255 | |
| 12256 | params->conf.peer_link_timeout = timeout; |
| 12257 | return ret; |
| 12258 | } |
| 12259 | |
| 12260 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12261 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 12262 | { |
| 12263 | struct i802_bss *bss = priv; |
| 12264 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12265 | struct nl_msg *msg; |
| 12266 | int ret; |
| 12267 | |
| 12268 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 12269 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12270 | ret = send_and_recv(drv->global, bss->nl_connect, msg, NULL, NULL, NULL, |
| 12271 | NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12272 | if (ret) { |
| 12273 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 12274 | ret, strerror(-ret)); |
| 12275 | } else { |
| 12276 | wpa_printf(MSG_DEBUG, |
| 12277 | "nl80211: mesh leave request send successfully"); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 12278 | drv->first_bss->flink->freq = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12279 | } |
| 12280 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12281 | if (drv->start_mode_sta && |
| 12282 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12283 | NL80211_IFTYPE_STATION)) { |
| 12284 | wpa_printf(MSG_INFO, |
| 12285 | "nl80211: Failed to set interface into station mode"); |
| 12286 | } |
| 12287 | return ret; |
| 12288 | } |
| 12289 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12290 | |
| 12291 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 12292 | size_t len) |
| 12293 | { |
| 12294 | struct i802_bss *bss = priv; |
| 12295 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12296 | struct nl_msg *msg; |
| 12297 | int ret; |
| 12298 | |
| 12299 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 12300 | if (!msg || |
| 12301 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12302 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 12303 | nlmsg_free(msg); |
| 12304 | return -ENOBUFS; |
| 12305 | } |
| 12306 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12307 | ret = send_and_recv_cmd(drv, msg); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12308 | if (ret) { |
| 12309 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 12310 | " failed: ret=%d (%s)", |
| 12311 | MAC2STR(addr), ret, strerror(-ret)); |
| 12312 | } else { |
| 12313 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 12314 | " probed successfully", MAC2STR(addr)); |
| 12315 | } |
| 12316 | |
| 12317 | return ret; |
| 12318 | } |
| 12319 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12320 | #endif /* CONFIG_MESH */ |
| 12321 | |
| 12322 | |
| 12323 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 12324 | const u8 *ipaddr, int prefixlen, |
| 12325 | const u8 *addr) |
| 12326 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12327 | struct i802_bss *bss = priv; |
| 12328 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12329 | struct ndmsg nhdr = { |
| 12330 | .ndm_state = NUD_PERMANENT, |
| 12331 | .ndm_ifindex = bss->br_ifindex, |
| 12332 | }; |
| 12333 | struct nl_msg *msg; |
| 12334 | int addrsize; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12335 | int res; |
| 12336 | |
| 12337 | if (!ipaddr || prefixlen == 0 || !addr) |
| 12338 | return -EINVAL; |
| 12339 | |
| 12340 | if (bss->br_ifindex == 0) { |
| 12341 | wpa_printf(MSG_DEBUG, |
| 12342 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 12343 | return -1; |
| 12344 | } |
| 12345 | |
| 12346 | if (!drv->rtnl_sk) { |
| 12347 | wpa_printf(MSG_DEBUG, |
| 12348 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 12349 | return -1; |
| 12350 | } |
| 12351 | |
| 12352 | if (version == 4) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12353 | nhdr.ndm_family = AF_INET; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12354 | addrsize = 4; |
| 12355 | } else if (version == 6) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12356 | nhdr.ndm_family = AF_INET6; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12357 | addrsize = 16; |
| 12358 | } else { |
| 12359 | return -EINVAL; |
| 12360 | } |
| 12361 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12362 | msg = nlmsg_alloc_simple(RTM_NEWNEIGH, NLM_F_CREATE); |
| 12363 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12364 | return -ENOMEM; |
| 12365 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12366 | res = -ENOMEM; |
| 12367 | if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0 || |
| 12368 | nla_put(msg, NDA_DST, addrsize, (void *) ipaddr) || |
| 12369 | nla_put(msg, NDA_LLADDR, ETH_ALEN, (void *) addr)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12370 | goto errout; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12371 | |
| 12372 | res = nl_send_auto_complete(drv->rtnl_sk, msg); |
| 12373 | if (res < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12374 | goto errout; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12375 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12376 | res = nl_wait_for_ack(drv->rtnl_sk); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12377 | if (res) { |
| 12378 | wpa_printf(MSG_DEBUG, |
| 12379 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12380 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12381 | } |
| 12382 | errout: |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12383 | nlmsg_free(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12384 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12385 | } |
| 12386 | |
| 12387 | |
| 12388 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 12389 | const u8 *ipaddr) |
| 12390 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12391 | struct i802_bss *bss = priv; |
| 12392 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12393 | struct ndmsg nhdr = { |
| 12394 | .ndm_state = NUD_PERMANENT, |
| 12395 | .ndm_ifindex = bss->br_ifindex, |
| 12396 | }; |
| 12397 | struct nl_msg *msg; |
| 12398 | int addrsize; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12399 | int res; |
| 12400 | |
| 12401 | if (!ipaddr) |
| 12402 | return -EINVAL; |
| 12403 | |
| 12404 | if (version == 4) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12405 | nhdr.ndm_family = AF_INET; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12406 | addrsize = 4; |
| 12407 | } else if (version == 6) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12408 | nhdr.ndm_family = AF_INET6; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12409 | addrsize = 16; |
| 12410 | } else { |
| 12411 | return -EINVAL; |
| 12412 | } |
| 12413 | |
| 12414 | if (bss->br_ifindex == 0) { |
| 12415 | wpa_printf(MSG_DEBUG, |
| 12416 | "nl80211: bridge must be set to delete an ip neigh"); |
| 12417 | return -1; |
| 12418 | } |
| 12419 | |
| 12420 | if (!drv->rtnl_sk) { |
| 12421 | wpa_printf(MSG_DEBUG, |
| 12422 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 12423 | return -1; |
| 12424 | } |
| 12425 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12426 | msg = nlmsg_alloc_simple(RTM_DELNEIGH, NLM_F_CREATE); |
| 12427 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12428 | return -ENOMEM; |
| 12429 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12430 | res = -ENOMEM; |
| 12431 | if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0 || |
| 12432 | nla_put(msg, NDA_DST, addrsize, (void *) ipaddr)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12433 | goto errout; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12434 | |
| 12435 | res = nl_send_auto_complete(drv->rtnl_sk, msg); |
| 12436 | if (res < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12437 | goto errout; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12438 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12439 | res = nl_wait_for_ack(drv->rtnl_sk); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12440 | if (res) { |
| 12441 | wpa_printf(MSG_DEBUG, |
| 12442 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12443 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12444 | } |
| 12445 | errout: |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12446 | nlmsg_free(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12447 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12448 | } |
| 12449 | |
| 12450 | |
| 12451 | static int linux_write_system_file(const char *path, unsigned int val) |
| 12452 | { |
| 12453 | char buf[50]; |
| 12454 | int fd, len; |
| 12455 | |
| 12456 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 12457 | if (os_snprintf_error(sizeof(buf), len)) |
| 12458 | return -1; |
| 12459 | |
| 12460 | fd = open(path, O_WRONLY); |
| 12461 | if (fd < 0) |
| 12462 | return -1; |
| 12463 | |
| 12464 | if (write(fd, buf, len) < 0) { |
| 12465 | wpa_printf(MSG_DEBUG, |
| 12466 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 12467 | path, val); |
| 12468 | close(fd); |
| 12469 | return -1; |
| 12470 | } |
| 12471 | close(fd); |
| 12472 | |
| 12473 | return 0; |
| 12474 | } |
| 12475 | |
| 12476 | |
| 12477 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 12478 | { |
| 12479 | switch (attr) { |
| 12480 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 12481 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12482 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 12483 | return "hairpin_mode"; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 12484 | case DRV_BR_PORT_ATTR_MCAST2UCAST: |
| 12485 | return "multicast_to_unicast"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12486 | } |
| 12487 | |
| 12488 | return NULL; |
| 12489 | } |
| 12490 | |
| 12491 | |
| 12492 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 12493 | unsigned int val) |
| 12494 | { |
| 12495 | struct i802_bss *bss = priv; |
| 12496 | char path[128]; |
| 12497 | const char *attr_txt; |
| 12498 | |
| 12499 | attr_txt = drv_br_port_attr_str(attr); |
| 12500 | if (attr_txt == NULL) |
| 12501 | return -EINVAL; |
| 12502 | |
| 12503 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 12504 | bss->ifname, attr_txt); |
| 12505 | |
| 12506 | if (linux_write_system_file(path, val)) |
| 12507 | return -1; |
| 12508 | |
| 12509 | return 0; |
| 12510 | } |
| 12511 | |
| 12512 | |
| 12513 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 12514 | { |
| 12515 | switch (param) { |
| 12516 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 12517 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12518 | default: |
| 12519 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12520 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12521 | } |
| 12522 | |
| 12523 | |
| 12524 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 12525 | unsigned int val) |
| 12526 | { |
| 12527 | struct i802_bss *bss = priv; |
| 12528 | char path[128]; |
| 12529 | const char *param_txt; |
| 12530 | int ip_version = 4; |
| 12531 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12532 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 12533 | os_snprintf(path, sizeof(path), |
| 12534 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 12535 | bss->brname); |
| 12536 | goto set_val; |
| 12537 | } |
| 12538 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12539 | param_txt = drv_br_net_param_str(param); |
| 12540 | if (param_txt == NULL) |
| 12541 | return -EINVAL; |
| 12542 | |
| 12543 | switch (param) { |
| 12544 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 12545 | ip_version = 4; |
| 12546 | break; |
| 12547 | default: |
| 12548 | return -EINVAL; |
| 12549 | } |
| 12550 | |
| 12551 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 12552 | ip_version, bss->brname, param_txt); |
| 12553 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12554 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12555 | if (linux_write_system_file(path, val)) |
| 12556 | return -1; |
| 12557 | |
| 12558 | return 0; |
| 12559 | } |
| 12560 | |
| 12561 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12562 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 12563 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12564 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 12565 | { |
| 12566 | switch (hw_mode) { |
| 12567 | case HOSTAPD_MODE_IEEE80211B: |
| 12568 | return QCA_ACS_MODE_IEEE80211B; |
| 12569 | case HOSTAPD_MODE_IEEE80211G: |
| 12570 | return QCA_ACS_MODE_IEEE80211G; |
| 12571 | case HOSTAPD_MODE_IEEE80211A: |
| 12572 | return QCA_ACS_MODE_IEEE80211A; |
| 12573 | case HOSTAPD_MODE_IEEE80211AD: |
| 12574 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 12575 | case HOSTAPD_MODE_IEEE80211ANY: |
| 12576 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12577 | default: |
| 12578 | return -1; |
| 12579 | } |
| 12580 | } |
| 12581 | |
| 12582 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12583 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 12584 | { |
| 12585 | int num_channels = 0, num_freqs; |
| 12586 | u8 *ch_list; |
| 12587 | enum hostapd_hw_mode hw_mode; |
| 12588 | int ret = 0; |
| 12589 | int i; |
| 12590 | |
| 12591 | if (!freq_list) |
| 12592 | return 0; |
| 12593 | |
| 12594 | num_freqs = int_array_len(freq_list); |
| 12595 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 12596 | if (!ch_list) |
| 12597 | return -1; |
| 12598 | |
| 12599 | for (i = 0; i < num_freqs; i++) { |
| 12600 | const int freq = freq_list[i]; |
| 12601 | |
| 12602 | if (freq == 0) |
| 12603 | break; |
| 12604 | /* Send 2.4 GHz and 5 GHz channels with |
| 12605 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 12606 | * compatibility. |
| 12607 | */ |
| 12608 | if (!(freq >= 2412 && freq <= 2484) && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12609 | !(freq >= 5180 && freq <= 5900) && |
| 12610 | !(freq >= 5945 && freq <= 7115)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12611 | continue; |
| 12612 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 12613 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 12614 | num_channels++; |
| 12615 | } |
| 12616 | |
| 12617 | if (num_channels) |
| 12618 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 12619 | num_channels, ch_list); |
| 12620 | |
| 12621 | os_free(ch_list); |
| 12622 | return ret; |
| 12623 | } |
| 12624 | |
| 12625 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12626 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 12627 | { |
| 12628 | int i, len, ret; |
| 12629 | u32 *freqs; |
| 12630 | |
| 12631 | if (!freq_list) |
| 12632 | return 0; |
| 12633 | len = int_array_len(freq_list); |
| 12634 | freqs = os_malloc(sizeof(u32) * len); |
| 12635 | if (!freqs) |
| 12636 | return -1; |
| 12637 | for (i = 0; i < len; i++) |
| 12638 | freqs[i] = freq_list[i]; |
| 12639 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 12640 | sizeof(u32) * len, freqs); |
| 12641 | os_free(freqs); |
| 12642 | return ret; |
| 12643 | } |
| 12644 | |
| 12645 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12646 | static int nl80211_qca_do_acs(struct wpa_driver_nl80211_data *drv, |
| 12647 | struct drv_acs_params *params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12648 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12649 | struct nl_msg *msg; |
| 12650 | struct nlattr *data; |
| 12651 | int ret; |
| 12652 | int mode; |
| 12653 | |
| 12654 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 12655 | if (mode < 0) |
| 12656 | return -1; |
| 12657 | |
| 12658 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12659 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12660 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12661 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 12662 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12663 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 12664 | (params->ht_enabled && |
| 12665 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 12666 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 12667 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 12668 | (params->vht_enabled && |
| 12669 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12670 | (params->eht_enabled && |
| 12671 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EHT_ENABLED)) || |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 12672 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 12673 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12674 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12675 | add_acs_freq_list(msg, params->freq_list) || |
| 12676 | (params->edmg_enabled && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12677 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED)) || |
| 12678 | (params->link_id != NL80211_DRV_LINK_ID_NA && |
| 12679 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_LINK_ID, |
| 12680 | params->link_id))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12681 | nlmsg_free(msg); |
| 12682 | return -ENOBUFS; |
| 12683 | } |
| 12684 | nla_nest_end(msg, data); |
| 12685 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 12686 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12687 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d EHT: %d BW: %d EDMG: %d, link_id: %d", |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 12688 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12689 | params->vht_enabled, params->eht_enabled, params->ch_width, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12690 | params->edmg_enabled, params->link_id); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 12691 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12692 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12693 | if (ret) { |
| 12694 | wpa_printf(MSG_DEBUG, |
| 12695 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12696 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12697 | } |
| 12698 | return ret; |
| 12699 | } |
| 12700 | |
| 12701 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12702 | static int nl80211_set_band(void *priv, u32 band_mask) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12703 | { |
| 12704 | struct i802_bss *bss = priv; |
| 12705 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12706 | struct nl_msg *msg; |
| 12707 | struct nlattr *data; |
| 12708 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12709 | enum qca_set_band qca_band_value; |
| 12710 | u32 qca_band_mask = QCA_SETBAND_AUTO; |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12711 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12712 | if (!drv->setband_vendor_cmd_avail || |
| 12713 | (band_mask > (WPA_SETBAND_2G | WPA_SETBAND_5G | WPA_SETBAND_6G))) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12714 | return -1; |
| 12715 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12716 | if (band_mask & WPA_SETBAND_5G) |
| 12717 | qca_band_mask |= QCA_SETBAND_5G; |
| 12718 | if (band_mask & WPA_SETBAND_2G) |
| 12719 | qca_band_mask |= QCA_SETBAND_2G; |
| 12720 | if (band_mask & WPA_SETBAND_6G) |
| 12721 | qca_band_mask |= QCA_SETBAND_6G; |
| 12722 | |
| 12723 | /* |
| 12724 | * QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE is a legacy interface hence make |
| 12725 | * it suite to its values (AUTO/5G/2G) for backwards compatibility. |
| 12726 | */ |
| 12727 | qca_band_value = ((qca_band_mask & QCA_SETBAND_5G) && |
| 12728 | (qca_band_mask & QCA_SETBAND_2G)) ? |
| 12729 | QCA_SETBAND_AUTO : |
| 12730 | qca_band_mask & ~QCA_SETBAND_6G; |
| 12731 | |
| 12732 | wpa_printf(MSG_DEBUG, |
| 12733 | "nl80211: QCA_BAND_MASK = 0x%x, QCA_BAND_VALUE = %d", |
| 12734 | qca_band_mask, qca_band_value); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12735 | |
| 12736 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12737 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12738 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12739 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 12740 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12741 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, |
| 12742 | qca_band_value) || |
| 12743 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_MASK, |
| 12744 | qca_band_mask)) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12745 | nlmsg_free(msg); |
| 12746 | return -ENOBUFS; |
| 12747 | } |
| 12748 | nla_nest_end(msg, data); |
| 12749 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12750 | ret = send_and_recv_cmd(drv, msg); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12751 | if (ret) { |
| 12752 | wpa_printf(MSG_DEBUG, |
| 12753 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12754 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12755 | } |
| 12756 | return ret; |
| 12757 | } |
| 12758 | |
| 12759 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12760 | struct nl80211_pcl { |
| 12761 | unsigned int num; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12762 | struct weighted_pcl *freq_list; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12763 | }; |
| 12764 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12765 | static void get_pcl_attr_values(struct weighted_pcl *wpcl, struct nlattr *nl[]) |
| 12766 | { |
| 12767 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]) |
| 12768 | wpcl->freq = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]); |
| 12769 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]) |
| 12770 | wpcl->weight = nla_get_u8(nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]); |
| 12771 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]) { |
| 12772 | u32 flags = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]); |
| 12773 | |
| 12774 | wpcl->flag = 0; |
| 12775 | if (flags & BIT(0)) |
| 12776 | wpcl->flag |= WEIGHTED_PCL_GO; |
| 12777 | if (flags & BIT(1)) |
| 12778 | wpcl->flag |= WEIGHTED_PCL_CLI; |
| 12779 | if (flags & BIT(2)) |
| 12780 | wpcl->flag |= WEIGHTED_PCL_MUST_CONSIDER; |
| 12781 | if (flags & BIT(3)) |
| 12782 | wpcl->flag |= WEIGHTED_PCL_EXCLUDE; |
| 12783 | } else { |
| 12784 | wpcl->flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 12785 | } |
| 12786 | } |
| 12787 | |
| 12788 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12789 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 12790 | { |
| 12791 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 12792 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 12793 | struct nl80211_pcl *param = arg; |
| 12794 | struct nlattr *nl_vend, *attr; |
| 12795 | enum qca_iface_type iface_type; |
| 12796 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12797 | struct nlattr *nl_pcl[QCA_WLAN_VENDOR_ATTR_PCL_MAX + 1]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12798 | unsigned int num, max_num; |
| 12799 | u32 *freqs; |
| 12800 | |
| 12801 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 12802 | genlmsg_attrlen(gnlh, 0), NULL); |
| 12803 | |
| 12804 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 12805 | if (!nl_vend) |
| 12806 | return NL_SKIP; |
| 12807 | |
| 12808 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 12809 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 12810 | |
| 12811 | attr = tb_vendor[ |
| 12812 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 12813 | if (!attr) { |
| 12814 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 12815 | param->num = 0; |
| 12816 | return NL_SKIP; |
| 12817 | } |
| 12818 | |
| 12819 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 12820 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 12821 | iface_type); |
| 12822 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12823 | attr = tb_vendor[ |
| 12824 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_WEIGHED_PCL]; |
| 12825 | if (attr) { |
| 12826 | int rem; |
| 12827 | struct nlattr *wpcl = attr; |
| 12828 | unsigned int i; |
| 12829 | |
| 12830 | num = 0; |
| 12831 | nla_for_each_nested(attr, wpcl, rem) { |
| 12832 | if (num == param->num) |
| 12833 | break; /* not enough room for all entries */ |
| 12834 | if (nla_parse(nl_pcl, QCA_WLAN_VENDOR_ATTR_PCL_MAX, |
| 12835 | nla_data(attr), nla_len(attr), NULL)) { |
| 12836 | wpa_printf(MSG_ERROR, |
| 12837 | "nl80211: Failed to parse PCL info"); |
| 12838 | param->num = 0; |
| 12839 | return NL_SKIP; |
| 12840 | } |
| 12841 | get_pcl_attr_values(¶m->freq_list[num], nl_pcl); |
| 12842 | num++; |
| 12843 | } |
| 12844 | param->num = num; |
| 12845 | |
| 12846 | /* Sort frequencies based on their weight */ |
| 12847 | for (i = 0; i < num; i++) { |
| 12848 | unsigned int j; |
| 12849 | |
| 12850 | for (j = i + 1; j < num; j++) { |
| 12851 | if (param->freq_list[i].weight < |
| 12852 | param->freq_list[j].weight) { |
| 12853 | struct weighted_pcl tmp; |
| 12854 | |
| 12855 | tmp = param->freq_list[i]; |
| 12856 | param->freq_list[i] = |
| 12857 | param->freq_list[j]; |
| 12858 | param->freq_list[j] = tmp; |
| 12859 | } |
| 12860 | } |
| 12861 | } |
| 12862 | } else if (tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]) { |
| 12863 | wpa_printf(MSG_DEBUG, |
| 12864 | "nl80211: Driver does not provide weighted PCL; use the non-weighted variant"); |
| 12865 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 12866 | /* |
| 12867 | * param->num has the maximum number of entries for which there |
| 12868 | * is room in the freq_list provided by the caller. |
| 12869 | */ |
| 12870 | freqs = nla_data(attr); |
| 12871 | max_num = nla_len(attr) / sizeof(u32); |
| 12872 | if (max_num > param->num) |
| 12873 | max_num = param->num; |
| 12874 | for (num = 0; num < max_num; num++) { |
| 12875 | param->freq_list[num].freq = freqs[num]; |
| 12876 | param->freq_list[num].flag = |
| 12877 | WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 12878 | } |
| 12879 | param->num = num; |
| 12880 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12881 | wpa_printf(MSG_ERROR, |
| 12882 | "nl80211: preferred_freq_list couldn't be found"); |
| 12883 | param->num = 0; |
| 12884 | return NL_SKIP; |
| 12885 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12886 | return NL_SKIP; |
| 12887 | } |
| 12888 | |
| 12889 | |
| 12890 | static int nl80211_get_pref_freq_list(void *priv, |
| 12891 | enum wpa_driver_if_type if_type, |
| 12892 | unsigned int *num, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12893 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12894 | { |
| 12895 | struct i802_bss *bss = priv; |
| 12896 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12897 | struct nl_msg *msg; |
| 12898 | int ret; |
| 12899 | unsigned int i; |
| 12900 | struct nlattr *params; |
| 12901 | struct nl80211_pcl param; |
| 12902 | enum qca_iface_type iface_type; |
| 12903 | |
| 12904 | if (!drv->get_pref_freq_list) |
| 12905 | return -1; |
| 12906 | |
| 12907 | switch (if_type) { |
| 12908 | case WPA_IF_STATION: |
| 12909 | iface_type = QCA_IFACE_TYPE_STA; |
| 12910 | break; |
| 12911 | case WPA_IF_AP_BSS: |
| 12912 | iface_type = QCA_IFACE_TYPE_AP; |
| 12913 | break; |
| 12914 | case WPA_IF_P2P_GO: |
| 12915 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 12916 | break; |
| 12917 | case WPA_IF_P2P_CLIENT: |
| 12918 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 12919 | break; |
| 12920 | case WPA_IF_IBSS: |
| 12921 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 12922 | break; |
| 12923 | case WPA_IF_TDLS: |
| 12924 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 12925 | break; |
| 12926 | default: |
| 12927 | return -1; |
| 12928 | } |
| 12929 | |
| 12930 | param.num = *num; |
| 12931 | param.freq_list = freq_list; |
| 12932 | |
| 12933 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12934 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 12935 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12936 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12937 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 12938 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12939 | nla_put_u32(msg, |
| 12940 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 12941 | iface_type)) { |
| 12942 | wpa_printf(MSG_ERROR, |
| 12943 | "%s: err in adding vendor_cmd and vendor_data", |
| 12944 | __func__); |
| 12945 | nlmsg_free(msg); |
| 12946 | return -1; |
| 12947 | } |
| 12948 | nla_nest_end(msg, params); |
| 12949 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12950 | if (freq_list) |
| 12951 | os_memset(freq_list, 0, *num * sizeof(struct weighted_pcl)); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12952 | ret = send_and_recv_resp(drv, msg, preferred_freq_info_handler, ¶m); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12953 | if (ret) { |
| 12954 | wpa_printf(MSG_ERROR, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 12955 | "%s: err in send_and_recv_resp", __func__); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12956 | return ret; |
| 12957 | } |
| 12958 | |
| 12959 | *num = param.num; |
| 12960 | |
| 12961 | for (i = 0; i < *num; i++) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12962 | wpa_printf(MSG_DEBUG, |
| 12963 | "nl80211: preferred_channel_list[%d]=%d[%d]:0x%x", |
| 12964 | i, freq_list[i].freq, freq_list[i].weight, |
| 12965 | freq_list[i].flag); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12966 | } |
| 12967 | |
| 12968 | return 0; |
| 12969 | } |
| 12970 | |
| 12971 | |
| 12972 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 12973 | { |
| 12974 | struct i802_bss *bss = priv; |
| 12975 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12976 | struct nl_msg *msg; |
| 12977 | int ret; |
| 12978 | struct nlattr *params; |
| 12979 | |
| 12980 | if (!drv->set_prob_oper_freq) |
| 12981 | return -1; |
| 12982 | |
| 12983 | wpa_printf(MSG_DEBUG, |
| 12984 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 12985 | freq, bss->ifindex); |
| 12986 | |
| 12987 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12988 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12989 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12990 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 12991 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12992 | nla_put_u32(msg, |
| 12993 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 12994 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 12995 | nla_put_u32(msg, |
| 12996 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 12997 | freq)) { |
| 12998 | wpa_printf(MSG_ERROR, |
| 12999 | "%s: err in adding vendor_cmd and vendor_data", |
| 13000 | __func__); |
| 13001 | nlmsg_free(msg); |
| 13002 | return -1; |
| 13003 | } |
| 13004 | nla_nest_end(msg, params); |
| 13005 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13006 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13007 | msg = NULL; |
| 13008 | if (ret) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13009 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_cmd", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13010 | __func__); |
| 13011 | return ret; |
| 13012 | } |
| 13013 | nlmsg_free(msg); |
| 13014 | return 0; |
| 13015 | } |
| 13016 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13017 | |
| 13018 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 13019 | unsigned int period, unsigned int interval, |
| 13020 | unsigned int count, const u8 *device_types, |
| 13021 | size_t dev_types_len, |
| 13022 | const u8 *ies, size_t ies_len) |
| 13023 | { |
| 13024 | struct i802_bss *bss = priv; |
| 13025 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13026 | struct nl_msg *msg; |
| 13027 | struct nlattr *container; |
| 13028 | int ret; |
| 13029 | |
| 13030 | wpa_printf(MSG_DEBUG, |
| 13031 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 13032 | freq, period, interval, count); |
| 13033 | |
| 13034 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 13035 | return -1; |
| 13036 | |
| 13037 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13038 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13039 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13040 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 13041 | goto fail; |
| 13042 | |
| 13043 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13044 | if (!container) |
| 13045 | goto fail; |
| 13046 | |
| 13047 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 13048 | freq) || |
| 13049 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 13050 | period) || |
| 13051 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 13052 | interval) || |
| 13053 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 13054 | count) || |
| 13055 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 13056 | dev_types_len, device_types) || |
| 13057 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 13058 | ies_len, ies)) |
| 13059 | goto fail; |
| 13060 | |
| 13061 | nla_nest_end(msg, container); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13062 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13063 | msg = NULL; |
| 13064 | if (ret) { |
| 13065 | wpa_printf(MSG_DEBUG, |
| 13066 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 13067 | goto fail; |
| 13068 | } |
| 13069 | |
| 13070 | return 0; |
| 13071 | |
| 13072 | fail: |
| 13073 | nlmsg_free(msg); |
| 13074 | return -1; |
| 13075 | } |
| 13076 | |
| 13077 | |
| 13078 | static int nl80211_p2p_lo_stop(void *priv) |
| 13079 | { |
| 13080 | struct i802_bss *bss = priv; |
| 13081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13082 | struct nl_msg *msg; |
| 13083 | |
| 13084 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 13085 | |
| 13086 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 13087 | return -1; |
| 13088 | |
| 13089 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13090 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13091 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13092 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 13093 | nlmsg_free(msg); |
| 13094 | return -1; |
| 13095 | } |
| 13096 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13097 | return send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13098 | } |
| 13099 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 13100 | |
| 13101 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 13102 | { |
| 13103 | struct i802_bss *bss = priv; |
| 13104 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13105 | struct nl_msg *msg; |
| 13106 | struct nlattr *params; |
| 13107 | int ret; |
| 13108 | u32 tdls_mode; |
| 13109 | |
| 13110 | wpa_printf(MSG_DEBUG, |
| 13111 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 13112 | tdls_external_control); |
| 13113 | |
| 13114 | if (tdls_external_control == 1) |
| 13115 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 13116 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 13117 | else |
| 13118 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 13119 | |
| 13120 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13121 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13122 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13123 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 13124 | goto fail; |
| 13125 | |
| 13126 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13127 | if (!params) |
| 13128 | goto fail; |
| 13129 | |
| 13130 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 13131 | tdls_mode)) |
| 13132 | goto fail; |
| 13133 | |
| 13134 | nla_nest_end(msg, params); |
| 13135 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13136 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 13137 | msg = NULL; |
| 13138 | if (ret) { |
| 13139 | wpa_printf(MSG_ERROR, |
| 13140 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 13141 | ret, strerror(-ret)); |
| 13142 | goto fail; |
| 13143 | } |
| 13144 | return 0; |
| 13145 | fail: |
| 13146 | nlmsg_free(msg); |
| 13147 | return -1; |
| 13148 | } |
| 13149 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13150 | |
| 13151 | #ifdef CONFIG_MBO |
| 13152 | |
| 13153 | static enum mbo_transition_reject_reason |
| 13154 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 13155 | { |
| 13156 | switch (status) { |
| 13157 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 13158 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 13159 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 13160 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 13161 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 13162 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 13163 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 13164 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 13165 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 13166 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 13167 | case QCA_STATUS_REJECT_UNKNOWN: |
| 13168 | default: |
| 13169 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 13170 | } |
| 13171 | } |
| 13172 | |
| 13173 | |
| 13174 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 13175 | struct nlattr *tb[], int num) |
| 13176 | { |
| 13177 | enum qca_wlan_btm_candidate_status status; |
| 13178 | char buf[50]; |
| 13179 | |
| 13180 | os_memcpy(candidate->bssid, |
| 13181 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 13182 | ETH_ALEN); |
| 13183 | |
| 13184 | status = nla_get_u32( |
| 13185 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 13186 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 13187 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 13188 | |
| 13189 | if (candidate->is_accept) |
| 13190 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 13191 | else |
| 13192 | os_snprintf(buf, sizeof(buf), |
| 13193 | "Rejected, Reject_reason: %d", |
| 13194 | candidate->reject_reason); |
| 13195 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 13196 | num, MAC2STR(candidate->bssid), buf); |
| 13197 | } |
| 13198 | |
| 13199 | |
| 13200 | static int |
| 13201 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 13202 | { |
| 13203 | struct wpa_bss_candidate_info *info = arg; |
| 13204 | struct candidate_list *candidate = info->candidates; |
| 13205 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 13206 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 13207 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 13208 | static struct nla_policy policy[ |
| 13209 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 13210 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 13211 | .minlen = ETH_ALEN |
| 13212 | }, |
| 13213 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 13214 | .type = NLA_U32, |
| 13215 | }, |
| 13216 | }; |
| 13217 | struct nlattr *attr; |
| 13218 | int rem; |
| 13219 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 13220 | u8 num; |
| 13221 | |
| 13222 | num = info->num; /* number of candidates sent to driver */ |
| 13223 | info->num = 0; |
| 13224 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 13225 | genlmsg_attrlen(gnlh, 0), NULL); |
| 13226 | |
| 13227 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 13228 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 13229 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 13230 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 13231 | return NL_SKIP; |
| 13232 | |
| 13233 | wpa_printf(MSG_DEBUG, |
| 13234 | "nl80211: WNM Candidate list received from driver"); |
| 13235 | nla_for_each_nested(attr, |
| 13236 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 13237 | rem) { |
| 13238 | if (info->num >= num || |
| 13239 | nla_parse_nested( |
| 13240 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 13241 | attr, policy) || |
| 13242 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 13243 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 13244 | break; |
| 13245 | |
| 13246 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 13247 | |
| 13248 | candidate++; |
| 13249 | info->num++; |
| 13250 | } |
| 13251 | |
| 13252 | return NL_SKIP; |
| 13253 | } |
| 13254 | |
| 13255 | |
| 13256 | static struct wpa_bss_candidate_info * |
| 13257 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 13258 | { |
| 13259 | struct i802_bss *bss = priv; |
| 13260 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13261 | struct nl_msg *msg; |
| 13262 | struct nlattr *attr, *attr1, *attr2; |
| 13263 | struct wpa_bss_candidate_info *info; |
| 13264 | u8 i; |
| 13265 | int ret; |
| 13266 | u8 *pos; |
| 13267 | |
| 13268 | if (!drv->fetch_bss_trans_status) |
| 13269 | return NULL; |
| 13270 | |
| 13271 | info = os_zalloc(sizeof(*info)); |
| 13272 | if (!info) |
| 13273 | return NULL; |
| 13274 | /* Allocate memory for number of candidates sent to driver */ |
| 13275 | info->candidates = os_calloc(params->n_candidates, |
| 13276 | sizeof(*info->candidates)); |
| 13277 | if (!info->candidates) { |
| 13278 | os_free(info); |
| 13279 | return NULL; |
| 13280 | } |
| 13281 | |
| 13282 | /* Copy the number of candidates being sent to driver. This is used in |
| 13283 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 13284 | * candidates that can be populated in info->candidates and will be |
| 13285 | * later overwritten with the actual number of candidates received from |
| 13286 | * the driver. |
| 13287 | */ |
| 13288 | info->num = params->n_candidates; |
| 13289 | |
| 13290 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13291 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13292 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13293 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 13294 | goto fail; |
| 13295 | |
| 13296 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13297 | if (!attr) |
| 13298 | goto fail; |
| 13299 | |
| 13300 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 13301 | params->mbo_transition_reason)) |
| 13302 | goto fail; |
| 13303 | |
| 13304 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 13305 | if (!attr1) |
| 13306 | goto fail; |
| 13307 | |
| 13308 | wpa_printf(MSG_DEBUG, |
| 13309 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 13310 | params->mbo_transition_reason, params->n_candidates); |
| 13311 | pos = params->bssid; |
| 13312 | for (i = 0; i < params->n_candidates; i++) { |
| 13313 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 13314 | MAC2STR(pos)); |
| 13315 | attr2 = nla_nest_start(msg, i); |
| 13316 | if (!attr2 || |
| 13317 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 13318 | ETH_ALEN, pos)) |
| 13319 | goto fail; |
| 13320 | pos += ETH_ALEN; |
| 13321 | nla_nest_end(msg, attr2); |
| 13322 | } |
| 13323 | |
| 13324 | nla_nest_end(msg, attr1); |
| 13325 | nla_nest_end(msg, attr); |
| 13326 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13327 | ret = send_and_recv_resp(drv, msg, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13328 | nl80211_get_bss_transition_status_handler, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13329 | info); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13330 | msg = NULL; |
| 13331 | if (ret) { |
| 13332 | wpa_printf(MSG_ERROR, |
| 13333 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 13334 | ret, strerror(-ret)); |
| 13335 | goto fail; |
| 13336 | } |
| 13337 | return info; |
| 13338 | |
| 13339 | fail: |
| 13340 | nlmsg_free(msg); |
| 13341 | os_free(info->candidates); |
| 13342 | os_free(info); |
| 13343 | return NULL; |
| 13344 | } |
| 13345 | |
| 13346 | |
| 13347 | /** |
| 13348 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 13349 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 13350 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 13351 | * Returns: 0 on success, -1 on failure |
| 13352 | */ |
| 13353 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 13354 | { |
| 13355 | struct i802_bss *bss = priv; |
| 13356 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13357 | struct nl_msg *msg; |
| 13358 | struct nlattr *attr; |
| 13359 | int ret = -1; |
| 13360 | |
| 13361 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 13362 | return -1; |
| 13363 | |
| 13364 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13365 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13366 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13367 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 13368 | goto fail; |
| 13369 | |
| 13370 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13371 | if (!attr) |
| 13372 | goto fail; |
| 13373 | |
| 13374 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 13375 | ignore_disallow); |
| 13376 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 13377 | ignore_disallow)) |
| 13378 | goto fail; |
| 13379 | |
| 13380 | nla_nest_end(msg, attr); |
| 13381 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13382 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13383 | msg = NULL; |
| 13384 | if (ret) { |
| 13385 | wpa_printf(MSG_ERROR, |
| 13386 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 13387 | ret, strerror(-ret)); |
| 13388 | goto fail; |
| 13389 | } |
| 13390 | |
| 13391 | fail: |
| 13392 | nlmsg_free(msg); |
| 13393 | return ret; |
| 13394 | } |
| 13395 | |
| 13396 | #endif /* CONFIG_MBO */ |
| 13397 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13398 | |
| 13399 | #ifdef CONFIG_PASN |
| 13400 | |
| 13401 | static int nl80211_send_pasn_resp(void *priv, struct pasn_auth *params) |
| 13402 | { |
| 13403 | unsigned int i; |
| 13404 | struct i802_bss *bss = priv; |
| 13405 | struct nl_msg *msg = NULL; |
| 13406 | struct nlattr *nlpeers, *attr, *attr1; |
| 13407 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13408 | |
| 13409 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13410 | "nl80211: PASN authentication response for %d entries", |
| 13411 | params->num_peers); |
| 13412 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 13413 | if (!msg || |
| 13414 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13415 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13416 | QCA_NL80211_VENDOR_SUBCMD_PASN)) |
| 13417 | goto fail; |
| 13418 | |
| 13419 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13420 | if (!attr) |
| 13421 | goto fail; |
| 13422 | |
| 13423 | nlpeers = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEERS); |
| 13424 | if (!nlpeers) |
| 13425 | goto fail; |
| 13426 | |
| 13427 | for (i = 0; i < params->num_peers; i++) { |
| 13428 | attr1 = nla_nest_start(msg, i); |
| 13429 | if (!attr1 || |
| 13430 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_SRC_ADDR, |
| 13431 | ETH_ALEN, params->peer[i].own_addr) || |
| 13432 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_MAC_ADDR, |
| 13433 | ETH_ALEN, params->peer[i].peer_addr)) |
| 13434 | goto fail; |
| 13435 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 13436 | if (params->peer[i].status == 0 && |
| 13437 | nla_put_flag(msg, |
| 13438 | QCA_WLAN_VENDOR_ATTR_PASN_PEER_STATUS_SUCCESS)) |
| 13439 | goto fail; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13440 | |
| 13441 | wpa_printf(MSG_DEBUG, |
| 13442 | "nl80211: Own address[%u]: " MACSTR |
| 13443 | " Peer address[%u]: " MACSTR " Status: %s", |
| 13444 | i, MAC2STR(params->peer[i].own_addr), i, |
| 13445 | MAC2STR(params->peer[i].peer_addr), |
| 13446 | params->peer[i].status ? "Fail" : "Success"); |
| 13447 | nla_nest_end(msg, attr1); |
| 13448 | } |
| 13449 | |
| 13450 | nla_nest_end(msg, nlpeers); |
| 13451 | nla_nest_end(msg, attr); |
| 13452 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13453 | return send_and_recv_cmd(drv, msg); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13454 | |
| 13455 | fail: |
| 13456 | nlmsg_free(msg); |
| 13457 | return -1; |
| 13458 | } |
| 13459 | |
| 13460 | |
| 13461 | static u32 wpa_ltf_keyseed_len_to_sha_type(size_t len) |
| 13462 | { |
| 13463 | if (len == SHA384_MAC_LEN) |
| 13464 | return QCA_WLAN_VENDOR_SHA_384; |
| 13465 | if (len == SHA256_MAC_LEN) |
| 13466 | return QCA_WLAN_VENDOR_SHA_256; |
| 13467 | |
| 13468 | wpa_printf(MSG_ERROR, "nl80211: Unexpected LTF keyseed len %zu", len); |
| 13469 | return (u32) -1; |
| 13470 | } |
| 13471 | |
| 13472 | |
| 13473 | static int nl80211_set_secure_ranging_ctx(void *priv, |
| 13474 | struct secure_ranging_params *params) |
| 13475 | { |
| 13476 | int ret; |
| 13477 | u32 suite; |
| 13478 | struct nlattr *attr; |
| 13479 | struct nl_msg *msg = NULL; |
| 13480 | struct i802_bss *bss = priv; |
| 13481 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13482 | |
| 13483 | /* Configure secure ranging context only to the drivers that support it. |
| 13484 | */ |
| 13485 | if (!drv->secure_ranging_ctx_vendor_cmd_avail) |
| 13486 | return 0; |
| 13487 | |
| 13488 | if (!params->peer_addr || !params->own_addr) |
| 13489 | return -1; |
| 13490 | |
| 13491 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13492 | "nl80211: Secure ranging context for " MACSTR, |
| 13493 | MAC2STR(params->peer_addr)); |
| 13494 | |
| 13495 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 13496 | if (!msg || |
| 13497 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 13498 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13499 | QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT)) |
| 13500 | goto fail; |
| 13501 | |
| 13502 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 13503 | if (!attr) |
| 13504 | goto fail; |
| 13505 | |
| 13506 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_PEER_MAC_ADDR, |
| 13507 | ETH_ALEN, params->peer_addr) || |
| 13508 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SRC_ADDR, |
| 13509 | ETH_ALEN, params->own_addr) || |
| 13510 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_ACTION, |
| 13511 | params->action)) |
| 13512 | goto fail; |
| 13513 | |
| 13514 | if (params->cipher) { |
| 13515 | suite = wpa_cipher_to_cipher_suite(params->cipher); |
| 13516 | if (!suite || |
| 13517 | nla_put_u32(msg, |
| 13518 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_CIPHER, |
| 13519 | suite)) |
| 13520 | goto fail; |
| 13521 | } |
| 13522 | |
| 13523 | if (params->tk_len && params->tk) { |
| 13524 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_TK, |
| 13525 | params->tk_len, params->tk)) |
| 13526 | goto fail; |
| 13527 | wpa_hexdump_key(MSG_DEBUG, "nl80211: TK", |
| 13528 | params->tk, params->tk_len); |
| 13529 | } |
| 13530 | |
| 13531 | if (params->ltf_keyseed_len && params->ltf_keyseed) { |
| 13532 | u32 sha_type = wpa_ltf_keyseed_len_to_sha_type( |
| 13533 | params->ltf_keyseed_len); |
| 13534 | |
| 13535 | if (sha_type == (u32) -1 || |
| 13536 | nla_put_u32( |
| 13537 | msg, |
| 13538 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SHA_TYPE, |
| 13539 | sha_type) || |
| 13540 | nla_put(msg, |
| 13541 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_LTF_KEYSEED, |
| 13542 | params->ltf_keyseed_len, params->ltf_keyseed)) |
| 13543 | goto fail; |
| 13544 | wpa_hexdump_key(MSG_DEBUG, "nl80211: LTF keyseed", |
| 13545 | params->ltf_keyseed, params->ltf_keyseed_len); |
| 13546 | } |
| 13547 | nla_nest_end(msg, attr); |
| 13548 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13549 | ret = send_and_recv_cmd(drv, msg); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13550 | if (ret) |
| 13551 | wpa_printf(MSG_DEBUG, |
| 13552 | "nl80211: Set secure ranging context failed: ret=%d (%s)", |
| 13553 | ret, strerror(-ret)); |
| 13554 | return ret; |
| 13555 | fail: |
| 13556 | nlmsg_free(msg); |
| 13557 | return -1; |
| 13558 | } |
| 13559 | |
| 13560 | #endif /* CONFIG_PASN */ |
| 13561 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13562 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 13563 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13564 | |
| 13565 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
| 13566 | static int wpa_driver_do_broadcom_acs(struct wpa_driver_nl80211_data *drv, |
| 13567 | struct drv_acs_params *params) |
| 13568 | { |
| 13569 | struct nl_msg *msg; |
| 13570 | struct nlattr *data; |
| 13571 | int freq_list_len; |
| 13572 | int ret = -1; |
| 13573 | |
| 13574 | freq_list_len = int_array_len(params->freq_list); |
| 13575 | wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d", |
| 13576 | __func__, freq_list_len); |
| 13577 | |
| 13578 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 13579 | if (!msg || |
| 13580 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 13581 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 13582 | BRCM_VENDOR_SCMD_ACS) || |
| 13583 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 13584 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode) || |
| 13585 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED, |
| 13586 | params->ht_enabled) || |
| 13587 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED, |
| 13588 | params->ht40_enabled) || |
| 13589 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED, |
| 13590 | params->vht_enabled) || |
| 13591 | nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width) || |
| 13592 | (freq_list_len > 0 && |
| 13593 | nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST, |
| 13594 | sizeof(int) * freq_list_len, params->freq_list))) |
| 13595 | goto fail; |
| 13596 | nla_nest_end(msg, data); |
| 13597 | |
| 13598 | wpa_printf(MSG_DEBUG, |
| 13599 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d", |
| 13600 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 13601 | params->vht_enabled, params->ch_width); |
| 13602 | |
| 13603 | ret = send_and_recv_cmd(drv, msg); |
| 13604 | if (ret) { |
| 13605 | wpa_printf(MSG_ERROR, |
| 13606 | "nl80211: BRCM Failed to invoke driver ACS function: %s", |
| 13607 | strerror(errno)); |
| 13608 | } |
| 13609 | |
| 13610 | msg = NULL; |
| 13611 | fail: |
| 13612 | nlmsg_free(msg); |
| 13613 | return ret; |
| 13614 | } |
| 13615 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 13616 | |
| 13617 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13618 | static int nl80211_do_acs(void *priv, struct drv_acs_params *params) |
| 13619 | { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 13620 | #if defined(CONFIG_DRIVER_NL80211_QCA) || defined(CONFIG_DRIVER_NL80211_BRCM) \ |
| 13621 | || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13622 | struct i802_bss *bss = priv; |
| 13623 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 13624 | #endif /* CONFIG_DRIVER_NL80211_QCA || CONFIG_DRIVER_NL80211_BRCM \ |
| 13625 | || defined(CONFIG_DRIVER_NL80211_SYNA) */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13626 | |
| 13627 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 13628 | if (drv->qca_do_acs) |
| 13629 | return nl80211_qca_do_acs(drv, params); |
| 13630 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 13631 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 13632 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13633 | if (drv->brcm_do_acs) |
| 13634 | return wpa_driver_do_broadcom_acs(drv, params); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 13635 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13636 | |
| 13637 | return -1; |
| 13638 | } |
| 13639 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13640 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13641 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 13642 | { |
| 13643 | int fd, len; |
| 13644 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13645 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13646 | |
| 13647 | fd = open(name, O_RDWR); |
| 13648 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13649 | int level; |
| 13650 | /* |
| 13651 | * Flags may not exist on older kernels, or while we're tearing |
| 13652 | * down a disappearing device. |
| 13653 | */ |
| 13654 | if (errno == ENOENT) { |
| 13655 | ret = 0; |
| 13656 | level = MSG_DEBUG; |
| 13657 | } else { |
| 13658 | ret = -1; |
| 13659 | level = MSG_ERROR; |
| 13660 | } |
| 13661 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13662 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13663 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13664 | } |
| 13665 | |
| 13666 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 13667 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13668 | if (len < 0) { |
| 13669 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13670 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 13671 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13672 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13673 | close(fd); |
| 13674 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13675 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13676 | } |
| 13677 | |
| 13678 | |
| 13679 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 13680 | { |
| 13681 | struct i802_bss *bss = priv; |
| 13682 | char path[128]; |
| 13683 | int ret; |
| 13684 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 13685 | /* P2P-Device has no netdev that can (or should) be configured here */ |
| 13686 | if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE) |
| 13687 | return 0; |
| 13688 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13689 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 13690 | filter_flags); |
| 13691 | |
| 13692 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 13693 | ret = os_snprintf(path, sizeof(path), |
| 13694 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 13695 | bss->ifname); |
| 13696 | if (os_snprintf_error(sizeof(path), ret)) |
| 13697 | return -1; |
| 13698 | |
| 13699 | ret = nl80211_write_to_file(path, |
| 13700 | !!(filter_flags & |
| 13701 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 13702 | if (ret) { |
| 13703 | wpa_printf(MSG_ERROR, |
| 13704 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 13705 | return ret; |
| 13706 | } |
| 13707 | |
| 13708 | os_snprintf(path, sizeof(path), |
| 13709 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 13710 | bss->ifname); |
| 13711 | ret = nl80211_write_to_file(path, |
| 13712 | !!(filter_flags & |
| 13713 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 13714 | |
| 13715 | if (ret) { |
| 13716 | wpa_printf(MSG_ERROR, |
| 13717 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 13718 | return ret; |
| 13719 | } |
| 13720 | |
| 13721 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 13722 | os_snprintf(path, sizeof(path), |
| 13723 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 13724 | bss->ifname); |
| 13725 | ret = nl80211_write_to_file(path, |
| 13726 | !!(filter_flags & |
| 13727 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 13728 | if (ret) { |
| 13729 | wpa_printf(MSG_ERROR, |
| 13730 | "nl80211: Failed set gratuitous ARP filter"); |
| 13731 | return ret; |
| 13732 | } |
| 13733 | |
| 13734 | /* Configure filtering of IPv6 NA frames */ |
| 13735 | os_snprintf(path, sizeof(path), |
| 13736 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 13737 | bss->ifname); |
| 13738 | ret = nl80211_write_to_file(path, |
| 13739 | !!(filter_flags & |
| 13740 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 13741 | if (ret) { |
| 13742 | wpa_printf(MSG_ERROR, |
| 13743 | "nl80211: Failed to set unsolicited NA filter"); |
| 13744 | return ret; |
| 13745 | } |
| 13746 | |
| 13747 | return 0; |
| 13748 | } |
| 13749 | |
| 13750 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 13751 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 13752 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 13753 | unsigned int *ext_capa_len) |
| 13754 | { |
| 13755 | struct i802_bss *bss = priv; |
| 13756 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13757 | enum nl80211_iftype nlmode; |
| 13758 | unsigned int i; |
| 13759 | |
| 13760 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 13761 | return -1; |
| 13762 | |
| 13763 | nlmode = wpa_driver_nl80211_if_type(type); |
| 13764 | |
| 13765 | /* By default, use the per-radio values */ |
| 13766 | *ext_capa = drv->extended_capa; |
| 13767 | *ext_capa_mask = drv->extended_capa_mask; |
| 13768 | *ext_capa_len = drv->extended_capa_len; |
| 13769 | |
| 13770 | /* Replace the default value if a per-interface type value exists */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 13771 | for (i = 0; i < drv->num_iface_capa; i++) { |
| 13772 | if (nlmode == drv->iface_capa[i].iftype) { |
| 13773 | *ext_capa = drv->iface_capa[i].ext_capa; |
| 13774 | *ext_capa_mask = drv->iface_capa[i].ext_capa_mask; |
| 13775 | *ext_capa_len = drv->iface_capa[i].ext_capa_len; |
| 13776 | break; |
| 13777 | } |
| 13778 | } |
| 13779 | |
| 13780 | return 0; |
| 13781 | } |
| 13782 | |
| 13783 | |
| 13784 | static int nl80211_get_mld_capab(void *priv, enum wpa_driver_if_type type, |
| 13785 | u16 *eml_capa, u16 *mld_capa_and_ops) |
| 13786 | { |
| 13787 | struct i802_bss *bss = priv; |
| 13788 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13789 | enum nl80211_iftype nlmode; |
| 13790 | unsigned int i; |
| 13791 | |
| 13792 | if (!eml_capa || !mld_capa_and_ops) |
| 13793 | return -1; |
| 13794 | |
| 13795 | nlmode = wpa_driver_nl80211_if_type(type); |
| 13796 | |
| 13797 | /* By default, set to zero */ |
| 13798 | *eml_capa = 0; |
| 13799 | *mld_capa_and_ops = 0; |
| 13800 | |
| 13801 | /* Replace the default value if a per-interface type value exists */ |
| 13802 | for (i = 0; i < drv->num_iface_capa; i++) { |
| 13803 | if (nlmode == drv->iface_capa[i].iftype) { |
| 13804 | *eml_capa = drv->iface_capa[i].eml_capa; |
| 13805 | *mld_capa_and_ops = |
| 13806 | drv->iface_capa[i].mld_capa_and_ops; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 13807 | break; |
| 13808 | } |
| 13809 | } |
| 13810 | |
| 13811 | return 0; |
| 13812 | } |
| 13813 | |
| 13814 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13815 | static int nl80211_update_connection_params( |
| 13816 | void *priv, struct wpa_driver_associate_params *params, |
| 13817 | enum wpa_drv_update_connect_params_mask mask) |
| 13818 | { |
| 13819 | struct i802_bss *bss = priv; |
| 13820 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13821 | struct nl_msg *msg; |
| 13822 | int ret = -1; |
| 13823 | enum nl80211_auth_type type; |
| 13824 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13825 | /* Update Connection Params is intended for drivers that implement |
| 13826 | * internal SME and expect these updated connection params from |
| 13827 | * wpa_supplicant. Do not send this request for the drivers using |
| 13828 | * SME from wpa_supplicant. |
| 13829 | */ |
| 13830 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 13831 | return 0; |
| 13832 | |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13833 | /* Handle any connection param update here which might receive kernel handling in future */ |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13834 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13835 | if (mask & WPA_DRV_UPDATE_TD_POLICY) { |
| 13836 | ret = nl80211_set_td_policy(priv, params->td_policy); |
| 13837 | if (ret) { |
| 13838 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13839 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 13840 | ret, strerror(-ret)); |
| 13841 | } |
| 13842 | return ret; |
| 13843 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13844 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13845 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13846 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 13847 | if (!msg) |
| 13848 | goto fail; |
| 13849 | |
| 13850 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 13851 | drv->ifindex); |
| 13852 | |
| 13853 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 13854 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 13855 | params->wpa_ie)) |
| 13856 | goto fail; |
| 13857 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 13858 | params->wpa_ie_len); |
| 13859 | } |
| 13860 | |
| 13861 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 13862 | type = get_nl_auth_type(params->auth_alg); |
| 13863 | if (type == NL80211_AUTHTYPE_MAX || |
| 13864 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 13865 | goto fail; |
| 13866 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 13867 | } |
| 13868 | |
| 13869 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 13870 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 13871 | goto fail; |
| 13872 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13873 | ret = send_and_recv_cmd(drv, msg); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13874 | msg = NULL; |
| 13875 | if (ret) |
| 13876 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13877 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 13878 | ret, strerror(-ret)); |
| 13879 | |
| 13880 | fail: |
| 13881 | nlmsg_free(msg); |
| 13882 | return ret; |
| 13883 | } |
| 13884 | |
| 13885 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13886 | static int nl80211_send_external_auth_status(void *priv, |
| 13887 | struct external_auth *params) |
| 13888 | { |
| 13889 | struct i802_bss *bss = priv; |
| 13890 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13891 | struct nl_msg *msg = NULL; |
| 13892 | int ret = -1; |
| 13893 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13894 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 13895 | * internal SME but want to offload authentication processing (e.g., |
| 13896 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13897 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 13898 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13899 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13900 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 13901 | return -1; |
| 13902 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13903 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13904 | "nl80211: External auth status: %u", params->status); |
| 13905 | |
| 13906 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 13907 | if (!msg || |
| 13908 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13909 | (params->ssid && params->ssid_len && |
| 13910 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 13911 | (params->pmkid && |
| 13912 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 13913 | (params->bssid && |
| 13914 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13915 | goto fail; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13916 | ret = send_and_recv_cmd(drv, msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13917 | msg = NULL; |
| 13918 | if (ret) { |
| 13919 | wpa_printf(MSG_DEBUG, |
| 13920 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 13921 | ret, strerror(-ret)); |
| 13922 | goto fail; |
| 13923 | } |
| 13924 | fail: |
| 13925 | nlmsg_free(msg); |
| 13926 | return ret; |
| 13927 | } |
| 13928 | |
| 13929 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13930 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 13931 | int val) |
| 13932 | { |
| 13933 | struct i802_bss *bss = priv; |
| 13934 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13935 | struct nl_msg *msg; |
| 13936 | int ret = -ENOBUFS; |
| 13937 | |
| 13938 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 13939 | val ? "Enable" : "Disable", bridge_ifname); |
| 13940 | |
| 13941 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 13942 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 13943 | goto fail; |
| 13944 | |
| 13945 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 13946 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 13947 | bridge_ifname, bss->ifname)) { |
| 13948 | wpa_printf(MSG_ERROR, |
| 13949 | "nl80211: Failed to remove interface %s from bridge %s", |
| 13950 | bss->ifname, bridge_ifname); |
| 13951 | return -1; |
| 13952 | } |
| 13953 | bss->added_if_into_bridge = 0; |
| 13954 | } |
| 13955 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 13956 | ret = send_and_recv_cmd(drv, msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13957 | msg = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 13958 | if (ret && val && nl80211_get_4addr(bss) == 1) { |
| 13959 | wpa_printf(MSG_DEBUG, |
| 13960 | "nl80211: 4addr mode was already enabled"); |
| 13961 | ret = 0; |
| 13962 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13963 | if (!ret) { |
| 13964 | if (bridge_ifname[0] && val && |
| 13965 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 13966 | return -1; |
| 13967 | return 0; |
| 13968 | } |
| 13969 | |
| 13970 | fail: |
| 13971 | nlmsg_free(msg); |
| 13972 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 13973 | |
| 13974 | return ret; |
| 13975 | } |
| 13976 | |
| 13977 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 13978 | #ifdef CONFIG_DPP |
| 13979 | static int nl80211_dpp_listen(void *priv, bool enable) |
| 13980 | { |
| 13981 | struct i802_bss *bss = priv; |
| 13982 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13983 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
| 13984 | struct nl_sock *handle; |
| 13985 | |
| 13986 | if (!drv->multicast_registrations || !bss->nl_mgmt) |
| 13987 | return 0; /* cannot do more than hope broadcast RX works */ |
| 13988 | |
| 13989 | wpa_printf(MSG_DEBUG, |
| 13990 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", |
| 13991 | enable ? "enable" : "disable"); |
| 13992 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 13993 | return nl80211_register_frame(bss, handle, type, |
| 13994 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, |
| 13995 | enable); |
| 13996 | } |
| 13997 | #endif /* CONFIG_DPP */ |
| 13998 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13999 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 14000 | static int nl80211_set_td_policy(void *priv, u32 td_policy) |
| 14001 | { |
| 14002 | struct i802_bss *bss = priv; |
| 14003 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 14004 | struct nl_msg *msg; |
| 14005 | int ret; |
| 14006 | struct nlattr *params; |
| 14007 | |
| 14008 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 14009 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 14010 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_SET_TD_POLICY) || |
| 14011 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 14012 | (nla_put_u32(msg, BRCM_ATTR_DRIVER_TD_POLICY, td_policy))) { |
| 14013 | nl80211_nlmsg_clear(msg); |
| 14014 | nlmsg_free(msg); |
| 14015 | return -ENOBUFS; |
| 14016 | } |
| 14017 | nla_nest_end(msg, params); |
| 14018 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable Policy %d\n", td_policy); |
| 14019 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14020 | ret = send_and_recv_cmd(drv, msg); |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 14021 | if (ret) { |
| 14022 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable setting failed: ret=%d (%s)", |
| 14023 | ret, strerror(-ret)); |
| 14024 | } |
| 14025 | |
| 14026 | return ret; |
| 14027 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 14028 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 14029 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14030 | static int nl80211_link_add(void *priv, u8 link_id, const u8 *addr, |
| 14031 | void *bss_ctx) |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14032 | { |
| 14033 | struct i802_bss *bss = priv; |
| 14034 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 14035 | struct nl_msg *msg; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14036 | int ret; |
| 14037 | |
| 14038 | wpa_printf(MSG_DEBUG, "nl80211: MLD: add link_id=%u, addr=" MACSTR, |
| 14039 | link_id, MAC2STR(addr)); |
| 14040 | |
| 14041 | if (drv->nlmode != NL80211_IFTYPE_AP) { |
| 14042 | wpa_printf(MSG_DEBUG, |
| 14043 | "nl80211: MLD: cannot add link to iftype=%u", |
| 14044 | drv->nlmode); |
| 14045 | return -EINVAL; |
| 14046 | } |
| 14047 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14048 | if (link_id >= MAX_NUM_MLD_LINKS) { |
| 14049 | wpa_printf(MSG_DEBUG, |
| 14050 | "nl80211: invalid link_id=%u", link_id); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14051 | return -EINVAL; |
| 14052 | } |
| 14053 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14054 | if (bss->valid_links & BIT(link_id)) { |
| 14055 | wpa_printf(MSG_DEBUG, |
| 14056 | "nl80211: MLD: Link %u already set", link_id); |
| 14057 | return -EINVAL; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14058 | } |
| 14059 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14060 | if (!bss->valid_links) { |
| 14061 | /* Becoming MLD, verify we were not beaconing */ |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14062 | if (bss->flink->beacon_set) { |
| 14063 | wpa_printf(MSG_DEBUG, "nl80211: BSS already beaconing"); |
| 14064 | return -EINVAL; |
| 14065 | } |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14066 | } |
| 14067 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 14068 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_ADD_LINK); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14069 | if (!msg || |
| 14070 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id) || |
| 14071 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 14072 | nlmsg_free(msg); |
| 14073 | return -ENOBUFS; |
| 14074 | } |
| 14075 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14076 | ret = send_and_recv_cmd(drv, msg); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14077 | if (ret) { |
| 14078 | wpa_printf(MSG_DEBUG, "nl80211: add link failed. ret=%d (%s)", |
| 14079 | ret, strerror(-ret)); |
| 14080 | return ret; |
| 14081 | } |
| 14082 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14083 | os_memcpy(bss->links[link_id].addr, addr, ETH_ALEN); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14084 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14085 | /* The new link is the first one, make it the default */ |
| 14086 | if (!bss->valid_links) |
| 14087 | bss->flink = &bss->links[link_id]; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14088 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14089 | bss->valid_links |= BIT(link_id); |
| 14090 | bss->links[link_id].ctx = bss_ctx; |
| 14091 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 14092 | wpa_printf(MSG_DEBUG, "nl80211: MLD: valid_links=0x%04x on %s", |
| 14093 | bss->valid_links, bss->ifname); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14094 | return 0; |
| 14095 | } |
| 14096 | |
| 14097 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14098 | #ifdef CONFIG_IEEE80211BE |
| 14099 | static int wpa_driver_nl80211_link_sta_remove(void *priv, u8 link_id, |
| 14100 | const u8 *addr) |
| 14101 | { |
| 14102 | struct i802_bss *bss = priv; |
| 14103 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 14104 | struct nl_msg *msg; |
| 14105 | int ret; |
| 14106 | |
| 14107 | if (!(bss->valid_links & BIT(link_id))) |
| 14108 | return -ENOLINK; |
| 14109 | |
| 14110 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_REMOVE_LINK_STA)) || |
| 14111 | nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, addr) || |
| 14112 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) { |
| 14113 | nlmsg_free(msg); |
| 14114 | return -ENOBUFS; |
| 14115 | } |
| 14116 | |
| 14117 | ret = send_and_recv_cmd(drv, msg); |
| 14118 | wpa_printf(MSG_DEBUG, |
| 14119 | "nl80211: link_sta_remove -> REMOVE_LINK_STA on link_id %u from MLD STA " |
| 14120 | MACSTR ", from %s --> %d (%s)", |
| 14121 | link_id, MAC2STR(addr), bss->ifname, ret, strerror(-ret)); |
| 14122 | |
| 14123 | return ret; |
| 14124 | } |
| 14125 | #endif /* CONFIG_IEEE80211BE */ |
| 14126 | |
| 14127 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 14128 | #ifdef CONFIG_TESTING_OPTIONS |
| 14129 | |
| 14130 | static int testing_nl80211_register_frame(void *priv, u16 type, |
| 14131 | const u8 *match, size_t match_len, |
| 14132 | bool multicast) |
| 14133 | { |
| 14134 | struct i802_bss *bss = priv; |
| 14135 | struct nl_sock *handle; |
| 14136 | |
| 14137 | if (!bss->nl_mgmt) |
| 14138 | return -1; |
| 14139 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 14140 | return nl80211_register_frame(bss, handle, type, match, match_len, |
| 14141 | multicast); |
| 14142 | } |
| 14143 | |
| 14144 | |
| 14145 | static int testing_nl80211_radio_disable(void *priv, int disabled) |
| 14146 | { |
| 14147 | struct i802_bss *bss = priv; |
| 14148 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 14149 | |
| 14150 | /* For now, this is supported only partially in station mode with |
| 14151 | * SME-in-wpa_supplicant case where the NL80211_ATTR_LOCAL_STATE_CHANGE |
| 14152 | * attribute can be used to avoid sending out the Deauthentication frame |
| 14153 | * to the currently associated AP. */ |
| 14154 | |
| 14155 | if (!disabled) |
| 14156 | return 0; |
| 14157 | |
| 14158 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 14159 | return -1; |
| 14160 | |
| 14161 | if (!drv->associated) |
| 14162 | return 0; |
| 14163 | |
| 14164 | return wpa_driver_nl80211_mlme(drv, drv->bssid, |
| 14165 | NL80211_CMD_DEAUTHENTICATE, |
| 14166 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1, |
| 14167 | drv->first_bss); |
| 14168 | } |
| 14169 | |
| 14170 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 14171 | |
| 14172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14173 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 14174 | .name = "nl80211", |
| 14175 | .desc = "Linux nl80211/cfg80211", |
| 14176 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 14177 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14178 | .set_key = driver_nl80211_set_key, |
| 14179 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14180 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 14181 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14182 | .get_scan_results = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 14183 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14184 | .deauthenticate = driver_nl80211_deauthenticate, |
| 14185 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14186 | .associate = wpa_driver_nl80211_associate, |
| 14187 | .global_init = nl80211_global_init, |
| 14188 | .global_deinit = nl80211_global_deinit, |
| 14189 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14190 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14191 | .get_capa = wpa_driver_nl80211_get_capa, |
| 14192 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 14193 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 14194 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 14195 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14196 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 14197 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14198 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14199 | .if_remove = driver_nl80211_if_remove, |
| 14200 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 14201 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14202 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14203 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 14204 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14205 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 14206 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 14207 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14208 | .hapd_init = i802_init, |
| 14209 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 14210 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14211 | .get_seqnum = i802_get_seqnum, |
| 14212 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14213 | .get_inact_sec = i802_get_inact_sec, |
| 14214 | .sta_clear_stats = i802_sta_clear_stats, |
| 14215 | .set_rts = i802_set_rts, |
| 14216 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14217 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14218 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14219 | .sta_deauth = i802_sta_deauth, |
| 14220 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14221 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14222 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14223 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14224 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 14225 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 14226 | .cancel_remain_on_channel = |
| 14227 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 14228 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14229 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 14230 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14231 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14232 | .signal_monitor = nl80211_signal_monitor, |
| 14233 | .signal_poll = nl80211_signal_poll, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 14234 | .mlo_signal_poll = nl80211_mlo_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 14235 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14236 | .set_param = nl80211_set_param, |
| 14237 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 14238 | .add_pmkid = nl80211_add_pmkid, |
| 14239 | .remove_pmkid = nl80211_remove_pmkid, |
| 14240 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14241 | .set_rekey_info = nl80211_set_rekey_info, |
| 14242 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14243 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 14244 | .start_dfs_cac = nl80211_start_radar_detection, |
| 14245 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14246 | #ifdef CONFIG_TDLS |
| 14247 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 14248 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 14249 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 14250 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14251 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 14252 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 14253 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 14254 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 14255 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 14256 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 14257 | .switch_channel = nl80211_switch_channel, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 14258 | #ifdef CONFIG_IEEE80211AX |
| 14259 | .switch_color = nl80211_switch_color, |
| 14260 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14261 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 14262 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14263 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 14264 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 14265 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 14266 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 14267 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 14268 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 14269 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 14270 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 14271 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 14272 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 14273 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 14274 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 14275 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 14276 | #ifdef CONFIG_MESH |
| 14277 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 14278 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 14279 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 14280 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 14281 | #endif /* CONFIG_MESH */ |
| 14282 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 14283 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 14284 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 14285 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 14286 | .add_tx_ts = nl80211_add_ts, |
| 14287 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 14288 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 14289 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 14290 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 14291 | .disable_fils = nl80211_disable_fils, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 14292 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 14293 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 14294 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 14295 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 14296 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 14297 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 14298 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 14299 | #ifdef CONFIG_MBO |
| 14300 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 14301 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 14302 | #endif /* CONFIG_MBO */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 14303 | .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 14304 | .add_sta_node = nl80211_add_sta_node, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 14305 | #ifdef CONFIG_PASN |
| 14306 | .send_pasn_resp = nl80211_send_pasn_resp, |
| 14307 | .set_secure_ranging_ctx = nl80211_set_secure_ranging_ctx, |
| 14308 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 14309 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 14310 | .do_acs = nl80211_do_acs, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 14311 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 14312 | .get_ext_capab = nl80211_get_ext_capab, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 14313 | .get_mld_capab = nl80211_get_mld_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 14314 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 14315 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 14316 | .set_4addr_mode = nl80211_set_4addr_mode, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 14317 | #ifdef CONFIG_DPP |
| 14318 | .dpp_listen = nl80211_dpp_listen, |
| 14319 | #endif /* CONFIG_DPP */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 14320 | .get_sta_mlo_info = nl80211_get_sta_mlo_info, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 14321 | .link_add = nl80211_link_add, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 14322 | #ifdef CONFIG_IEEE80211BE |
| 14323 | .link_remove = driver_nl80211_link_remove, |
| 14324 | .is_drv_shared = nl80211_is_drv_shared, |
| 14325 | .link_sta_remove = wpa_driver_nl80211_link_sta_remove, |
| 14326 | #endif /* CONFIG_IEEE80211BE */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 14327 | #ifdef CONFIG_TESTING_OPTIONS |
| 14328 | .register_frame = testing_nl80211_register_frame, |
| 14329 | .radio_disable = testing_nl80211_radio_disable, |
| 14330 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14331 | }; |