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> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include <fcntl.h> |
| 16 | #include <net/if.h> |
| 17 | #include <netlink/genl/genl.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include <netlink/genl/ctrl.h> |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_LIBNL3_ROUTE |
| 20 | #include <netlink/route/neighbour.h> |
| 21 | #endif /* CONFIG_LIBNL3_ROUTE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include <linux/rtnetlink.h> |
| 23 | #include <netpacket/packet.h> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 24 | #include <linux/errqueue.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | |
| 26 | #include "common.h" |
| 27 | #include "eloop.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 28 | #include "common/qca-vendor.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 29 | #include "common/qca-vendor-attr.h" |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 30 | #include "common/brcm_vendor.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 31 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 32 | #include "common/ieee802_11_common.h" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 33 | #include "common/wpa_common.h" |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 34 | #include "crypto/sha256.h" |
| 35 | #include "crypto/sha384.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 37 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 38 | #include "linux_ioctl.h" |
| 39 | #include "radiotap.h" |
| 40 | #include "radiotap_iter.h" |
| 41 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 42 | #include "driver_nl80211.h" |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 43 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 44 | #include "common/brcm_vendor.h" |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 45 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 46 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 47 | #ifndef NETLINK_CAP_ACK |
| 48 | #define NETLINK_CAP_ACK 10 |
| 49 | #endif /* NETLINK_CAP_ACK */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 50 | /* support for extack if compilation headers are too old */ |
| 51 | #ifndef NETLINK_EXT_ACK |
| 52 | #define NETLINK_EXT_ACK 11 |
| 53 | enum nlmsgerr_attrs { |
| 54 | NLMSGERR_ATTR_UNUSED, |
| 55 | NLMSGERR_ATTR_MSG, |
| 56 | NLMSGERR_ATTR_OFFS, |
| 57 | NLMSGERR_ATTR_COOKIE, |
| 58 | |
| 59 | __NLMSGERR_ATTR_MAX, |
| 60 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 61 | }; |
| 62 | #endif |
| 63 | #ifndef NLM_F_CAPPED |
| 64 | #define NLM_F_CAPPED 0x100 |
| 65 | #endif |
| 66 | #ifndef NLM_F_ACK_TLVS |
| 67 | #define NLM_F_ACK_TLVS 0x200 |
| 68 | #endif |
| 69 | #ifndef SOL_NETLINK |
| 70 | #define SOL_NETLINK 270 |
| 71 | #endif |
| 72 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 73 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 74 | #ifdef ANDROID |
| 75 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 76 | #undef nl_socket_set_nonblocking |
| 77 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 78 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 79 | #endif /* ANDROID */ |
| 80 | |
| 81 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 82 | 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] | 83 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 84 | struct nl_sock *handle; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 85 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 86 | handle = nl_socket_alloc_cb(cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 87 | if (handle == NULL) { |
| 88 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 89 | "callbacks (%s)", dbg); |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | if (genl_connect(handle)) { |
| 94 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 95 | "netlink (%s)", dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 96 | nl_socket_free(handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | return handle; |
| 101 | } |
| 102 | |
| 103 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 104 | static void nl_destroy_handles(struct nl_sock **handle) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 105 | { |
| 106 | if (*handle == NULL) |
| 107 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 108 | nl_socket_free(*handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 109 | *handle = NULL; |
| 110 | } |
| 111 | |
| 112 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 113 | #if __WORDSIZE == 64 |
| 114 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 115 | #else |
| 116 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 117 | #endif |
| 118 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 119 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 120 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 121 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 122 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 123 | /* |
| 124 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 125 | * by default. It is possible to hit that limit in some cases where |
| 126 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 127 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 128 | * this less likely to occur. |
| 129 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 130 | int err; |
| 131 | |
| 132 | err = nl_socket_set_buffer_size(*handle, 262144, 0); |
| 133 | if (err < 0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 134 | wpa_printf(MSG_DEBUG, |
| 135 | "nl80211: Could not set nl_socket RX buffer size: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 136 | nl_geterror(err)); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 137 | /* continue anyway with the default (smaller) buffer */ |
| 138 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 139 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 140 | nl_socket_set_nonblocking(*handle); |
| 141 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 142 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 143 | if (!persist) |
| 144 | *handle = (void *) (((intptr_t) *handle) ^ |
| 145 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 149 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 150 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 151 | if (!persist) |
| 152 | *handle = (void *) (((intptr_t) *handle) ^ |
| 153 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 154 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 155 | nl_destroy_handles(handle); |
| 156 | } |
| 157 | |
| 158 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 159 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 160 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 161 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 162 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 163 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 164 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 167 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 168 | const u8 *set_addr, int first, |
| 169 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 170 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 171 | unsigned int freq, unsigned int wait, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 172 | const u8 *buf, size_t buf_len, |
| 173 | int save_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 174 | int no_cck, int no_ack, int offchanok, |
| 175 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 176 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 177 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 178 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 179 | #define IFIDX_ANY -1 |
| 180 | |
| 181 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 182 | int ifidx_reason); |
| 183 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 184 | int ifidx_reason); |
| 185 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 186 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 187 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 188 | static int nl80211_set_channel(struct i802_bss *bss, |
| 189 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 190 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 191 | int ifindex, int disabled); |
| 192 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 193 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 194 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 195 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 196 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 197 | static int nl80211_set_param(void *priv, const char *param); |
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); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 280 | drv->first_bss->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; |
| 284 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 285 | |
| 286 | drv->auth_mld = false; |
| 287 | drv->auth_mld_link_id = -1; |
| 288 | os_memset(drv->auth_ap_mld_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 292 | /* nl80211 code */ |
| 293 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 294 | { |
| 295 | int *err = arg; |
| 296 | *err = 0; |
| 297 | return NL_STOP; |
| 298 | } |
| 299 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 300 | |
| 301 | struct nl80211_ack_ext_arg { |
| 302 | int *err; |
| 303 | void *ext_data; |
| 304 | }; |
| 305 | |
| 306 | |
| 307 | static int ack_handler_cookie(struct nl_msg *msg, void *arg) |
| 308 | { |
| 309 | struct nl80211_ack_ext_arg *ext_arg = arg; |
| 310 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
| 311 | u64 *cookie = ext_arg->ext_data; |
| 312 | struct nlattr *attrs; |
| 313 | size_t ack_len, attr_len; |
| 314 | |
| 315 | *ext_arg->err = 0; |
| 316 | ack_len = sizeof(struct nlmsghdr) + sizeof(int) + |
| 317 | sizeof(struct nlmsghdr); |
| 318 | attrs = (struct nlattr *) |
| 319 | ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) + |
| 320 | sizeof(int)); |
| 321 | if (nlmsg_hdr(msg)->nlmsg_len <= ack_len) |
| 322 | return NL_STOP; |
| 323 | |
| 324 | attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len; |
| 325 | |
| 326 | if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 327 | return NL_STOP; |
| 328 | |
| 329 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL); |
| 330 | if (tb[NLMSGERR_ATTR_COOKIE]) |
| 331 | *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]); |
| 332 | |
| 333 | return NL_STOP; |
| 334 | } |
| 335 | |
| 336 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 337 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 338 | { |
| 339 | int *ret = arg; |
| 340 | *ret = 0; |
| 341 | return NL_SKIP; |
| 342 | } |
| 343 | |
| 344 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 345 | void *arg) |
| 346 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 347 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 348 | int len = nlh->nlmsg_len; |
| 349 | struct nlattr *attrs; |
| 350 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 351 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 352 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 355 | |
| 356 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 357 | return NL_SKIP; |
| 358 | |
| 359 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 360 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 361 | |
| 362 | if (len <= ack_len) |
| 363 | return NL_STOP; |
| 364 | |
| 365 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 366 | len -= ack_len; |
| 367 | |
| 368 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 369 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 370 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 371 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 372 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 373 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 374 | } |
| 375 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 376 | return NL_SKIP; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 381 | { |
| 382 | return NL_OK; |
| 383 | } |
| 384 | |
| 385 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 386 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 387 | { |
| 388 | /* |
| 389 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 390 | * heap memory for unnecessarily long time. |
| 391 | */ |
| 392 | if (msg) { |
| 393 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 394 | void *data = nlmsg_data(hdr); |
| 395 | /* |
| 396 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 397 | * only libnl were to maintain a stable API.. Neither will work |
| 398 | * with all released versions, so just calculate the length |
| 399 | * here. |
| 400 | */ |
| 401 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 402 | |
| 403 | os_memset(data, 0, len); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 408 | static int send_and_recv(struct nl80211_global *global, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 409 | struct nl_sock *nl_handle, struct nl_msg *msg, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 410 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 411 | void *valid_data, |
| 412 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 413 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 414 | { |
| 415 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 416 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 418 | if (!msg) |
| 419 | return -ENOMEM; |
| 420 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 421 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | if (!cb) |
| 423 | goto out; |
| 424 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 425 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 426 | opt = 1; |
| 427 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 428 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 429 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 430 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 431 | opt = 1; |
| 432 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 433 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 434 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 435 | err = nl_send_auto_complete(nl_handle, msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 436 | if (err < 0) { |
| 437 | wpa_printf(MSG_INFO, |
| 438 | "nl80211: nl_send_auto_complete() failed: %s", |
| 439 | nl_geterror(err)); |
| 440 | /* Need to convert libnl error code to an errno value. For now, |
| 441 | * just hardcode this to EBADF; the real error reason is shown |
| 442 | * in that error print above. */ |
| 443 | err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 444 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 445 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 446 | |
| 447 | err = 1; |
| 448 | |
| 449 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 450 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 451 | if (ack_handler_custom) { |
| 452 | struct nl80211_ack_ext_arg *ext_arg = ack_data; |
| 453 | |
| 454 | ext_arg->err = &err; |
| 455 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, |
| 456 | ack_handler_custom, ack_data); |
| 457 | } else { |
| 458 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 459 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 460 | |
| 461 | if (valid_handler) |
| 462 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 463 | valid_handler, valid_data); |
| 464 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 465 | while (err > 0) { |
| 466 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 467 | |
| 468 | if (res == -NLE_DUMP_INTR) { |
| 469 | /* Most likely one of the nl80211 dump routines hit a |
| 470 | * case where internal results changed while the dump |
| 471 | * was being sent. The most common known case for this |
| 472 | * is scan results fetching while associated were every |
| 473 | * received Beacon frame from the AP may end up |
| 474 | * incrementing bss_generation. This |
| 475 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 476 | * other cases (of which there are no known common ones) |
| 477 | * will stop and return an error. */ |
| 478 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 479 | nl_geterror(res)); |
| 480 | err = -EAGAIN; |
| 481 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 482 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 483 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 484 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 487 | out: |
| 488 | nl_cb_put(cb); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 489 | /* Always clear the message as it can potentially contain keys */ |
| 490 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 491 | nlmsg_free(msg); |
| 492 | return err; |
| 493 | } |
| 494 | |
| 495 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 496 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 497 | struct nl_msg *msg, |
| 498 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 499 | void *valid_data, |
| 500 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 501 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 502 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 503 | return send_and_recv(drv->global, drv->global->nl, msg, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 504 | valid_handler, valid_data, |
| 505 | ack_handler_custom, ack_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 509 | /* Use this method to mark that it is necessary to own the connection/interface |
| 510 | * for this operation. |
| 511 | * handle may be set to NULL, to get the same behavior as send_and_recv_msgs(). |
| 512 | * set_owner can be used to mark this socket for receiving control port frames. |
| 513 | */ |
| 514 | static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv, |
| 515 | struct nl_msg *msg, |
| 516 | struct nl_sock *handle, int set_owner, |
| 517 | int (*valid_handler)(struct nl_msg *, |
| 518 | void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 519 | void *valid_data, |
| 520 | int (*ack_handler_custom)(struct nl_msg *, |
| 521 | void *), |
| 522 | void *ack_data) |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 523 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 524 | if (!msg) |
| 525 | return -ENOMEM; |
| 526 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 527 | /* Control port over nl80211 needs the flags and attributes below. |
| 528 | * |
| 529 | * The Linux kernel has initial checks for them (in nl80211.c) like: |
| 530 | * validate_pae_over_nl80211(...) |
| 531 | * or final checks like: |
| 532 | * dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid |
| 533 | * |
| 534 | * Final operations (e.g., disassociate) don't need to set these |
| 535 | * attributes, but they have to be performed on the socket, which has |
| 536 | * the connection owner property set in the kernel. |
| 537 | */ |
| 538 | if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && |
| 539 | handle && set_owner && |
| 540 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || |
| 541 | nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) || |
| 542 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 543 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))) |
| 544 | return -1; |
| 545 | |
| 546 | return send_and_recv(drv->global, handle ? handle : drv->global->nl, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 547 | msg, valid_handler, valid_data, |
| 548 | ack_handler_custom, ack_data); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 552 | static int |
| 553 | send_and_recv_msgs_connect_handle(struct wpa_driver_nl80211_data *drv, |
| 554 | struct nl_msg *msg, struct i802_bss *bss, |
| 555 | int set_owner) |
| 556 | { |
| 557 | struct nl_sock *nl_connect = get_connect_handle(bss); |
| 558 | |
| 559 | if (nl_connect) |
| 560 | return send_and_recv_msgs_owner(drv, msg, nl_connect, set_owner, |
| 561 | process_bss_event, bss, NULL, |
| 562 | NULL); |
| 563 | else |
| 564 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 565 | } |
| 566 | |
| 567 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 568 | struct nl_sock * get_connect_handle(struct i802_bss *bss) |
| 569 | { |
| 570 | if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) || |
| 571 | bss->use_nl_connect) |
| 572 | return bss->nl_connect; |
| 573 | |
| 574 | return NULL; |
| 575 | } |
| 576 | |
| 577 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 578 | struct family_data { |
| 579 | const char *group; |
| 580 | int id; |
| 581 | }; |
| 582 | |
| 583 | |
| 584 | static int family_handler(struct nl_msg *msg, void *arg) |
| 585 | { |
| 586 | struct family_data *res = arg; |
| 587 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 588 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 589 | struct nlattr *mcgrp; |
| 590 | int i; |
| 591 | |
| 592 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 593 | genlmsg_attrlen(gnlh, 0), NULL); |
| 594 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 595 | return NL_SKIP; |
| 596 | |
| 597 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 598 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 599 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 600 | nla_len(mcgrp), NULL); |
| 601 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 602 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 603 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 604 | res->group, |
| 605 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 606 | continue; |
| 607 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 608 | break; |
| 609 | }; |
| 610 | |
| 611 | return NL_SKIP; |
| 612 | } |
| 613 | |
| 614 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 615 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 616 | const char *family, const char *group) |
| 617 | { |
| 618 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 619 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 620 | struct family_data res = { group, -ENOENT }; |
| 621 | |
| 622 | msg = nlmsg_alloc(); |
| 623 | if (!msg) |
| 624 | return -ENOMEM; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 625 | if (!genlmsg_put(msg, 0, 0, global->nlctrl_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 626 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 627 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 628 | nlmsg_free(msg); |
| 629 | return -1; |
| 630 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 631 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 632 | ret = send_and_recv(global, global->nl, msg, family_handler, &res, |
| 633 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 634 | if (ret == 0) |
| 635 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 640 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 641 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 642 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 643 | if (TEST_FAIL()) |
| 644 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 645 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 646 | 0, flags, cmd, 0); |
| 647 | } |
| 648 | |
| 649 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 650 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 651 | { |
| 652 | if (bss->wdev_id_set) |
| 653 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 654 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 659 | { |
| 660 | struct nl_msg *msg; |
| 661 | |
| 662 | msg = nlmsg_alloc(); |
| 663 | if (!msg) |
| 664 | return NULL; |
| 665 | |
| 666 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 667 | nl80211_set_iface_id(msg, bss) < 0) { |
| 668 | nlmsg_free(msg); |
| 669 | return NULL; |
| 670 | } |
| 671 | |
| 672 | return msg; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | static struct nl_msg * |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 677 | nl80211_ifindex_msg_build(struct wpa_driver_nl80211_data *drv, |
| 678 | struct nl_msg *msg, int ifindex, int flags, |
| 679 | uint8_t cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 680 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 681 | if (!msg) |
| 682 | return NULL; |
| 683 | |
| 684 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 685 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 686 | nlmsg_free(msg); |
| 687 | return NULL; |
| 688 | } |
| 689 | |
| 690 | return msg; |
| 691 | } |
| 692 | |
| 693 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 694 | static struct nl_msg * |
| 695 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 696 | int flags, uint8_t cmd) |
| 697 | { |
| 698 | return nl80211_ifindex_msg_build(drv, nlmsg_alloc(), ifindex, flags, |
| 699 | cmd); |
| 700 | } |
| 701 | |
| 702 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 703 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 704 | uint8_t cmd) |
| 705 | { |
| 706 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 707 | } |
| 708 | |
| 709 | |
| 710 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 711 | { |
| 712 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 713 | } |
| 714 | |
| 715 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 716 | struct wiphy_idx_data { |
| 717 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 718 | enum nl80211_iftype nlmode; |
| 719 | u8 *macaddr; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 720 | u8 use_4addr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 721 | }; |
| 722 | |
| 723 | |
| 724 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 725 | { |
| 726 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 727 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 728 | struct wiphy_idx_data *info = arg; |
| 729 | |
| 730 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 731 | genlmsg_attrlen(gnlh, 0), NULL); |
| 732 | |
| 733 | if (tb[NL80211_ATTR_WIPHY]) |
| 734 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 735 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 736 | if (tb[NL80211_ATTR_IFTYPE]) |
| 737 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 738 | |
| 739 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 740 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 741 | ETH_ALEN); |
| 742 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 743 | if (tb[NL80211_ATTR_4ADDR]) |
| 744 | info->use_4addr = nla_get_u8(tb[NL80211_ATTR_4ADDR]); |
| 745 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 746 | return NL_SKIP; |
| 747 | } |
| 748 | |
| 749 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 750 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 751 | { |
| 752 | struct nl_msg *msg; |
| 753 | struct wiphy_idx_data data = { |
| 754 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 755 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 756 | }; |
| 757 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 758 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 759 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 760 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 761 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 762 | NULL, NULL) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 763 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 764 | return -1; |
| 765 | } |
| 766 | |
| 767 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 768 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 769 | { |
| 770 | struct nl_msg *msg; |
| 771 | struct wiphy_idx_data data = { |
| 772 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 773 | .macaddr = NULL, |
| 774 | }; |
| 775 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 776 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 777 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 778 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 779 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 780 | NULL, NULL) == 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 781 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 782 | return NL80211_IFTYPE_UNSPECIFIED; |
| 783 | } |
| 784 | |
| 785 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 786 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 787 | { |
| 788 | struct nl_msg *msg; |
| 789 | struct wiphy_idx_data data = { |
| 790 | .macaddr = bss->addr, |
| 791 | }; |
| 792 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 793 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 794 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 795 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 796 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 797 | NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 798 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 799 | |
| 800 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 801 | static int nl80211_get_4addr(struct i802_bss *bss) |
| 802 | { |
| 803 | struct nl_msg *msg; |
| 804 | struct wiphy_idx_data data = { |
| 805 | .use_4addr = 0, |
| 806 | }; |
| 807 | |
| 808 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)) || |
| 809 | send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 810 | NULL, NULL)) |
| 811 | return -1; |
| 812 | return data.use_4addr; |
| 813 | } |
| 814 | |
| 815 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 816 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 817 | struct nl80211_wiphy_data *w) |
| 818 | { |
| 819 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 820 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 821 | |
| 822 | msg = nlmsg_alloc(); |
| 823 | if (!msg) |
| 824 | return -1; |
| 825 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 826 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 827 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 828 | nlmsg_free(msg); |
| 829 | return -1; |
| 830 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 831 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 832 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL, |
| 833 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 834 | if (ret) { |
| 835 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 836 | "failed: ret=%d (%s)", |
| 837 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 838 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 839 | return ret; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 844 | { |
| 845 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 846 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 847 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 848 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 849 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 850 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 851 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 852 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 853 | __func__, res); |
| 854 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | |
| 858 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 859 | { |
| 860 | struct nl80211_wiphy_data *w = arg; |
| 861 | struct wpa_driver_nl80211_data *drv; |
| 862 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 863 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 864 | union wpa_event_data event; |
| 865 | |
| 866 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 867 | genlmsg_attrlen(gnlh, 0), NULL); |
| 868 | |
| 869 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 870 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 871 | gnlh->cmd); |
| 872 | return NL_SKIP; |
| 873 | } |
| 874 | |
| 875 | if (!tb[NL80211_ATTR_FRAME]) |
| 876 | return NL_SKIP; |
| 877 | |
| 878 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 879 | wiphy_list) { |
| 880 | os_memset(&event, 0, sizeof(event)); |
| 881 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 882 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 883 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 884 | } |
| 885 | |
| 886 | return NL_SKIP; |
| 887 | } |
| 888 | |
| 889 | |
| 890 | static struct nl80211_wiphy_data * |
| 891 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 892 | { |
| 893 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 894 | struct nl80211_wiphy_data *w; |
| 895 | int wiphy_idx, found = 0; |
| 896 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 897 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 898 | |
| 899 | if (bss->wiphy_data != NULL) |
| 900 | return bss->wiphy_data; |
| 901 | |
| 902 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 903 | |
| 904 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 905 | if (w->wiphy_idx == wiphy_idx) |
| 906 | goto add; |
| 907 | } |
| 908 | |
| 909 | /* alloc new one */ |
| 910 | w = os_zalloc(sizeof(*w)); |
| 911 | if (w == NULL) |
| 912 | return NULL; |
| 913 | w->wiphy_idx = wiphy_idx; |
| 914 | dl_list_init(&w->bsss); |
| 915 | dl_list_init(&w->drvs); |
| 916 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 917 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 918 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 919 | HOSTAPD_MODE_IEEE80211AD) { |
| 920 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 921 | if (!w->nl_cb) { |
| 922 | os_free(w); |
| 923 | return NULL; |
| 924 | } |
| 925 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 926 | no_seq_check, NULL); |
| 927 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 928 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 929 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 930 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 931 | "wiphy beacons"); |
| 932 | if (w->nl_beacons == NULL) { |
| 933 | os_free(w); |
| 934 | return NULL; |
| 935 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 936 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 937 | if (nl80211_register_beacons(bss->drv, w)) { |
| 938 | nl_destroy_handles(&w->nl_beacons); |
| 939 | os_free(w); |
| 940 | return NULL; |
| 941 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 942 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 943 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 944 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 945 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 946 | |
| 947 | dl_list_add(&nl80211_wiphys, &w->list); |
| 948 | |
| 949 | add: |
| 950 | /* drv entry for this bss already there? */ |
| 951 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 952 | if (tmp_bss->drv == bss->drv) { |
| 953 | found = 1; |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | /* if not add it */ |
| 958 | if (!found) |
| 959 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 960 | |
| 961 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 962 | bss->wiphy_data = w; |
| 963 | return w; |
| 964 | } |
| 965 | |
| 966 | |
| 967 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 968 | { |
| 969 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 970 | struct i802_bss *tmp_bss; |
| 971 | int found = 0; |
| 972 | |
| 973 | if (w == NULL) |
| 974 | return; |
| 975 | bss->wiphy_data = NULL; |
| 976 | dl_list_del(&bss->wiphy_list); |
| 977 | |
| 978 | /* still any for this drv present? */ |
| 979 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 980 | if (tmp_bss->drv == bss->drv) { |
| 981 | found = 1; |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | /* if not remove it */ |
| 986 | if (!found) |
| 987 | dl_list_del(&bss->drv->wiphy_list); |
| 988 | |
| 989 | if (!dl_list_empty(&w->bsss)) |
| 990 | return; |
| 991 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 992 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 993 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | |
| 995 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 996 | dl_list_del(&w->list); |
| 997 | os_free(w); |
| 998 | } |
| 999 | |
| 1000 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1001 | static unsigned int nl80211_get_ifindex(void *priv) |
| 1002 | { |
| 1003 | struct i802_bss *bss = priv; |
| 1004 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1005 | |
| 1006 | return drv->ifindex; |
| 1007 | } |
| 1008 | |
| 1009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1010 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 1011 | { |
| 1012 | struct i802_bss *bss = priv; |
| 1013 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1014 | if (!drv->associated) |
| 1015 | return -1; |
| 1016 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 1022 | { |
| 1023 | struct i802_bss *bss = priv; |
| 1024 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1025 | if (!drv->associated) |
| 1026 | return -1; |
| 1027 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 1028 | return drv->ssid_len; |
| 1029 | } |
| 1030 | |
| 1031 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1032 | static int get_mlo_info(struct nl_msg *msg, void *arg) |
| 1033 | { |
| 1034 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1035 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1036 | struct nlattr *link_attr, *link_data[NL80211_ATTR_MAX + 1]; |
| 1037 | static struct nla_policy link_policy[NL80211_ATTR_MAX + 1] = { |
| 1038 | [NL80211_ATTR_MLO_LINK_ID] = { .type = NLA_U8 }, |
| 1039 | [NL80211_ATTR_MAC] = { .minlen = ETH_ALEN, .maxlen = ETH_ALEN }, |
| 1040 | }; |
| 1041 | struct driver_sta_mlo_info *info = arg; |
| 1042 | int rem; |
| 1043 | |
| 1044 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1045 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1046 | |
| 1047 | if (!tb[NL80211_ATTR_MLO_LINKS]) |
| 1048 | return NL_SKIP; |
| 1049 | |
| 1050 | info->valid_links = 0; |
| 1051 | nla_for_each_nested(link_attr, tb[NL80211_ATTR_MLO_LINKS], rem) { |
| 1052 | u8 link_id; |
| 1053 | |
| 1054 | if (nla_parse_nested(link_data, NL80211_ATTR_MAX, |
| 1055 | link_attr, link_policy) != 0) |
| 1056 | continue; |
| 1057 | |
| 1058 | if (!link_data[NL80211_ATTR_MLO_LINK_ID] || |
| 1059 | !link_data[NL80211_ATTR_MAC]) |
| 1060 | continue; |
| 1061 | |
| 1062 | link_id = nla_get_u8(link_data[NL80211_ATTR_MLO_LINK_ID]); |
| 1063 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 1064 | continue; |
| 1065 | info->valid_links |= BIT(link_id); |
| 1066 | os_memcpy(info->links[link_id].addr, |
| 1067 | nla_data(link_data[NL80211_ATTR_MAC]), ETH_ALEN); |
| 1068 | if (link_data[NL80211_ATTR_WIPHY_FREQ]) |
| 1069 | info->links[link_id].freq = |
| 1070 | nla_get_u32(link_data[NL80211_ATTR_WIPHY_FREQ]); |
| 1071 | } |
| 1072 | |
| 1073 | return NL_SKIP; |
| 1074 | } |
| 1075 | |
| 1076 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1077 | static int nl80211_get_sta_mlo_info(void *priv, |
| 1078 | struct driver_sta_mlo_info *mlo_info) |
| 1079 | { |
| 1080 | struct i802_bss *bss = priv; |
| 1081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1082 | |
| 1083 | if (!drv->associated) |
| 1084 | return -1; |
| 1085 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1086 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1087 | struct nl_msg *msg; |
| 1088 | |
| 1089 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
| 1090 | if (send_and_recv_msgs(drv, msg, get_mlo_info, |
| 1091 | &drv->sta_mlo_info, NULL, NULL)) |
| 1092 | return -1; |
| 1093 | } |
| 1094 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1095 | os_memcpy(mlo_info, &drv->sta_mlo_info, sizeof(*mlo_info)); |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1100 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1101 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1102 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1103 | { |
| 1104 | union wpa_event_data event; |
| 1105 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1106 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1107 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 1108 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 1109 | drv->first_bss->ifname); |
| 1110 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1111 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1112 | if (!drv->if_removed) |
| 1113 | return; |
| 1114 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 1115 | drv->first_bss->ifname); |
| 1116 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1119 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1120 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1121 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1122 | sizeof(event.interface_status.ifname)); |
| 1123 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1124 | if (drv) |
| 1125 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1126 | else |
| 1127 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1128 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1133 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1134 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1135 | { |
| 1136 | union wpa_event_data event; |
| 1137 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1138 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1139 | if (drv->if_removed) { |
| 1140 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1141 | ifname); |
| 1142 | return; |
| 1143 | } |
| 1144 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1145 | ifname); |
| 1146 | drv->if_removed = 1; |
| 1147 | } else { |
| 1148 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1149 | ifname); |
| 1150 | } |
| 1151 | |
| 1152 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1153 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1154 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1155 | sizeof(event.interface_status.ifname)); |
| 1156 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1157 | if (drv) |
| 1158 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1159 | else |
| 1160 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1161 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1166 | u8 *buf, size_t len) |
| 1167 | { |
| 1168 | int attrlen, rta_len; |
| 1169 | struct rtattr *attr; |
| 1170 | |
| 1171 | attrlen = len; |
| 1172 | attr = (struct rtattr *) buf; |
| 1173 | |
| 1174 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1175 | while (RTA_OK(attr, attrlen)) { |
| 1176 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1177 | if (os_strcmp(((char *) attr) + rta_len, |
| 1178 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1179 | return 1; |
| 1180 | else |
| 1181 | break; |
| 1182 | } |
| 1183 | attr = RTA_NEXT(attr, attrlen); |
| 1184 | } |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | |
| 1190 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1191 | int ifindex, u8 *buf, size_t len) |
| 1192 | { |
| 1193 | if (drv->ifindex == ifindex) |
| 1194 | return 1; |
| 1195 | |
| 1196 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1197 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1198 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1199 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1200 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 1201 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1209 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1210 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 1211 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1212 | { |
| 1213 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1214 | int res; |
| 1215 | |
| 1216 | if (init_failed) |
| 1217 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1218 | dl_list_for_each(drv, &global->interfaces, |
| 1219 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1220 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1221 | if (res < 0) { |
| 1222 | wpa_printf(MSG_DEBUG, |
| 1223 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1224 | if (init_failed) |
| 1225 | *init_failed = 1; |
| 1226 | return drv; |
| 1227 | } |
| 1228 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1229 | return drv; |
| 1230 | } |
| 1231 | return NULL; |
| 1232 | } |
| 1233 | |
| 1234 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1235 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1236 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1237 | { |
| 1238 | struct i802_bss *bss; |
| 1239 | u8 addr[ETH_ALEN]; |
| 1240 | |
| 1241 | bss = get_bss_ifindex(drv, ifindex); |
| 1242 | if (bss && |
| 1243 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1244 | bss->ifname, addr) < 0) { |
| 1245 | wpa_printf(MSG_DEBUG, |
| 1246 | "nl80211: %s: failed to re-read MAC address", |
| 1247 | bss->ifname); |
| 1248 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1249 | wpa_printf(MSG_DEBUG, |
| 1250 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1251 | MACSTR " to " MACSTR, |
| 1252 | ifindex, bss->ifname, |
| 1253 | MAC2STR(bss->addr), MAC2STR(addr)); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1254 | os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1255 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1256 | if (notify) |
| 1257 | wpa_supplicant_event(drv->ctx, |
| 1258 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1263 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1264 | struct ifinfomsg *ifi, |
| 1265 | u8 *buf, size_t len) |
| 1266 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1267 | struct nl80211_global *global = ctx; |
| 1268 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1269 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1270 | struct rtattr *attr; |
| 1271 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1272 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1273 | char ifname[IFNAMSIZ + 1]; |
| 1274 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1275 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1276 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1277 | extra[0] = '\0'; |
| 1278 | pos = extra; |
| 1279 | end = pos + sizeof(extra); |
| 1280 | ifname[0] = '\0'; |
| 1281 | |
| 1282 | attrlen = len; |
| 1283 | attr = (struct rtattr *) buf; |
| 1284 | while (RTA_OK(attr, attrlen)) { |
| 1285 | switch (attr->rta_type) { |
| 1286 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1287 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1288 | break; |
| 1289 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1290 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1291 | break; |
| 1292 | case IFLA_MASTER: |
| 1293 | brid = nla_get_u32((struct nlattr *) attr); |
| 1294 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1295 | break; |
| 1296 | case IFLA_WIRELESS: |
| 1297 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1298 | break; |
| 1299 | case IFLA_OPERSTATE: |
| 1300 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1301 | nla_get_u32((struct nlattr *) attr)); |
| 1302 | break; |
| 1303 | case IFLA_LINKMODE: |
| 1304 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1305 | nla_get_u32((struct nlattr *) attr)); |
| 1306 | break; |
| 1307 | } |
| 1308 | attr = RTA_NEXT(attr, attrlen); |
| 1309 | } |
| 1310 | extra[sizeof(extra) - 1] = '\0'; |
| 1311 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1312 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1313 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1314 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1315 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1316 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1317 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1318 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1319 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1320 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1321 | if (!drv) |
| 1322 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1323 | if (init_failed) |
| 1324 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1326 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1327 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1328 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1329 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1330 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1331 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1332 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1333 | /* Re-read MAC address as it may have changed */ |
| 1334 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1335 | return; |
| 1336 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1337 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1338 | namebuf, ifname); |
| 1339 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1340 | wpa_printf(MSG_DEBUG, |
| 1341 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1342 | drv->first_bss->ifname); |
| 1343 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1344 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1345 | "event generated by mode change"); |
| 1346 | drv->ignore_if_down_event = 0; |
| 1347 | } else { |
| 1348 | drv->if_disabled = 1; |
| 1349 | wpa_supplicant_event(drv->ctx, |
| 1350 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1351 | |
| 1352 | /* |
| 1353 | * Try to get drv again, since it may be removed as |
| 1354 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1355 | * dynamic interfaces |
| 1356 | */ |
| 1357 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1358 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1359 | if (!drv) |
| 1360 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1361 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1365 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1366 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1367 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1368 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1369 | "event since interface %s is down", |
| 1370 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1371 | return; |
| 1372 | } |
| 1373 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1374 | namebuf, ifname); |
| 1375 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1376 | wpa_printf(MSG_DEBUG, |
| 1377 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1378 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1379 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1380 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1381 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1382 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1383 | } else if (drv->if_removed) { |
| 1384 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1385 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1386 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1387 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1388 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1389 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1390 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1391 | drv->if_disabled = 0; |
| 1392 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1393 | NULL); |
| 1394 | } |
Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1395 | } else if (ifi->ifi_flags & IFF_UP) { |
| 1396 | /* Re-read MAC address as it may have changed */ |
| 1397 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* |
| 1401 | * Some drivers send the association event before the operup event--in |
| 1402 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1403 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1404 | * IEEE 802.1X authentication |
| 1405 | */ |
| 1406 | if (drv->operstate == 1 && |
| 1407 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1408 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1409 | 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] | 1410 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1411 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1414 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1415 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1416 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1417 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1418 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1419 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1420 | struct i802_bss *bss; |
| 1421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1423 | if (!if_indextoname(brid, namebuf)) { |
| 1424 | wpa_printf(MSG_DEBUG, |
| 1425 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1426 | brid); |
| 1427 | return; |
| 1428 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1429 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1430 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1431 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1432 | |
| 1433 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1434 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1435 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1439 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1444 | struct ifinfomsg *ifi, |
| 1445 | u8 *buf, size_t len) |
| 1446 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1447 | struct nl80211_global *global = ctx; |
| 1448 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1449 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1450 | struct rtattr *attr; |
| 1451 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1452 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1453 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1454 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1455 | extra[0] = '\0'; |
| 1456 | pos = extra; |
| 1457 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1458 | ifname[0] = '\0'; |
| 1459 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | attrlen = len; |
| 1461 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1462 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1463 | switch (attr->rta_type) { |
| 1464 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1465 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1466 | break; |
| 1467 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1468 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1469 | break; |
| 1470 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1471 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1472 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1473 | break; |
| 1474 | case IFLA_OPERSTATE: |
| 1475 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1476 | nla_get_u32((struct nlattr *) attr)); |
| 1477 | break; |
| 1478 | case IFLA_LINKMODE: |
| 1479 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1480 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1481 | break; |
| 1482 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1483 | attr = RTA_NEXT(attr, attrlen); |
| 1484 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1485 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1486 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1487 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1488 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1489 | ifi->ifi_flags, |
| 1490 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1491 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1492 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1493 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1494 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1495 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1496 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1497 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1498 | /* device has been removed from bridge */ |
| 1499 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1500 | |
| 1501 | if (!if_indextoname(brid, namebuf)) { |
| 1502 | wpa_printf(MSG_DEBUG, |
| 1503 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1504 | brid); |
| 1505 | } else { |
| 1506 | wpa_printf(MSG_DEBUG, |
| 1507 | "nl80211: Remove ifindex %u for bridge %s", |
| 1508 | brid, namebuf); |
| 1509 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1510 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1511 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1512 | |
| 1513 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1514 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1515 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1519 | struct nl80211_get_assoc_freq_arg { |
| 1520 | struct wpa_driver_nl80211_data *drv; |
| 1521 | unsigned int assoc_freq; |
| 1522 | unsigned int ibss_freq; |
| 1523 | u8 assoc_bssid[ETH_ALEN]; |
| 1524 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1525 | u8 assoc_ssid_len; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1526 | u8 bssid[MAX_NUM_MLD_LINKS][ETH_ALEN]; |
| 1527 | unsigned int freq[MAX_NUM_MLD_LINKS]; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1528 | }; |
| 1529 | |
| 1530 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1531 | { |
| 1532 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1533 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1534 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1535 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1536 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1537 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1538 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1539 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1540 | [NL80211_BSS_MLO_LINK_ID] = { .type = NLA_U8 }, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1541 | }; |
| 1542 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1543 | enum nl80211_bss_status status; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1544 | struct wpa_driver_nl80211_data *drv = ctx->drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1545 | |
| 1546 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1547 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1548 | if (!tb[NL80211_ATTR_BSS] || |
| 1549 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1550 | bss_policy) || |
| 1551 | !bss[NL80211_BSS_STATUS]) |
| 1552 | return NL_SKIP; |
| 1553 | |
| 1554 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1555 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1556 | bss[NL80211_BSS_FREQUENCY]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1557 | int link_id = -1; |
| 1558 | u32 freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1559 | |
| 1560 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1561 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1562 | |
| 1563 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1564 | ctx->freq[link_id] = freq; |
| 1565 | wpa_printf(MSG_DEBUG, |
| 1566 | "nl80211: MLO link %d associated on %u MHz", |
| 1567 | link_id, ctx->freq[link_id]); |
| 1568 | } |
| 1569 | |
| 1570 | if (!drv->sta_mlo_info.valid_links || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1571 | drv->sta_mlo_info.assoc_link_id == link_id) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1572 | ctx->assoc_freq = freq; |
| 1573 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1574 | ctx->assoc_freq); |
| 1575 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1576 | } |
| 1577 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1578 | bss[NL80211_BSS_FREQUENCY]) { |
| 1579 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1580 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1581 | ctx->ibss_freq); |
| 1582 | } |
| 1583 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1584 | bss[NL80211_BSS_BSSID]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1585 | int link_id = -1; |
| 1586 | const u8 *bssid = nla_data(bss[NL80211_BSS_BSSID]); |
| 1587 | |
| 1588 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1589 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1590 | |
| 1591 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1592 | os_memcpy(ctx->bssid[link_id], bssid, ETH_ALEN); |
| 1593 | wpa_printf(MSG_DEBUG, |
| 1594 | "nl80211: MLO link %d associated with " |
| 1595 | MACSTR, link_id, MAC2STR(bssid)); |
| 1596 | } |
| 1597 | |
| 1598 | if (!drv->sta_mlo_info.valid_links || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1599 | drv->sta_mlo_info.assoc_link_id == link_id) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1600 | os_memcpy(ctx->assoc_bssid, bssid, ETH_ALEN); |
| 1601 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1602 | MACSTR, MAC2STR(bssid)); |
| 1603 | } |
| 1604 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1608 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1609 | const u8 *ie, *ssid; |
| 1610 | size_t ie_len; |
| 1611 | |
| 1612 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1613 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1614 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1615 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1616 | ctx->assoc_ssid_len = ssid[1]; |
| 1617 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | return NL_SKIP; |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | 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] | 1626 | { |
| 1627 | struct nl_msg *msg; |
| 1628 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1629 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1630 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1631 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1632 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1633 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1634 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1635 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1636 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1637 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1638 | if (ret == -EAGAIN) { |
| 1639 | count++; |
| 1640 | if (count >= 10) { |
| 1641 | wpa_printf(MSG_INFO, |
| 1642 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1643 | } else { |
| 1644 | wpa_printf(MSG_DEBUG, |
| 1645 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1646 | goto try_again; |
| 1647 | } |
| 1648 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1649 | if (ret == 0) { |
| 1650 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1651 | return arg.assoc_ssid_len; |
| 1652 | } |
| 1653 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1654 | ret, strerror(-ret)); |
| 1655 | return ret; |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1660 | { |
| 1661 | struct nl_msg *msg; |
| 1662 | int ret; |
| 1663 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1664 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1665 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1666 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1667 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1668 | os_memset(&arg, 0, sizeof(arg)); |
| 1669 | arg.drv = drv; |
| 1670 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1671 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1672 | if (ret == -EAGAIN) { |
| 1673 | count++; |
| 1674 | if (count >= 10) { |
| 1675 | wpa_printf(MSG_INFO, |
| 1676 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1677 | } else { |
| 1678 | wpa_printf(MSG_DEBUG, |
| 1679 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1680 | goto try_again; |
| 1681 | } |
| 1682 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1683 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1684 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1685 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1686 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1687 | "associated BSS from scan results: %u MHz", freq); |
| 1688 | if (freq) |
| 1689 | drv->assoc_freq = freq; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (drv->sta_mlo_info.valid_links) { |
| 1692 | int i; |
| 1693 | |
| 1694 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) |
| 1695 | drv->sta_mlo_info.links[i].freq = arg.freq[i]; |
| 1696 | } |
| 1697 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1698 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1699 | } |
| 1700 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1701 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1702 | return drv->assoc_freq; |
| 1703 | } |
| 1704 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1706 | { |
| 1707 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1708 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1709 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1710 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1711 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1712 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1713 | }; |
| 1714 | struct wpa_signal_info *sig_change = arg; |
| 1715 | |
| 1716 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1717 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1718 | |
| 1719 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1720 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1721 | return NL_SKIP; |
| 1722 | } |
| 1723 | |
| 1724 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1725 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1726 | survey_policy)) { |
| 1727 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1728 | "attributes!"); |
| 1729 | return NL_SKIP; |
| 1730 | } |
| 1731 | |
| 1732 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1733 | return NL_SKIP; |
| 1734 | |
| 1735 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1736 | sig_change->frequency) |
| 1737 | return NL_SKIP; |
| 1738 | |
| 1739 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1740 | return NL_SKIP; |
| 1741 | |
| 1742 | sig_change->current_noise = |
| 1743 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1744 | |
| 1745 | return NL_SKIP; |
| 1746 | } |
| 1747 | |
| 1748 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1749 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1750 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1751 | { |
| 1752 | struct nl_msg *msg; |
| 1753 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1754 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1755 | sig_change->frequency = drv->assoc_freq; |
| 1756 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1757 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1758 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change, |
| 1759 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1763 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1764 | { |
| 1765 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1766 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1767 | struct wpa_channel_info *chan_info = arg; |
| 1768 | |
| 1769 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1770 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1771 | |
| 1772 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1773 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1774 | |
| 1775 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1776 | chan_info->frequency = |
| 1777 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1778 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1779 | chan_info->chanwidth = convert2width( |
| 1780 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1781 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1782 | enum nl80211_channel_type ct = |
| 1783 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1784 | |
| 1785 | switch (ct) { |
| 1786 | case NL80211_CHAN_HT40MINUS: |
| 1787 | chan_info->sec_channel = -1; |
| 1788 | break; |
| 1789 | case NL80211_CHAN_HT40PLUS: |
| 1790 | chan_info->sec_channel = 1; |
| 1791 | break; |
| 1792 | default: |
| 1793 | chan_info->sec_channel = 0; |
| 1794 | break; |
| 1795 | } |
| 1796 | } |
| 1797 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1798 | chan_info->center_frq1 = |
| 1799 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1800 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1801 | chan_info->center_frq2 = |
| 1802 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1803 | |
| 1804 | if (chan_info->center_frq2) { |
| 1805 | u8 seg1_idx = 0; |
| 1806 | |
| 1807 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1808 | NUM_HOSTAPD_MODES) |
| 1809 | chan_info->seg1_idx = seg1_idx; |
| 1810 | } |
| 1811 | |
| 1812 | return NL_SKIP; |
| 1813 | } |
| 1814 | |
| 1815 | |
| 1816 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1817 | { |
| 1818 | struct i802_bss *bss = priv; |
| 1819 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1820 | struct nl_msg *msg; |
| 1821 | |
| 1822 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1823 | return send_and_recv_msgs(drv, msg, get_channel_info, ci, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1827 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1828 | void *handle) |
| 1829 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1830 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1831 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1832 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1833 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1834 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1835 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1836 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1837 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1838 | __func__, res); |
| 1839 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | /** |
| 1844 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1845 | * @priv: driver_nl80211 private data |
| 1846 | * @alpha2_arg: country to which to switch to |
| 1847 | * Returns: 0 on success, -1 on failure |
| 1848 | * |
| 1849 | * This asks nl80211 to set the regulatory domain for given |
| 1850 | * country ISO / IEC alpha2. |
| 1851 | */ |
| 1852 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1853 | { |
| 1854 | struct i802_bss *bss = priv; |
| 1855 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1856 | char alpha2[3]; |
| 1857 | struct nl_msg *msg; |
| 1858 | |
| 1859 | msg = nlmsg_alloc(); |
| 1860 | if (!msg) |
| 1861 | return -ENOMEM; |
| 1862 | |
| 1863 | alpha2[0] = alpha2_arg[0]; |
| 1864 | alpha2[1] = alpha2_arg[1]; |
| 1865 | alpha2[2] = '\0'; |
| 1866 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1867 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1868 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1869 | nlmsg_free(msg); |
| 1870 | return -EINVAL; |
| 1871 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1872 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1873 | return -EINVAL; |
| 1874 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1878 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1879 | { |
| 1880 | char *alpha2 = arg; |
| 1881 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1882 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1883 | |
| 1884 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1885 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1886 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1887 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1888 | return NL_SKIP; |
| 1889 | } |
| 1890 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1891 | return NL_SKIP; |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1896 | { |
| 1897 | struct i802_bss *bss = priv; |
| 1898 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1899 | struct nl_msg *msg; |
| 1900 | int ret; |
| 1901 | |
| 1902 | msg = nlmsg_alloc(); |
| 1903 | if (!msg) |
| 1904 | return -ENOMEM; |
| 1905 | |
| 1906 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1907 | alpha2[0] = '\0'; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1908 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2, |
| 1909 | NULL, NULL); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1910 | if (!alpha2[0]) |
| 1911 | ret = -1; |
| 1912 | |
| 1913 | return ret; |
| 1914 | } |
| 1915 | |
| 1916 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1917 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1918 | { |
| 1919 | int ret; |
| 1920 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1921 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1922 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1923 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1924 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1925 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1928 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1929 | if (global->nl == NULL) |
| 1930 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1931 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1932 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1933 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1934 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1935 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1936 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1939 | global->nlctrl_id = genl_ctrl_resolve(global->nl, "nlctrl"); |
| 1940 | if (global->nlctrl_id < 0) { |
| 1941 | wpa_printf(MSG_ERROR, |
| 1942 | "nl80211: 'nlctrl' generic netlink not found"); |
| 1943 | goto err; |
| 1944 | } |
| 1945 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1946 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1947 | if (global->nl_event == NULL) |
| 1948 | goto err; |
| 1949 | |
| 1950 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1951 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1952 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1953 | if (ret < 0) { |
| 1954 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1955 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1956 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1957 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1960 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1961 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1962 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1963 | if (ret < 0) { |
| 1964 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1965 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1966 | ret, nl_geterror(ret)); |
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 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1970 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1973 | if (ret < 0) { |
| 1974 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1975 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1976 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1977 | /* Continue without regulatory events */ |
| 1978 | } |
| 1979 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1980 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1981 | if (ret >= 0) |
| 1982 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1983 | if (ret < 0) { |
| 1984 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1985 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1986 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1987 | /* Continue without vendor events */ |
| 1988 | } |
| 1989 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1990 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1991 | no_seq_check, NULL); |
| 1992 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1993 | process_global_event, global); |
| 1994 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1995 | nl80211_register_eloop_read(&global->nl_event, |
| 1996 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1997 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1998 | |
| 1999 | return 0; |
| 2000 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2001 | err: |
| 2002 | nl_destroy_handles(&global->nl_event); |
| 2003 | nl_destroy_handles(&global->nl); |
| 2004 | nl_cb_put(global->nl_cb); |
| 2005 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2006 | return -1; |
| 2007 | } |
| 2008 | |
| 2009 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2010 | static void nl80211_check_global(struct nl80211_global *global) |
| 2011 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2012 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2013 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 2014 | int ret; |
| 2015 | unsigned int i; |
| 2016 | |
| 2017 | /* |
| 2018 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 2019 | * and all registration having been cleared. |
| 2020 | */ |
| 2021 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 2022 | ELOOP_SOCKET_INVALID); |
| 2023 | |
| 2024 | for (i = 0; groups[i]; i++) { |
| 2025 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 2026 | if (ret >= 0) |
| 2027 | ret = nl_socket_add_membership(handle, ret); |
| 2028 | if (ret < 0) { |
| 2029 | wpa_printf(MSG_INFO, |
| 2030 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2031 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2037 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 2038 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2039 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2040 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2041 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2044 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 2045 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2046 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2047 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2048 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | |
| 2052 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 2053 | { |
| 2054 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2055 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2056 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2057 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 2058 | "after rfkill unblock"); |
| 2059 | return; |
| 2060 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2061 | |
| 2062 | if (is_p2p_net_interface(drv->nlmode)) |
| 2063 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 2064 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2065 | /* |
| 2066 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 2067 | * Device interface as enabled. |
| 2068 | */ |
| 2069 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2070 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2074 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 2075 | void *eloop_ctx, |
| 2076 | void *handle) |
| 2077 | { |
| 2078 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 2079 | u8 data[2048]; |
| 2080 | struct msghdr msg; |
| 2081 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2082 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2083 | struct cmsghdr *cmsg; |
| 2084 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 2085 | union wpa_event_data event; |
| 2086 | |
| 2087 | memset(&msg, 0, sizeof(msg)); |
| 2088 | msg.msg_iov = &entry; |
| 2089 | msg.msg_iovlen = 1; |
| 2090 | entry.iov_base = data; |
| 2091 | entry.iov_len = sizeof(data); |
| 2092 | msg.msg_control = &control; |
| 2093 | msg.msg_controllen = sizeof(control); |
| 2094 | |
| 2095 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 2096 | /* if error or not fitting 802.3 header, return */ |
| 2097 | if (res < 14) |
| 2098 | return; |
| 2099 | |
| 2100 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 2101 | { |
| 2102 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 2103 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 2104 | int *ack; |
| 2105 | |
| 2106 | found_wifi = 1; |
| 2107 | ack = (void *)CMSG_DATA(cmsg); |
| 2108 | acked = *ack; |
| 2109 | } |
| 2110 | |
| 2111 | if (cmsg->cmsg_level == SOL_PACKET && |
| 2112 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 2113 | struct sock_extended_err *err = |
| 2114 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 2115 | |
| 2116 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 2117 | found_ee = 1; |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | if (!found_ee || !found_wifi) |
| 2122 | return; |
| 2123 | |
| 2124 | memset(&event, 0, sizeof(event)); |
| 2125 | event.eapol_tx_status.dst = data; |
| 2126 | event.eapol_tx_status.data = data + 14; |
| 2127 | event.eapol_tx_status.data_len = res - 14; |
| 2128 | event.eapol_tx_status.ack = acked; |
| 2129 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 2130 | } |
| 2131 | |
| 2132 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2133 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2134 | { |
| 2135 | if (bss->nl_connect) { |
| 2136 | wpa_printf(MSG_DEBUG, |
| 2137 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2138 | bss->nl_connect); |
| 2139 | return -1; |
| 2140 | } |
| 2141 | |
| 2142 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2143 | if (!bss->nl_connect) |
| 2144 | return -1; |
| 2145 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2146 | wpa_driver_nl80211_event_receive, |
| 2147 | bss->nl_cb, 1); |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
| 2151 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2152 | static int nl80211_init_bss(struct i802_bss *bss) |
| 2153 | { |
| 2154 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 2155 | if (!bss->nl_cb) |
| 2156 | return -1; |
| 2157 | |
| 2158 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2159 | no_seq_check, NULL); |
| 2160 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2161 | process_bss_event, bss); |
| 2162 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2163 | nl80211_init_connect_handle(bss); |
| 2164 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2165 | return 0; |
| 2166 | } |
| 2167 | |
| 2168 | |
| 2169 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 2170 | { |
| 2171 | nl_cb_put(bss->nl_cb); |
| 2172 | bss->nl_cb = NULL; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2173 | |
| 2174 | if (bss->nl_connect) |
| 2175 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2179 | static void |
| 2180 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 2181 | { |
| 2182 | struct rfkill_config *rcfg; |
| 2183 | |
| 2184 | if (drv->rfkill) |
| 2185 | return; |
| 2186 | |
| 2187 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 2188 | if (!rcfg) |
| 2189 | return; |
| 2190 | |
| 2191 | rcfg->ctx = drv; |
| 2192 | |
| 2193 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 2194 | * not associated with a netdev, so use the name of some other interface |
| 2195 | * sharing the same wiphy as the P2P Device interface. |
| 2196 | * |
| 2197 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 2198 | * created and is created only once another wpa_s interface was added. |
| 2199 | */ |
| 2200 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 2201 | struct nl80211_global *global = drv->global; |
| 2202 | struct wpa_driver_nl80211_data *tmp1; |
| 2203 | |
| 2204 | dl_list_for_each(tmp1, &global->interfaces, |
| 2205 | struct wpa_driver_nl80211_data, list) { |
| 2206 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 2207 | !tmp1->rfkill) |
| 2208 | continue; |
| 2209 | |
| 2210 | wpa_printf(MSG_DEBUG, |
| 2211 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 2212 | tmp1->first_bss->ifname); |
| 2213 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 2214 | sizeof(rcfg->ifname)); |
| 2215 | break; |
| 2216 | } |
| 2217 | } else { |
| 2218 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 2219 | sizeof(rcfg->ifname)); |
| 2220 | } |
| 2221 | |
| 2222 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 2223 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 2224 | drv->rfkill = rfkill_init(rcfg); |
| 2225 | if (!drv->rfkill) { |
| 2226 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 2227 | os_free(rcfg); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2232 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 2233 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2234 | const u8 *set_addr, |
| 2235 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | { |
| 2237 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2238 | struct i802_bss *bss; |
| 2239 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2240 | if (global_priv == NULL) |
| 2241 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2242 | drv = os_zalloc(sizeof(*drv)); |
| 2243 | if (drv == NULL) |
| 2244 | return NULL; |
| 2245 | drv->global = global_priv; |
| 2246 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2247 | drv->hostapd = !!hostapd; |
| 2248 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2249 | |
| 2250 | /* |
| 2251 | * There is no driver capability flag for this, so assume it is |
| 2252 | * supported and disable this on first attempt to use if the driver |
| 2253 | * rejects the command due to missing support. |
| 2254 | */ |
| 2255 | drv->set_rekey_offload = 1; |
| 2256 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2257 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2258 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2259 | |
| 2260 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2261 | if (!drv->first_bss) { |
| 2262 | os_free(drv); |
| 2263 | return NULL; |
| 2264 | } |
| 2265 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2267 | bss->ctx = ctx; |
| 2268 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2269 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2270 | drv->monitor_ifidx = -1; |
| 2271 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2272 | drv->eapol_tx_sock = -1; |
| 2273 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2275 | if (nl80211_init_bss(bss)) |
| 2276 | goto failed; |
| 2277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2278 | 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] | 2279 | goto failed; |
| 2280 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2281 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) { |
| 2282 | drv->control_port_ap = 1; |
| 2283 | goto skip_wifi_status; |
| 2284 | } |
| 2285 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2286 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2287 | if (drv->eapol_tx_sock < 0) |
| 2288 | goto failed; |
| 2289 | |
| 2290 | if (drv->data_tx_status) { |
| 2291 | int enabled = 1; |
| 2292 | |
| 2293 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2294 | &enabled, sizeof(enabled)) < 0) { |
| 2295 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2296 | "nl80211: wifi status sockopt failed: %s", |
| 2297 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2298 | drv->data_tx_status = 0; |
| 2299 | if (!drv->use_monitor) |
| 2300 | drv->capa.flags &= |
| 2301 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2302 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2303 | eloop_register_read_sock( |
| 2304 | drv->eapol_tx_sock, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2305 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2306 | drv, NULL); |
| 2307 | } |
| 2308 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2309 | skip_wifi_status: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2310 | |
| 2311 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2312 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2314 | drv->in_interface_list = 1; |
| 2315 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2316 | |
| 2317 | return bss; |
| 2318 | |
| 2319 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2320 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2321 | return NULL; |
| 2322 | } |
| 2323 | |
| 2324 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2325 | /** |
| 2326 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2327 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2328 | * e.g., wpa_supplicant_event() |
| 2329 | * @ifname: interface name, e.g., wlan0 |
| 2330 | * @global_priv: private driver global data from global_init() |
| 2331 | * Returns: Pointer to private data, %NULL on failure |
| 2332 | */ |
| 2333 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2334 | void *global_priv) |
| 2335 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2336 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2337 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2341 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2342 | struct nl_sock *nl_handle, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2343 | u16 type, const u8 *match, size_t match_len, |
| 2344 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2345 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2346 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2347 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2348 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2349 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2350 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2351 | buf[0] = '\0'; |
| 2352 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2353 | wpa_printf(MSG_DEBUG, |
| 2354 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", |
| 2355 | type, fc2str(type), nl_handle, buf, multicast); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2356 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2357 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2358 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2359 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2360 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2361 | nlmsg_free(msg); |
| 2362 | return -1; |
| 2363 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2364 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2365 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL, |
| 2366 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2367 | if (ret) { |
| 2368 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2369 | "failed (type=%u): ret=%d (%s)", |
| 2370 | type, ret, strerror(-ret)); |
| 2371 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2372 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2373 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2374 | return ret; |
| 2375 | } |
| 2376 | |
| 2377 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2378 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2379 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2380 | if (bss->nl_mgmt) { |
| 2381 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2382 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2383 | return -1; |
| 2384 | } |
| 2385 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2386 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2387 | if (bss->nl_mgmt == NULL) |
| 2388 | return -1; |
| 2389 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2390 | return 0; |
| 2391 | } |
| 2392 | |
| 2393 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2394 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2395 | { |
| 2396 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2397 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2398 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2402 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | const u8 *match, size_t match_len) |
| 2404 | { |
| 2405 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2406 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2407 | type, match, match_len, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2411 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2412 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2413 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2414 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2415 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2416 | |
| 2417 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2418 | return -1; |
| 2419 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2420 | "handle %p", bss->nl_mgmt); |
| 2421 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2422 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2423 | /* register for any AUTH message */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2424 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2425 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2426 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 2427 | /* register for SAE Authentication frames */ |
| 2428 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2429 | (u8 *) "\x03\x00", 2, false); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2432 | #ifdef CONFIG_PASN |
| 2433 | /* register for PASN Authentication frames */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2434 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2435 | (u8 *) "\x07\x00", 2, false)) |
| 2436 | ret = -1; |
| 2437 | #endif /* CONFIG_PASN */ |
| 2438 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2439 | #ifdef CONFIG_INTERWORKING |
| 2440 | /* QoS Map Configure */ |
| 2441 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2442 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2443 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2444 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2445 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2446 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2447 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2448 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2449 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2450 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2451 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2452 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2453 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2454 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2455 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2456 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2457 | /* Protected GAS Initial Request */ |
| 2458 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2459 | ret = -1; |
| 2460 | /* Protected GAS Initial Response */ |
| 2461 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2462 | ret = -1; |
| 2463 | /* Protected GAS Comeback Request */ |
| 2464 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2465 | ret = -1; |
| 2466 | /* Protected GAS Comeback Response */ |
| 2467 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2468 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2469 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2470 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2472 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2473 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2474 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2475 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2476 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2477 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2478 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2479 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2480 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2481 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2482 | #ifdef CONFIG_DPP |
| 2483 | /* DPP Public Action */ |
| 2484 | if (nl80211_register_action_frame(bss, |
| 2485 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2486 | 6) < 0) |
| 2487 | ret = -1; |
| 2488 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2489 | #ifdef CONFIG_OCV |
| 2490 | /* SA Query Request */ |
| 2491 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2492 | ret = -1; |
| 2493 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2494 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2495 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2496 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2497 | #ifdef CONFIG_TDLS |
| 2498 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2499 | /* TDLS Discovery Response */ |
| 2500 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2501 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2502 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2503 | } |
| 2504 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2505 | #ifdef CONFIG_FST |
| 2506 | /* FST Action frames */ |
| 2507 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2508 | ret = -1; |
| 2509 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2510 | |
| 2511 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2512 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2513 | ret = -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2514 | else if (!drv->has_driver_key_mgmt) { |
| 2515 | int i; |
| 2516 | |
| 2517 | /* Update supported AKMs only if the driver doesn't advertize |
| 2518 | * any AKM capabilities. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2519 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2520 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2521 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2522 | /* Update per interface supported AKMs */ |
| 2523 | for (i = 0; i < WPA_IF_MAX; i++) |
| 2524 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; |
| 2525 | } |
| 2526 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2527 | /* WNM - BSS Transition Management Request */ |
| 2528 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2529 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2530 | /* WNM-Sleep Mode Response */ |
| 2531 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2532 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2533 | #ifdef CONFIG_WNM |
| 2534 | /* WNM - Collocated Interference Request */ |
| 2535 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2536 | ret = -1; |
| 2537 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2538 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2539 | #ifdef CONFIG_HS20 |
| 2540 | /* WNM-Notification */ |
| 2541 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2542 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2543 | #endif /* CONFIG_HS20 */ |
| 2544 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2545 | /* WMM-AC ADDTS Response */ |
| 2546 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2547 | ret = -1; |
| 2548 | |
| 2549 | /* WMM-AC DELTS */ |
| 2550 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2551 | ret = -1; |
| 2552 | |
| 2553 | /* Radio Measurement - Neighbor Report Response */ |
| 2554 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2555 | ret = -1; |
| 2556 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2557 | /* Radio Measurement - Radio Measurement Request */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2558 | if (!drv->no_rrm && |
| 2559 | nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2560 | ret = -1; |
| 2561 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2562 | /* Radio Measurement - Link Measurement Request */ |
| 2563 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2564 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2565 | ret = -1; |
| 2566 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2567 | /* Robust AV SCS Response */ |
| 2568 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x01", 2) < 0) |
| 2569 | ret = -1; |
| 2570 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2571 | /* Robust AV MSCS Response */ |
| 2572 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0) |
| 2573 | ret = -1; |
| 2574 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2575 | /* Protected QoS Management Action frame */ |
| 2576 | if (nl80211_register_action_frame(bss, (u8 *) "\x7e\x50\x6f\x9a\x1a", |
| 2577 | 5) < 0) |
| 2578 | ret = -1; |
| 2579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | nl80211_mgmt_handle_register_eloop(bss); |
| 2581 | |
| 2582 | return ret; |
| 2583 | } |
| 2584 | |
| 2585 | |
| 2586 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2587 | { |
| 2588 | int ret = 0; |
| 2589 | |
| 2590 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2591 | return -1; |
| 2592 | |
| 2593 | wpa_printf(MSG_DEBUG, |
| 2594 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2595 | bss->nl_mgmt); |
| 2596 | |
| 2597 | /* Auth frames for mesh SAE */ |
| 2598 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2599 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2600 | (WLAN_FC_STYPE_AUTH << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2601 | NULL, 0, false) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2602 | ret = -1; |
| 2603 | |
| 2604 | /* Mesh peering open */ |
| 2605 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2606 | ret = -1; |
| 2607 | /* Mesh peering confirm */ |
| 2608 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2609 | ret = -1; |
| 2610 | /* Mesh peering close */ |
| 2611 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2612 | ret = -1; |
| 2613 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2614 | nl80211_mgmt_handle_register_eloop(bss); |
| 2615 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2616 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2620 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2621 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2622 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2623 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2624 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2625 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2626 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL, |
| 2627 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2628 | if (ret) { |
| 2629 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2630 | "failed: ret=%d (%s)", |
| 2631 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2632 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2633 | return ret; |
| 2634 | } |
| 2635 | |
| 2636 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2637 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2638 | { |
| 2639 | int ret = 0; |
| 2640 | |
| 2641 | /* Public Action frames */ |
| 2642 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2643 | ret = -1; |
| 2644 | /* RRM Measurement Report */ |
| 2645 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2646 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2647 | /* RRM Link Measurement Report */ |
| 2648 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2649 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2650 | /* RRM Neighbor Report Request */ |
| 2651 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2652 | ret = -1; |
| 2653 | /* FT Action frames */ |
| 2654 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2655 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2656 | /* SA Query */ |
| 2657 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2658 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2659 | /* Protected Dual of Public Action */ |
| 2660 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2661 | ret = -1; |
| 2662 | /* WNM */ |
| 2663 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2664 | ret = -1; |
| 2665 | /* WMM */ |
| 2666 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2667 | ret = -1; |
| 2668 | #ifdef CONFIG_FST |
| 2669 | /* FST Action frames */ |
| 2670 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2671 | ret = -1; |
| 2672 | #endif /* CONFIG_FST */ |
| 2673 | /* Vendor-specific */ |
| 2674 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2675 | ret = -1; |
| 2676 | |
| 2677 | return ret; |
| 2678 | } |
| 2679 | |
| 2680 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2681 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2682 | { |
| 2683 | static const int stypes[] = { |
| 2684 | WLAN_FC_STYPE_AUTH, |
| 2685 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2686 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2687 | WLAN_FC_STYPE_DISASSOC, |
| 2688 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2689 | WLAN_FC_STYPE_PROBE_REQ, |
| 2690 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2691 | * it, but it wouldn't really be the right thing anyway as |
| 2692 | * it isn't per interface ... maybe just dump the scan |
| 2693 | * results periodically for OLBC? |
| 2694 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2695 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2696 | }; |
| 2697 | unsigned int i; |
| 2698 | |
| 2699 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2700 | return -1; |
| 2701 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2702 | "handle %p", bss->nl_mgmt); |
| 2703 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2704 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2705 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2706 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2707 | (stypes[i] << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2708 | NULL, 0, false) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2709 | goto out_err; |
| 2710 | } |
| 2711 | } |
| 2712 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2713 | if (nl80211_action_subscribe_ap(bss)) |
| 2714 | goto out_err; |
| 2715 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2716 | if (nl80211_register_spurious_class3(bss)) |
| 2717 | goto out_err; |
| 2718 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2719 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2720 | return 0; |
| 2721 | |
| 2722 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2723 | nl_destroy_handles(&bss->nl_mgmt); |
| 2724 | return -1; |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2729 | { |
| 2730 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2731 | return -1; |
| 2732 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2733 | "handle %p (device SME)", bss->nl_mgmt); |
| 2734 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2735 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2736 | goto out_err; |
| 2737 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2738 | if (bss->drv->device_ap_sme) { |
| 2739 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2740 | |
| 2741 | /* Register for all Authentication frames */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2742 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, |
| 2743 | false) < 0) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2744 | wpa_printf(MSG_DEBUG, |
| 2745 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2746 | } |
| 2747 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2748 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2749 | return 0; |
| 2750 | |
| 2751 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2752 | nl_destroy_handles(&bss->nl_mgmt); |
| 2753 | return -1; |
| 2754 | } |
| 2755 | |
| 2756 | |
| 2757 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2758 | { |
| 2759 | if (bss->nl_mgmt == NULL) |
| 2760 | return; |
| 2761 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2762 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2763 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2764 | |
| 2765 | nl80211_put_wiphy_data_ap(bss); |
| 2766 | } |
| 2767 | |
| 2768 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2769 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2770 | { |
| 2771 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2772 | } |
| 2773 | |
| 2774 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2775 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2776 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2777 | struct nl_msg *msg; |
| 2778 | int ret; |
| 2779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2780 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2781 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2782 | |
| 2783 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2784 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2785 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | |
| 2789 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2790 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2791 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2792 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2793 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2794 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2795 | NL80211_CMD_STOP_P2P_DEVICE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2796 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2797 | |
| 2798 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2799 | start ? "Start" : "Stop", |
| 2800 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2801 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2802 | return ret; |
| 2803 | } |
| 2804 | |
| 2805 | |
| 2806 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2807 | { |
| 2808 | enum nl80211_iftype nlmode; |
| 2809 | |
| 2810 | nlmode = nl80211_get_ifmode(bss); |
| 2811 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2812 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2813 | bss->ifname, up); |
| 2814 | } |
| 2815 | |
| 2816 | /* P2P Device has start/stop which is equivalent */ |
| 2817 | return nl80211_set_p2pdev(bss, up); |
| 2818 | } |
| 2819 | |
| 2820 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2821 | #ifdef CONFIG_TESTING_OPTIONS |
| 2822 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2823 | { |
| 2824 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2825 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2826 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2827 | |
| 2828 | |
| 2829 | wpa_printf(MSG_DEBUG, |
| 2830 | "nl80211: QCA vendor test command response received"); |
| 2831 | |
| 2832 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2833 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2834 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2835 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2836 | return NL_SKIP; |
| 2837 | } |
| 2838 | |
| 2839 | wpa_hexdump(MSG_DEBUG, |
| 2840 | "nl80211: Received QCA vendor test command response", |
| 2841 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2842 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2843 | |
| 2844 | return NL_SKIP; |
| 2845 | } |
| 2846 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2847 | |
| 2848 | |
| 2849 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2850 | { |
| 2851 | #ifdef CONFIG_TESTING_OPTIONS |
| 2852 | struct nl_msg *msg; |
| 2853 | struct nlattr *params; |
| 2854 | int ret; |
| 2855 | |
| 2856 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2857 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2858 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2859 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2860 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2861 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2862 | nlmsg_free(msg); |
| 2863 | return; |
| 2864 | } |
| 2865 | nla_nest_end(msg, params); |
| 2866 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2867 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv, |
| 2868 | NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2869 | wpa_printf(MSG_DEBUG, |
| 2870 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2871 | ret, strerror(-ret)); |
| 2872 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2873 | } |
| 2874 | |
| 2875 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2876 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2877 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2878 | const u8 *set_addr, int first, |
| 2879 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2880 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2881 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2882 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2883 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2884 | |
| 2885 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2886 | bss->ifindex = drv->ifindex; |
| 2887 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2888 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2889 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2890 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2891 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2892 | drv->global->if_add_wdevid_set = 0; |
| 2893 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2894 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2895 | bss->static_ap = 1; |
| 2896 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2897 | if (first && |
| 2898 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2899 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2900 | drv->start_iface_up = 1; |
| 2901 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2902 | if (wpa_driver_nl80211_capa(drv)) |
| 2903 | return -1; |
| 2904 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2905 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2906 | return -1; |
| 2907 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2908 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2909 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2910 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2911 | if (set_addr && |
| 2912 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2913 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2914 | set_addr))) |
| 2915 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2916 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2917 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_STATION) |
| 2918 | drv->start_mode_sta = 1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2919 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2920 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2921 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2922 | else if (bss->if_dynamic || |
| 2923 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2924 | nlmode = nl80211_get_ifmode(bss); |
| 2925 | else |
| 2926 | nlmode = NL80211_IFTYPE_STATION; |
| 2927 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2928 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2929 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2930 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2931 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2932 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2933 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2934 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2935 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2936 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2937 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2938 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2939 | int ret = i802_set_iface_flags(bss, 1); |
| 2940 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2941 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2942 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2943 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2944 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2945 | |
| 2946 | if (is_p2p_net_interface(nlmode)) |
| 2947 | nl80211_disable_11b_rates(bss->drv, |
| 2948 | bss->drv->ifindex, 1); |
| 2949 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2950 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2951 | return ret; |
| 2952 | } else { |
| 2953 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2954 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2955 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2956 | drv->if_disabled = 1; |
| 2957 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2958 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2961 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2962 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2963 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2964 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2965 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2966 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2967 | bss->addr)) |
| 2968 | return -1; |
| 2969 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2970 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2972 | if (send_rfkill_event) { |
| 2973 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2974 | drv, drv->ctx); |
| 2975 | } |
| 2976 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2977 | if (drv->vendor_cmd_test_avail) |
| 2978 | qca_vendor_test(drv); |
| 2979 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2980 | return 0; |
| 2981 | } |
| 2982 | |
| 2983 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2984 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2985 | { |
| 2986 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2987 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2988 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2989 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2990 | drv->ifindex); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2991 | bss->beacon_set = 0; |
| 2992 | bss->freq = 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2993 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2994 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2995 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | |
| 2999 | /** |
| 3000 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3001 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | * |
| 3003 | * Shut down driver interface and processing of driver events. Free |
| 3004 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 3005 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3006 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3007 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3008 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3009 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3010 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3011 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 3012 | bss->ifname, drv->disabled_11b_rates); |
| 3013 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3014 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3015 | if (drv->data_tx_status) |
| 3016 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 3017 | if (drv->eapol_tx_sock >= 0) |
| 3018 | close(drv->eapol_tx_sock); |
| 3019 | |
| 3020 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3021 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3022 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3023 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 3024 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3025 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3026 | "interface %s from bridge %s: %s", |
| 3027 | bss->ifname, bss->brname, strerror(errno)); |
| 3028 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3029 | |
| 3030 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3031 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3032 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3033 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3034 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 3035 | 0) < 0) |
| 3036 | wpa_printf(MSG_INFO, |
| 3037 | "nl80211: Could not set bridge %s down", |
| 3038 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3039 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3040 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3041 | "bridge %s: %s", |
| 3042 | bss->brname, strerror(errno)); |
| 3043 | } |
| 3044 | |
| 3045 | nl80211_remove_monitor_interface(drv); |
| 3046 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3047 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3048 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3049 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3050 | if (drv->eapol_sock >= 0) { |
| 3051 | eloop_unregister_read_sock(drv->eapol_sock); |
| 3052 | close(drv->eapol_sock); |
| 3053 | } |
| 3054 | |
| 3055 | if (drv->if_indices != drv->default_if_indices) |
| 3056 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3057 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3058 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3059 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3060 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3061 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 3062 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3063 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3064 | rfkill_deinit(drv->rfkill); |
| 3065 | |
| 3066 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3067 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3068 | if (!drv->start_iface_up) |
| 3069 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3070 | |
| 3071 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3072 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 3073 | 0) < 0) { |
| 3074 | wpa_printf(MSG_DEBUG, |
| 3075 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 3076 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3077 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3078 | drv->perm_addr) < 0) { |
| 3079 | wpa_printf(MSG_DEBUG, |
| 3080 | "nl80211: Could not restore permanent MAC address"); |
| 3081 | } |
| 3082 | } |
| 3083 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3084 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3085 | if (drv->start_mode_sta) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3086 | wpa_driver_nl80211_set_mode(bss, |
| 3087 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3088 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3089 | } else { |
| 3090 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 3091 | nl80211_del_p2pdev(bss); |
| 3092 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3094 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3095 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3096 | os_free(drv->filter_ssids); |
| 3097 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3098 | os_free(drv->auth_ie); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3099 | os_free(drv->auth_data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3100 | |
| 3101 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3102 | dl_list_del(&drv->list); |
| 3103 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3104 | os_free(drv->extended_capa); |
| 3105 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3106 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 3107 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 3108 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 3109 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3110 | os_free(drv->first_bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3111 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 3112 | os_free(drv->pending_roam_data); |
| 3113 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3114 | os_free(drv); |
| 3115 | } |
| 3116 | |
| 3117 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3118 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 3119 | { |
| 3120 | switch (alg) { |
| 3121 | case WPA_ALG_WEP: |
| 3122 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3123 | return RSN_CIPHER_SUITE_WEP40; |
| 3124 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3125 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3126 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3127 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3128 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3129 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3130 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3131 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3132 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3133 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3134 | return RSN_CIPHER_SUITE_GCMP_256; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3135 | case WPA_ALG_BIP_CMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3136 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3137 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3138 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3139 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3140 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3141 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3142 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3143 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3144 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3145 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3146 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3147 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3148 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 3149 | alg); |
| 3150 | return 0; |
| 3151 | } |
| 3152 | |
| 3153 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 3154 | alg); |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
| 3158 | |
| 3159 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 3160 | { |
| 3161 | switch (cipher) { |
| 3162 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3163 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3164 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3165 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3166 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3167 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3168 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3169 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3170 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3171 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3172 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3173 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3174 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3175 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3176 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3177 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3178 | default: |
| 3179 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3180 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | |
| 3184 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 3185 | int max_suites) |
| 3186 | { |
| 3187 | int num_suites = 0; |
| 3188 | |
| 3189 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3190 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3191 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3192 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3193 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3194 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3195 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3196 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3197 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3198 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3199 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3200 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3201 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3202 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3203 | |
| 3204 | return num_suites; |
| 3205 | } |
| 3206 | |
| 3207 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3208 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3209 | int max_suites) |
| 3210 | { |
| 3211 | int num_suites = 0; |
| 3212 | |
| 3213 | #define __AKM(a, b) \ |
| 3214 | if (num_suites < max_suites && \ |
| 3215 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3216 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3217 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 3218 | __AKM(PSK, PSK_OVER_802_1X); |
| 3219 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 3220 | __AKM(FT_PSK, FT_PSK); |
| 3221 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 3222 | __AKM(PSK_SHA256, PSK_SHA256); |
| 3223 | __AKM(SAE, SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3224 | __AKM(SAE_EXT_KEY, SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3225 | __AKM(FT_SAE, FT_SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3226 | __AKM(FT_SAE_EXT_KEY, FT_SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3227 | __AKM(CCKM, CCKM); |
| 3228 | __AKM(OSEN, OSEN); |
| 3229 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 3230 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 3231 | __AKM(FILS_SHA256, FILS_SHA256); |
| 3232 | __AKM(FILS_SHA384, FILS_SHA384); |
| 3233 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 3234 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 3235 | __AKM(OWE, OWE); |
| 3236 | __AKM(DPP, DPP); |
| 3237 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
| 3238 | #undef __AKM |
| 3239 | |
| 3240 | return num_suites; |
| 3241 | } |
| 3242 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3243 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3244 | static int wpa_driver_do_broadcom_acs(struct wpa_driver_nl80211_data *drv, |
| 3245 | struct drv_acs_params *params) |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3246 | { |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3247 | struct nl_msg *msg; |
| 3248 | struct nlattr *data; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3249 | int freq_list_len; |
| 3250 | int ret = -1; |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3251 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3252 | freq_list_len = int_array_len(params->freq_list); |
| 3253 | wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d", |
| 3254 | __func__, freq_list_len); |
| 3255 | |
| 3256 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 3257 | if (!msg || |
| 3258 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3259 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3260 | BRCM_VENDOR_SCMD_ACS) || |
| 3261 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3262 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode) || |
| 3263 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED, |
| 3264 | params->ht_enabled) || |
| 3265 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED, |
| 3266 | params->ht40_enabled) || |
| 3267 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED, |
| 3268 | params->vht_enabled) || |
| 3269 | nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width) || |
| 3270 | (freq_list_len > 0 && |
| 3271 | nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST, |
| 3272 | sizeof(int) * freq_list_len, params->freq_list))) |
| 3273 | goto fail; |
| 3274 | nla_nest_end(msg, data); |
| 3275 | |
| 3276 | wpa_printf(MSG_DEBUG, |
| 3277 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d", |
| 3278 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 3279 | params->vht_enabled, params->ch_width); |
| 3280 | |
| 3281 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 3282 | if (ret) { |
| 3283 | wpa_printf(MSG_ERROR, |
| 3284 | "nl80211: BRCM Failed to invoke driver ACS function: %s", |
| 3285 | strerror(errno)); |
| 3286 | } |
| 3287 | |
| 3288 | msg = NULL; |
| 3289 | fail: |
| 3290 | nlmsg_free(msg); |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3291 | return ret; |
| 3292 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3293 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3294 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3295 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3296 | static int wpa_cross_akm_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3297 | int max_suites) |
| 3298 | { |
| 3299 | int num_suites = 0; |
| 3300 | |
| 3301 | #define __AKM_TO_SUITES_ARRAY(a, b) \ |
| 3302 | if (num_suites < max_suites && \ |
| 3303 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3304 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3305 | __AKM_TO_SUITES_ARRAY(PSK, PSK_OVER_802_1X); |
| 3306 | __AKM_TO_SUITES_ARRAY(SAE, SAE); |
| 3307 | #undef __AKM_TO_SUITES_ARRAY |
| 3308 | |
| 3309 | return num_suites; |
| 3310 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3311 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3312 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3313 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3314 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3315 | const u8 *key, size_t key_len) |
| 3316 | { |
| 3317 | struct nl_msg *msg; |
| 3318 | int ret; |
| 3319 | |
| 3320 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 3321 | return 0; |
| 3322 | |
| 3323 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3324 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3325 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3326 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 3327 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 3328 | nl80211_nlmsg_clear(msg); |
| 3329 | nlmsg_free(msg); |
| 3330 | return -1; |
| 3331 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3332 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3333 | if (ret) { |
| 3334 | wpa_printf(MSG_DEBUG, |
| 3335 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3336 | ret, strerror(-ret)); |
| 3337 | } |
| 3338 | |
| 3339 | return ret; |
| 3340 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3341 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3342 | |
| 3343 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3344 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3345 | static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3346 | const u8 *key, size_t key_len) |
| 3347 | { |
| 3348 | struct nl_msg *msg; |
| 3349 | int ret; |
| 3350 | struct nlattr *params; |
| 3351 | |
| 3352 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3353 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3354 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3355 | BRCM_VENDOR_SCMD_SET_PMK) || |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3356 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3357 | nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) { |
| 3358 | nl80211_nlmsg_clear(msg); |
| 3359 | nlmsg_free(msg); |
| 3360 | return -ENOBUFS; |
| 3361 | } |
| 3362 | nla_nest_end(msg, params); |
| 3363 | |
| 3364 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 3365 | if (ret) { |
| 3366 | wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)", |
| 3367 | ret, strerror(-ret)); |
| 3368 | } |
| 3369 | |
| 3370 | return ret; |
| 3371 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3372 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3373 | |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3374 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3375 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3376 | const u8 *key, size_t key_len, |
| 3377 | const u8 *addr) |
| 3378 | { |
| 3379 | struct nl_msg *msg = NULL; |
| 3380 | int ret; |
| 3381 | |
| 3382 | /* |
| 3383 | * If the authenticator address is not set, assume it is |
| 3384 | * the current BSSID. |
| 3385 | */ |
| 3386 | if (!addr && drv->associated) |
| 3387 | addr = drv->bssid; |
| 3388 | else if (!addr) |
| 3389 | return -1; |
| 3390 | |
| 3391 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3392 | MAC2STR(addr)); |
| 3393 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3394 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3395 | if (!msg || |
| 3396 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3397 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3398 | nl80211_nlmsg_clear(msg); |
| 3399 | nlmsg_free(msg); |
| 3400 | return -ENOBUFS; |
| 3401 | } |
| 3402 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3403 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3404 | if (ret) { |
| 3405 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3406 | ret, strerror(-ret)); |
| 3407 | } |
| 3408 | |
| 3409 | return ret; |
| 3410 | } |
| 3411 | |
| 3412 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3413 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3414 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3415 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3416 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3417 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3418 | struct nl_msg *msg; |
| 3419 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3420 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3421 | int skip_set_key = 1; |
| 3422 | const char *ifname = params->ifname; |
| 3423 | enum wpa_alg alg = params->alg; |
| 3424 | const u8 *addr = params->addr; |
| 3425 | int key_idx = params->key_idx; |
| 3426 | int set_tx = params->set_tx; |
| 3427 | const u8 *seq = params->seq; |
| 3428 | size_t seq_len = params->seq_len; |
| 3429 | const u8 *key = params->key; |
| 3430 | size_t key_len = params->key_len; |
| 3431 | int vlan_id = params->vlan_id; |
| 3432 | enum key_flag key_flag = params->key_flag; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3433 | int link_id = params->link_id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3434 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3435 | /* Ignore for P2P Device */ |
| 3436 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3437 | return 0; |
| 3438 | |
| 3439 | ifindex = if_nametoindex(ifname); |
| 3440 | 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^] | 3441 | "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] | 3442 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3443 | (unsigned long) seq_len, (unsigned long) key_len, key_flag, |
| 3444 | link_id); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3445 | |
| 3446 | if (check_key_flag(key_flag)) { |
| 3447 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3448 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3449 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3450 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3451 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3452 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3453 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3454 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3455 | __func__); |
| 3456 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3457 | return ret; |
| 3458 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3459 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3460 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3461 | if (key_flag & KEY_FLAG_PMK) { |
| 3462 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3463 | return nl80211_set_pmk(drv, key, key_len, addr); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3464 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3465 | if (drv->vendor_set_pmk) { |
Jay Patel | 731adae | 2021-02-17 14:55:58 -0800 | [diff] [blame] | 3466 | 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] | 3467 | return key_mgmt_set_key(drv, key, key_len); |
| 3468 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3469 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3470 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3471 | /* The driver does not have any offload mechanism for PMK, so |
| 3472 | * there is no need to configure this key. */ |
| 3473 | return 0; |
| 3474 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3475 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3476 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3477 | key_msg = nlmsg_alloc(); |
| 3478 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3479 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3480 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3481 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3482 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3483 | wpa_printf(MSG_DEBUG, |
| 3484 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3485 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3486 | if (!msg) |
| 3487 | goto fail2; |
| 3488 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3489 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3490 | __func__); |
| 3491 | ret = -EINVAL; |
| 3492 | goto fail2; |
| 3493 | } else if (alg == WPA_ALG_NONE) { |
| 3494 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3495 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3496 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3497 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3498 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3499 | u32 suite; |
| 3500 | |
| 3501 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3502 | if (!suite) { |
| 3503 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3504 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3505 | } |
| 3506 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3507 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3508 | if (!msg) |
| 3509 | goto fail2; |
| 3510 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3511 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3512 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3513 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3514 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3515 | if (seq && seq_len) { |
| 3516 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3517 | goto fail; |
| 3518 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3519 | seq, seq_len); |
| 3520 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3521 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3522 | |
| 3523 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3524 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3525 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3526 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3527 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3528 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3529 | KEY_FLAG_PAIRWISE_RX || |
| 3530 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3531 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3532 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3533 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3534 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3535 | goto fail; |
| 3536 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3537 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3539 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3540 | NL80211_KEYTYPE_GROUP)) |
| 3541 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3542 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3543 | wpa_printf(MSG_DEBUG, |
| 3544 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3545 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3546 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3547 | } else if (alg == WPA_ALG_WEP && |
| 3548 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3549 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3550 | skip_set_key = 0; |
| 3551 | } else { |
| 3552 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3553 | } |
| 3554 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3555 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3556 | wpa_printf(MSG_DEBUG, |
| 3557 | " invalid key_flag for a broadcast key"); |
| 3558 | ret = -EINVAL; |
| 3559 | goto fail; |
| 3560 | } else { |
| 3561 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3562 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3563 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3564 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3565 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3566 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3567 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3568 | nl80211_nlmsg_clear(key_msg); |
| 3569 | nlmsg_free(key_msg); |
| 3570 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3571 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3572 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3573 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3574 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3575 | goto fail; |
| 3576 | } |
| 3577 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3578 | if (link_id != -1) { |
| 3579 | wpa_printf(MSG_DEBUG, "nl80211: Link ID %d", link_id); |
| 3580 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 3581 | goto fail; |
| 3582 | } |
| 3583 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3584 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3585 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3586 | ret = 0; |
| 3587 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3588 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3589 | ret, strerror(-ret)); |
| 3590 | |
| 3591 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3592 | * 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] | 3593 | * we're done here. |
| 3594 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3595 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3596 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3597 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3598 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3599 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3600 | key_msg = nlmsg_alloc(); |
| 3601 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3602 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3603 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3604 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3605 | if (!msg) |
| 3606 | goto fail2; |
| 3607 | if (!key_msg || |
| 3608 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3609 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3610 | (key_idx == 6 || key_idx == 7 ? |
| 3611 | NL80211_KEY_DEFAULT_BEACON : |
| 3612 | NL80211_KEY_DEFAULT_MGMT) : |
| 3613 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3614 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3615 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3616 | struct nlattr *types; |
| 3617 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3618 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3619 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3620 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3621 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3622 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3623 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3624 | struct nlattr *types; |
| 3625 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3626 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3627 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3628 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3629 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3630 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3633 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3634 | goto fail; |
| 3635 | nl80211_nlmsg_clear(key_msg); |
| 3636 | nlmsg_free(key_msg); |
| 3637 | key_msg = NULL; |
| 3638 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3639 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3640 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3641 | vlan_id); |
| 3642 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3643 | goto fail; |
| 3644 | } |
| 3645 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3646 | if (link_id != -1) { |
| 3647 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - Link ID %d", |
| 3648 | link_id); |
| 3649 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
| 3650 | goto fail; |
| 3651 | } |
| 3652 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3653 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3654 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3655 | wpa_printf(MSG_DEBUG, |
| 3656 | "nl80211: set_key default failed; err=%d %s", |
| 3657 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3658 | return ret; |
| 3659 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3660 | fail: |
| 3661 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3662 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3663 | fail2: |
| 3664 | nl80211_nlmsg_clear(key_msg); |
| 3665 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3666 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | |
| 3670 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3671 | int key_idx, int defkey, |
| 3672 | const u8 *seq, size_t seq_len, |
| 3673 | const u8 *key, size_t key_len) |
| 3674 | { |
| 3675 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3676 | u32 suite; |
| 3677 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3678 | if (!key_attr) |
| 3679 | return -1; |
| 3680 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3681 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3682 | if (!suite) |
| 3683 | return -1; |
| 3684 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3685 | if (defkey && wpa_alg_bip(alg)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3686 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3687 | return -1; |
| 3688 | } else if (defkey) { |
| 3689 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3690 | return -1; |
| 3691 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3693 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3694 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3695 | (seq && seq_len && |
| 3696 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3697 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3698 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3699 | |
| 3700 | nla_nest_end(msg, key_attr); |
| 3701 | |
| 3702 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | |
| 3706 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3707 | struct nl_msg *msg) |
| 3708 | { |
| 3709 | int i, privacy = 0; |
| 3710 | struct nlattr *nl_keys, *nl_key; |
| 3711 | |
| 3712 | for (i = 0; i < 4; i++) { |
| 3713 | if (!params->wep_key[i]) |
| 3714 | continue; |
| 3715 | privacy = 1; |
| 3716 | break; |
| 3717 | } |
| 3718 | if (params->wps == WPS_MODE_PRIVACY) |
| 3719 | privacy = 1; |
| 3720 | if (params->pairwise_suite && |
| 3721 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3722 | privacy = 1; |
| 3723 | |
| 3724 | if (!privacy) |
| 3725 | return 0; |
| 3726 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3727 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3728 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3729 | |
| 3730 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3731 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3732 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3733 | |
| 3734 | for (i = 0; i < 4; i++) { |
| 3735 | if (!params->wep_key[i]) |
| 3736 | continue; |
| 3737 | |
| 3738 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3739 | if (!nl_key || |
| 3740 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3741 | params->wep_key[i]) || |
| 3742 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3743 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3744 | RSN_CIPHER_SUITE_WEP40 : |
| 3745 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3746 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3747 | (i == params->wep_tx_keyidx && |
| 3748 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3749 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3750 | |
| 3751 | nla_nest_end(msg, nl_key); |
| 3752 | } |
| 3753 | nla_nest_end(msg, nl_keys); |
| 3754 | |
| 3755 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3759 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3760 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3761 | int local_state_change, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3762 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3763 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3764 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3765 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3766 | struct nl_sock *nl_connect = get_connect_handle(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3767 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3768 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3769 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3770 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3771 | (local_state_change && |
| 3772 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3773 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3774 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3775 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3776 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3777 | if (nl_connect) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3778 | ret = send_and_recv(drv->global, nl_connect, msg, |
| 3779 | process_bss_event, bss, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3780 | else |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3781 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3782 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3783 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3784 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3785 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3786 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3787 | return ret; |
| 3788 | } |
| 3789 | |
| 3790 | |
| 3791 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3792 | u16 reason_code, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3793 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3794 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3795 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3796 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3797 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3798 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3799 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3800 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3801 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3802 | reason_code, 0, bss); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3803 | /* |
| 3804 | * For locally generated disconnect, supplicant already generates a |
| 3805 | * DEAUTH event, so ignore the event from NL80211. |
| 3806 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3807 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3808 | |
| 3809 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3813 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3814 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3815 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3816 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3817 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3818 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3819 | |
| 3820 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3821 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3822 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3823 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3824 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3825 | return wpa_driver_nl80211_disconnect(drv, reason_code, bss); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3826 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3827 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3828 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3829 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3830 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3831 | reason_code, 0, bss); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3832 | /* |
| 3833 | * For locally generated deauthenticate, supplicant already generates a |
| 3834 | * DEAUTH event, so ignore the event from NL80211. |
| 3835 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3836 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3837 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3838 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3842 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3843 | struct wpa_driver_auth_params *params) |
| 3844 | { |
| 3845 | int i; |
| 3846 | |
| 3847 | drv->auth_freq = params->freq; |
| 3848 | drv->auth_alg = params->auth_alg; |
| 3849 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3850 | drv->auth_local_state_change = params->local_state_change; |
| 3851 | drv->auth_p2p = params->p2p; |
| 3852 | |
| 3853 | if (params->bssid) |
| 3854 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3855 | else |
| 3856 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3857 | |
| 3858 | if (params->ssid) { |
| 3859 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3860 | drv->auth_ssid_len = params->ssid_len; |
| 3861 | } else |
| 3862 | drv->auth_ssid_len = 0; |
| 3863 | |
| 3864 | |
| 3865 | os_free(drv->auth_ie); |
| 3866 | drv->auth_ie = NULL; |
| 3867 | drv->auth_ie_len = 0; |
| 3868 | if (params->ie) { |
| 3869 | drv->auth_ie = os_malloc(params->ie_len); |
| 3870 | if (drv->auth_ie) { |
| 3871 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3872 | drv->auth_ie_len = params->ie_len; |
| 3873 | } |
| 3874 | } |
| 3875 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3876 | if (params->mld && params->ap_mld_addr) { |
| 3877 | drv->auth_mld = params->mld; |
| 3878 | drv->auth_mld_link_id = params->mld_link_id; |
| 3879 | os_memcpy(drv->auth_ap_mld_addr, params->ap_mld_addr, ETH_ALEN); |
| 3880 | } else { |
| 3881 | drv->auth_mld = false; |
| 3882 | drv->auth_mld_link_id = -1; |
| 3883 | } |
| 3884 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3885 | os_free(drv->auth_data); |
| 3886 | drv->auth_data = NULL; |
| 3887 | drv->auth_data_len = 0; |
| 3888 | if (params->auth_data) { |
| 3889 | drv->auth_data = os_memdup(params->auth_data, |
| 3890 | params->auth_data_len); |
| 3891 | if (drv->auth_data) |
| 3892 | drv->auth_data_len = params->auth_data_len; |
| 3893 | } |
| 3894 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3895 | for (i = 0; i < 4; i++) { |
| 3896 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3897 | params->wep_key_len[i] <= 16) { |
| 3898 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3899 | params->wep_key_len[i]); |
| 3900 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3901 | } else |
| 3902 | drv->auth_wep_key_len[i] = 0; |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3907 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3908 | { |
| 3909 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3910 | |
| 3911 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3912 | return; |
| 3913 | |
| 3914 | /* |
| 3915 | * Looks like we failed to unmask 11b rates previously. This could |
| 3916 | * happen, e.g., if the interface was down at the point in time when a |
| 3917 | * P2P group was terminated. |
| 3918 | */ |
| 3919 | wpa_printf(MSG_DEBUG, |
| 3920 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3921 | bss->ifname); |
| 3922 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3923 | } |
| 3924 | |
| 3925 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3926 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3927 | { |
| 3928 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3929 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3930 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3931 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3932 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3933 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3934 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3935 | return NL80211_AUTHTYPE_FT; |
| 3936 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3937 | return NL80211_AUTHTYPE_SAE; |
| 3938 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3939 | return NL80211_AUTHTYPE_FILS_SK; |
| 3940 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3941 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3942 | |
| 3943 | return NL80211_AUTHTYPE_MAX; |
| 3944 | } |
| 3945 | |
| 3946 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3947 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3948 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3949 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3950 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3951 | int ret = -1, i; |
| 3952 | struct nl_msg *msg; |
| 3953 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3954 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3956 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3957 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3958 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3959 | nl80211_unmask_11b_rates(bss); |
| 3960 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3961 | is_retry = drv->retry_auth; |
| 3962 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3963 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3964 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3965 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3966 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3967 | if (params->bssid) |
| 3968 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3969 | else |
| 3970 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3972 | nlmode = params->p2p ? |
| 3973 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3974 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3975 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3976 | return -1; |
| 3977 | |
| 3978 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3979 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3980 | drv->ifindex); |
| 3981 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3982 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3983 | if (!msg) |
| 3984 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3986 | os_memset(&p, 0, sizeof(p)); |
| 3987 | p.ifname = bss->ifname; |
| 3988 | p.alg = WPA_ALG_WEP; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 3989 | p.link_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | for (i = 0; i < 4; i++) { |
| 3991 | if (!params->wep_key[i]) |
| 3992 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3993 | p.key_idx = i; |
| 3994 | p.set_tx = i == params->wep_tx_keyidx; |
| 3995 | p.key = params->wep_key[i]; |
| 3996 | p.key_len = params->wep_key_len[i]; |
| 3997 | p.key_flag = i == params->wep_tx_keyidx ? |
| 3998 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 3999 | KEY_FLAG_GROUP_RX_TX; |
| 4000 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4001 | if (params->wep_tx_keyidx != i) |
| 4002 | continue; |
| 4003 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4004 | params->wep_key[i], params->wep_key_len[i])) |
| 4005 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4008 | if (params->bssid) { |
| 4009 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4010 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4011 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4012 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4013 | } |
| 4014 | if (params->freq) { |
| 4015 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 4017 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4018 | } |
| 4019 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4020 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 4021 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4022 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4023 | params->ssid)) |
| 4024 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4025 | } |
| 4026 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4027 | if (params->ie && |
| 4028 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 4029 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4030 | if (params->auth_data) { |
| 4031 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 4032 | params->auth_data_len); |
| 4033 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 4034 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4035 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4036 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4037 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4038 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4039 | if (type == NL80211_AUTHTYPE_MAX || |
| 4040 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4041 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4042 | if (params->local_state_change) { |
| 4043 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4044 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 4045 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4048 | if (params->mld && params->ap_mld_addr) { |
| 4049 | wpa_printf(MSG_DEBUG, " * MLD: link_id=%u, MLD addr=" MACSTR, |
| 4050 | params->mld_link_id, MAC2STR(params->ap_mld_addr)); |
| 4051 | |
| 4052 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 4053 | params->mld_link_id) || |
| 4054 | nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, |
| 4055 | params->ap_mld_addr)) |
| 4056 | goto fail; |
| 4057 | } |
| 4058 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4059 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4060 | msg = NULL; |
| 4061 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4062 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4063 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 4064 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4065 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4066 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 4067 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4068 | /* |
| 4069 | * mac80211 does not currently accept new |
| 4070 | * authentication if we are already authenticated. As a |
| 4071 | * workaround, force deauthentication and try again. |
| 4072 | */ |
| 4073 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 4074 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4075 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4076 | wpa_driver_nl80211_deauthenticate( |
| 4077 | bss, params->bssid, |
| 4078 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 4079 | nlmsg_free(msg); |
| 4080 | goto retry; |
| 4081 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4082 | |
| 4083 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 4084 | /* |
| 4085 | * cfg80211 has likely expired the BSS entry even |
| 4086 | * though it was previously available in our internal |
| 4087 | * BSS table. To recover quickly, start a single |
| 4088 | * channel scan on the specified channel. |
| 4089 | */ |
| 4090 | struct wpa_driver_scan_params scan; |
| 4091 | int freqs[2]; |
| 4092 | |
| 4093 | os_memset(&scan, 0, sizeof(scan)); |
| 4094 | scan.num_ssids = 1; |
| 4095 | if (params->ssid) { |
| 4096 | scan.ssids[0].ssid = params->ssid; |
| 4097 | scan.ssids[0].ssid_len = params->ssid_len; |
| 4098 | } |
| 4099 | freqs[0] = params->freq; |
| 4100 | freqs[1] = 0; |
| 4101 | scan.freqs = freqs; |
| 4102 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 4103 | "channel scan to refresh cfg80211 BSS " |
| 4104 | "entry"); |
| 4105 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 4106 | if (ret == 0) { |
| 4107 | nl80211_copy_auth_params(drv, params); |
| 4108 | drv->scan_for_auth = 1; |
| 4109 | } |
| 4110 | } else if (is_retry) { |
| 4111 | /* |
| 4112 | * Need to indicate this with an event since the return |
| 4113 | * value from the retry is not delivered to core code. |
| 4114 | */ |
| 4115 | union wpa_event_data event; |
| 4116 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 4117 | "failed"); |
| 4118 | os_memset(&event, 0, sizeof(event)); |
| 4119 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 4120 | ETH_ALEN); |
| 4121 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 4122 | &event); |
| 4123 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4124 | } else { |
| 4125 | wpa_printf(MSG_DEBUG, |
| 4126 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4127 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4128 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4129 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4130 | nlmsg_free(msg); |
| 4131 | return ret; |
| 4132 | } |
| 4133 | |
| 4134 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4135 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4136 | { |
| 4137 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4138 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4139 | int i; |
| 4140 | |
| 4141 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 4142 | |
| 4143 | os_memset(¶ms, 0, sizeof(params)); |
| 4144 | params.freq = drv->auth_freq; |
| 4145 | params.auth_alg = drv->auth_alg; |
| 4146 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 4147 | params.local_state_change = drv->auth_local_state_change; |
| 4148 | params.p2p = drv->auth_p2p; |
| 4149 | |
| 4150 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 4151 | params.bssid = drv->auth_bssid_; |
| 4152 | |
| 4153 | if (drv->auth_ssid_len) { |
| 4154 | params.ssid = drv->auth_ssid; |
| 4155 | params.ssid_len = drv->auth_ssid_len; |
| 4156 | } |
| 4157 | |
| 4158 | params.ie = drv->auth_ie; |
| 4159 | params.ie_len = drv->auth_ie_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4160 | params.auth_data = drv->auth_data; |
| 4161 | params.auth_data_len = drv->auth_data_len; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4162 | params.mld = drv->auth_mld; |
| 4163 | params.mld_link_id = drv->auth_mld_link_id; |
| 4164 | if (drv->auth_mld) |
| 4165 | params.ap_mld_addr = drv->auth_ap_mld_addr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4166 | |
| 4167 | for (i = 0; i < 4; i++) { |
| 4168 | if (drv->auth_wep_key_len[i]) { |
| 4169 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 4170 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 4171 | } |
| 4172 | } |
| 4173 | |
| 4174 | drv->retry_auth = 1; |
| 4175 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 4176 | } |
| 4177 | |
| 4178 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4179 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 4180 | size_t data_len, int noack, |
| 4181 | unsigned int freq, int no_cck, |
| 4182 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4183 | unsigned int wait_time, |
| 4184 | const u16 *csa_offs, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4185 | size_t csa_offs_len, int no_encrypt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4186 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4187 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4188 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4189 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4190 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4191 | int use_cookie = 1; |
| 4192 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | |
| 4194 | mgmt = (struct ieee80211_mgmt *) data; |
| 4195 | fc = le_to_host16(mgmt->frame_control); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4196 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR |
| 4197 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d", |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 4198 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4199 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4200 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4201 | if ((is_sta_interface(drv->nlmode) || |
| 4202 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4203 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4204 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 4205 | /* |
| 4206 | * The use of last_mgmt_freq is a bit of a hack, |
| 4207 | * but it works due to the single-threaded nature |
| 4208 | * of wpa_supplicant. |
| 4209 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4210 | if (freq == 0) { |
| 4211 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 4212 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4213 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4214 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4215 | wait_time = 0; |
| 4216 | use_cookie = 0; |
| 4217 | no_cck = 1; |
| 4218 | offchanok = 1; |
| 4219 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4220 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4221 | |
| 4222 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4223 | if (freq == 0) { |
| 4224 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 4225 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4226 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4227 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4228 | if ((int) freq == bss->freq) |
| 4229 | wait_time = 0; |
| 4230 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 4231 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 4232 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4233 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4234 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4235 | /* |
| 4236 | * Only one of the authentication frame types is encrypted. |
| 4237 | * In order for static WEP encryption to work properly (i.e., |
| 4238 | * to not encrypt the frame), we need to tell mac80211 about |
| 4239 | * the frames that must not be encrypted. |
| 4240 | */ |
| 4241 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4242 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4243 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 4244 | encrypt = 0; |
| 4245 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4246 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4247 | if (is_sta_interface(drv->nlmode) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4248 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4249 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4250 | if (freq == 0 && |
| 4251 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 4252 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 4253 | freq = nl80211_get_assoc_freq(drv); |
| 4254 | wpa_printf(MSG_DEBUG, |
| 4255 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 4256 | freq); |
| 4257 | } |
| 4258 | |
| 4259 | /* Allow off channel for PASN authentication */ |
| 4260 | if (data_len >= IEEE80211_HDRLEN + 2 && |
| 4261 | WPA_GET_LE16(data + IEEE80211_HDRLEN) == WLAN_AUTH_PASN && |
| 4262 | !offchanok) { |
| 4263 | wpa_printf(MSG_DEBUG, |
| 4264 | "nl80211: send_mlme: allow off channel for PASN"); |
| 4265 | offchanok = 1; |
| 4266 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4269 | #ifdef CONFIG_PASN |
| 4270 | if (is_sta_interface(drv->nlmode) && |
| 4271 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4272 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DEAUTH) { |
| 4273 | wpa_printf(MSG_DEBUG, |
| 4274 | "nl80211: send_mlme: allow Deauthentication frame for PASN"); |
| 4275 | |
| 4276 | use_cookie = 0; |
| 4277 | offchanok = 1; |
| 4278 | goto send_frame_cmd; |
| 4279 | } |
| 4280 | #endif /* CONFIG_PASN */ |
| 4281 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4282 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4283 | freq = nl80211_get_assoc_freq(drv); |
| 4284 | wpa_printf(MSG_DEBUG, |
| 4285 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 4286 | freq); |
| 4287 | } |
| 4288 | if (freq == 0) { |
| 4289 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
| 4290 | bss->freq); |
| 4291 | freq = bss->freq; |
| 4292 | } |
| 4293 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4294 | if (drv->use_monitor && is_ap_interface(drv->nlmode)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4295 | wpa_printf(MSG_DEBUG, |
| 4296 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
| 4297 | freq, bss->freq); |
| 4298 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4299 | noack); |
| 4300 | } |
| 4301 | |
| 4302 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 4303 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 4304 | use_cookie = 0; |
| 4305 | send_frame_cmd: |
| 4306 | #ifdef CONFIG_TESTING_OPTIONS |
| 4307 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 4308 | wpa_printf(MSG_DEBUG, |
| 4309 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 4310 | if (nl80211_create_monitor_interface(drv) < 0) |
| 4311 | return -1; |
| 4312 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4313 | noack); |
| 4314 | nl80211_remove_monitor_interface(drv); |
| 4315 | return res; |
| 4316 | } |
| 4317 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4318 | |
| 4319 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 4320 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 4321 | use_cookie, no_cck, noack, offchanok, |
| 4322 | csa_offs, csa_offs_len); |
| 4323 | |
| 4324 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4328 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 4329 | { |
| 4330 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 4331 | u8 rates_len = 0; |
| 4332 | int i; |
| 4333 | |
| 4334 | if (!basic_rates) |
| 4335 | return 0; |
| 4336 | |
| 4337 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 4338 | rates[rates_len++] = basic_rates[i] / 5; |
| 4339 | |
| 4340 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 4341 | } |
| 4342 | |
| 4343 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4344 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 4345 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4346 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4347 | { |
| 4348 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4349 | struct nl_msg *msg; |
| 4350 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4351 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 4352 | (cts >= 0 && |
| 4353 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 4354 | (preamble >= 0 && |
| 4355 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 4356 | (slot >= 0 && |
| 4357 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 4358 | (ht_opmode >= 0 && |
| 4359 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 4360 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4361 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 4362 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 4363 | nlmsg_free(msg); |
| 4364 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4365 | } |
| 4366 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4367 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4371 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 4372 | struct hostapd_acl_params *params) |
| 4373 | { |
| 4374 | struct i802_bss *bss = priv; |
| 4375 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4376 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4377 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4378 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4379 | int ret; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4380 | size_t acl_nla_sz, acl_nlmsg_sz, nla_sz, nlmsg_sz; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4381 | |
| 4382 | if (!(drv->capa.max_acl_mac_addrs)) |
| 4383 | return -ENOTSUP; |
| 4384 | |
| 4385 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 4386 | return -ENOTSUP; |
| 4387 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4388 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 4389 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 4390 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4391 | acl_nla_sz = nla_total_size(ETH_ALEN) * params->num_mac_acl; |
| 4392 | acl_nlmsg_sz = nlmsg_total_size(acl_nla_sz); |
| 4393 | acl = nlmsg_alloc_size(acl_nlmsg_sz); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4394 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4395 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4396 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4397 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 4398 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4399 | return -ENOMEM; |
| 4400 | } |
| 4401 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4402 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4403 | /* |
| 4404 | * genetlink message header (Length of user header is 0) + |
| 4405 | * u32 attr: NL80211_ATTR_IFINDEX + |
| 4406 | * u32 attr: NL80211_ATTR_ACL_POLICY + |
| 4407 | * nested acl attr |
| 4408 | */ |
| 4409 | nla_sz = GENL_HDRLEN + |
| 4410 | nla_total_size(4) * 2 + |
| 4411 | nla_total_size(acl_nla_sz); |
| 4412 | nlmsg_sz = nlmsg_total_size(nla_sz); |
| 4413 | if (!(msg = nl80211_ifindex_msg_build(drv, nlmsg_alloc_size(nlmsg_sz), |
| 4414 | drv->ifindex, 0, |
| 4415 | NL80211_CMD_SET_MAC_ACL)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4416 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 4417 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 4418 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 4419 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 4420 | nlmsg_free(msg); |
| 4421 | nlmsg_free(acl); |
| 4422 | return -ENOMEM; |
| 4423 | } |
| 4424 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4425 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4426 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4427 | if (ret) { |
| 4428 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 4429 | ret, strerror(-ret)); |
| 4430 | } |
| 4431 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4432 | return ret; |
| 4433 | } |
| 4434 | |
| 4435 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4436 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 4437 | { |
| 4438 | if (beacon_int > 0) { |
| 4439 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 4440 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4441 | beacon_int); |
| 4442 | } |
| 4443 | |
| 4444 | return 0; |
| 4445 | } |
| 4446 | |
| 4447 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4448 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 4449 | { |
| 4450 | if (dtim_period > 0) { |
| 4451 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 4452 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 4453 | } |
| 4454 | |
| 4455 | return 0; |
| 4456 | } |
| 4457 | |
| 4458 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4459 | #ifdef CONFIG_MESH |
| 4460 | static int nl80211_set_mesh_config(void *priv, |
| 4461 | struct wpa_driver_mesh_bss_params *params) |
| 4462 | { |
| 4463 | struct i802_bss *bss = priv; |
| 4464 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4465 | struct nl_msg *msg; |
| 4466 | int ret; |
| 4467 | |
| 4468 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4469 | if (!msg) |
| 4470 | return -1; |
| 4471 | |
| 4472 | ret = nl80211_put_mesh_config(msg, params); |
| 4473 | if (ret < 0) { |
| 4474 | nlmsg_free(msg); |
| 4475 | return ret; |
| 4476 | } |
| 4477 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4478 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4479 | if (ret) { |
| 4480 | wpa_printf(MSG_ERROR, |
| 4481 | "nl80211: Mesh config set failed: %d (%s)", |
| 4482 | ret, strerror(-ret)); |
| 4483 | return ret; |
| 4484 | } |
| 4485 | return 0; |
| 4486 | } |
| 4487 | #endif /* CONFIG_MESH */ |
| 4488 | |
| 4489 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4490 | 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] | 4491 | struct wpa_driver_ap_params *params) |
| 4492 | { |
| 4493 | struct nlattr *bands, *band; |
| 4494 | struct nl80211_txrate_vht vht_rate; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4495 | struct nl80211_txrate_he he_rate; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4496 | |
| 4497 | if (!params->freq || |
| 4498 | (params->beacon_rate == 0 && |
| 4499 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4500 | return 0; |
| 4501 | |
| 4502 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4503 | if (!bands) |
| 4504 | return -1; |
| 4505 | |
| 4506 | switch (params->freq->mode) { |
| 4507 | case HOSTAPD_MODE_IEEE80211B: |
| 4508 | case HOSTAPD_MODE_IEEE80211G: |
| 4509 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4510 | break; |
| 4511 | case HOSTAPD_MODE_IEEE80211A: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4512 | if (is_6ghz_freq(params->freq->freq)) |
| 4513 | band = nla_nest_start(msg, NL80211_BAND_6GHZ); |
| 4514 | else |
| 4515 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4516 | break; |
| 4517 | case HOSTAPD_MODE_IEEE80211AD: |
| 4518 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4519 | break; |
| 4520 | default: |
| 4521 | return 0; |
| 4522 | } |
| 4523 | |
| 4524 | if (!band) |
| 4525 | return -1; |
| 4526 | |
| 4527 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4528 | os_memset(&he_rate, 0, sizeof(he_rate)); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4529 | |
| 4530 | switch (params->rate_type) { |
| 4531 | case BEACON_RATE_LEGACY: |
| 4532 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4533 | wpa_printf(MSG_INFO, |
| 4534 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4535 | return -1; |
| 4536 | } |
| 4537 | |
| 4538 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 4539 | (u8) params->beacon_rate / 5) || |
| 4540 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4541 | (params->freq->vht_enabled && |
| 4542 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4543 | &vht_rate))) |
| 4544 | return -1; |
| 4545 | |
| 4546 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4547 | params->beacon_rate); |
| 4548 | break; |
| 4549 | case BEACON_RATE_HT: |
| 4550 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4551 | wpa_printf(MSG_INFO, |
| 4552 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4553 | return -1; |
| 4554 | } |
| 4555 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4556 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4557 | (params->freq->vht_enabled && |
| 4558 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4559 | &vht_rate))) |
| 4560 | return -1; |
| 4561 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4562 | params->beacon_rate); |
| 4563 | break; |
| 4564 | case BEACON_RATE_VHT: |
| 4565 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4566 | wpa_printf(MSG_INFO, |
| 4567 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4568 | return -1; |
| 4569 | } |
| 4570 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4571 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4572 | return -1; |
| 4573 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4574 | return -1; |
| 4575 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4576 | &vht_rate)) |
| 4577 | return -1; |
| 4578 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4579 | params->beacon_rate); |
| 4580 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4581 | case BEACON_RATE_HE: |
| 4582 | if (!(flags2 & WPA_DRIVER_FLAGS2_BEACON_RATE_HE)) { |
| 4583 | wpa_printf(MSG_INFO, |
| 4584 | "nl80211: Driver does not support setting Beacon frame rate (HE)"); |
| 4585 | return -1; |
| 4586 | } |
| 4587 | he_rate.mcs[0] = BIT(params->beacon_rate); |
| 4588 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4589 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4590 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4591 | &vht_rate) || |
| 4592 | nla_put(msg, NL80211_TXRATE_HE, sizeof(he_rate), &he_rate)) |
| 4593 | return -1; |
| 4594 | wpa_printf(MSG_DEBUG, " * beacon_rate = HE-MCS %u", |
| 4595 | params->beacon_rate); |
| 4596 | break; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | nla_nest_end(msg, band); |
| 4600 | nla_nest_end(msg, bands); |
| 4601 | |
| 4602 | return 0; |
| 4603 | } |
| 4604 | |
| 4605 | |
| 4606 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4607 | int multicast_to_unicast) |
| 4608 | { |
| 4609 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4610 | struct nl_msg *msg; |
| 4611 | int ret; |
| 4612 | |
| 4613 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4614 | if (!msg || |
| 4615 | (multicast_to_unicast && |
| 4616 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4617 | wpa_printf(MSG_ERROR, |
| 4618 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4619 | bss->ifname); |
| 4620 | nlmsg_free(msg); |
| 4621 | return -ENOBUFS; |
| 4622 | } |
| 4623 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4624 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4625 | |
| 4626 | switch (ret) { |
| 4627 | case 0: |
| 4628 | wpa_printf(MSG_DEBUG, |
| 4629 | "nl80211: multicast to unicast %s on interface %s", |
| 4630 | multicast_to_unicast ? "enabled" : "disabled", |
| 4631 | bss->ifname); |
| 4632 | break; |
| 4633 | case -EOPNOTSUPP: |
| 4634 | if (!multicast_to_unicast) |
| 4635 | break; |
| 4636 | wpa_printf(MSG_INFO, |
| 4637 | "nl80211: multicast to unicast not supported on interface %s", |
| 4638 | bss->ifname); |
| 4639 | break; |
| 4640 | default: |
| 4641 | wpa_printf(MSG_ERROR, |
| 4642 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4643 | multicast_to_unicast ? "enabling" : "disabling", |
| 4644 | ret, strerror(-ret), bss->ifname); |
| 4645 | break; |
| 4646 | } |
| 4647 | |
| 4648 | return ret; |
| 4649 | } |
| 4650 | |
| 4651 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4652 | #ifdef CONFIG_SAE |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4653 | 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] | 4654 | { |
| 4655 | u8 sae_pwe; |
| 4656 | |
| 4657 | wpa_printf(MSG_DEBUG, "nl802111: sae_pwe=%d", pwe); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4658 | if (pwe == SAE_PWE_HUNT_AND_PECK) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4659 | sae_pwe = NL80211_SAE_PWE_HUNT_AND_PECK; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4660 | else if (pwe == SAE_PWE_HASH_TO_ELEMENT) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4661 | sae_pwe = NL80211_SAE_PWE_HASH_TO_ELEMENT; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4662 | else if (pwe == SAE_PWE_BOTH) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4663 | sae_pwe = NL80211_SAE_PWE_BOTH; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4664 | else if (pwe == SAE_PWE_FORCE_HUNT_AND_PECK) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4665 | return 0; /* special test mode */ |
| 4666 | else |
| 4667 | return -1; |
| 4668 | if (nla_put_u8(msg, NL80211_ATTR_SAE_PWE, sae_pwe)) |
| 4669 | return -1; |
| 4670 | |
| 4671 | return 0; |
| 4672 | } |
| 4673 | #endif /* CONFIG_SAE */ |
| 4674 | |
| 4675 | |
| 4676 | #ifdef CONFIG_FILS |
| 4677 | static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
| 4678 | struct wpa_driver_ap_params *params) |
| 4679 | { |
| 4680 | struct nlattr *attr; |
| 4681 | |
| 4682 | if (!bss->drv->fils_discovery) { |
| 4683 | wpa_printf(MSG_ERROR, |
| 4684 | "nl80211: Driver does not support FILS Discovery frame transmission for %s", |
| 4685 | bss->ifname); |
| 4686 | return -1; |
| 4687 | } |
| 4688 | |
| 4689 | attr = nla_nest_start(msg, NL80211_ATTR_FILS_DISCOVERY); |
| 4690 | if (!attr || |
| 4691 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 4692 | params->fd_min_int) || |
| 4693 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 4694 | params->fd_max_int) || |
| 4695 | (params->fd_frame_tmpl && |
| 4696 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 4697 | params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 4698 | return -1; |
| 4699 | |
| 4700 | nla_nest_end(msg, attr); |
| 4701 | return 0; |
| 4702 | } |
| 4703 | #endif /* CONFIG_FILS */ |
| 4704 | |
| 4705 | |
| 4706 | #ifdef CONFIG_IEEE80211AX |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4707 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4708 | static int nl80211_unsol_bcast_probe_resp(struct i802_bss *bss, |
| 4709 | struct nl_msg *msg, |
| 4710 | struct wpa_driver_ap_params *params) |
| 4711 | { |
| 4712 | struct nlattr *attr; |
| 4713 | |
| 4714 | if (!bss->drv->unsol_bcast_probe_resp) { |
| 4715 | wpa_printf(MSG_ERROR, |
| 4716 | "nl80211: Driver does not support unsolicited broadcast Probe Response frame transmission for %s", |
| 4717 | bss->ifname); |
| 4718 | return -1; |
| 4719 | } |
| 4720 | |
| 4721 | wpa_printf(MSG_DEBUG, |
| 4722 | "nl80211: Unsolicited broadcast Probe Response frame interval: %u", |
| 4723 | params->unsol_bcast_probe_resp_interval); |
| 4724 | attr = nla_nest_start(msg, NL80211_ATTR_UNSOL_BCAST_PROBE_RESP); |
| 4725 | if (!attr || |
| 4726 | nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT, |
| 4727 | params->unsol_bcast_probe_resp_interval) || |
| 4728 | (params->unsol_bcast_probe_resp_tmpl && |
| 4729 | nla_put(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL, |
| 4730 | params->unsol_bcast_probe_resp_tmpl_len, |
| 4731 | params->unsol_bcast_probe_resp_tmpl))) |
| 4732 | return -1; |
| 4733 | |
| 4734 | nla_nest_end(msg, attr); |
| 4735 | return 0; |
| 4736 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 4737 | |
| 4738 | |
| 4739 | static int nl80211_mbssid(struct nl_msg *msg, |
| 4740 | struct wpa_driver_ap_params *params) |
| 4741 | { |
| 4742 | struct nlattr *config, *elems; |
| 4743 | int ifidx; |
| 4744 | |
| 4745 | if (!params->mbssid_tx_iface) |
| 4746 | return 0; |
| 4747 | |
| 4748 | config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); |
| 4749 | if (!config || |
| 4750 | nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_INDEX, |
| 4751 | params->mbssid_index)) |
| 4752 | return -1; |
| 4753 | |
| 4754 | if (params->mbssid_tx_iface) { |
| 4755 | ifidx = if_nametoindex(params->mbssid_tx_iface); |
| 4756 | if (ifidx <= 0 || |
| 4757 | nla_put_u32(msg, NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX, |
| 4758 | ifidx)) |
| 4759 | return -1; |
| 4760 | } |
| 4761 | |
| 4762 | if (params->ema && nla_put_flag(msg, NL80211_MBSSID_CONFIG_ATTR_EMA)) |
| 4763 | return -1; |
| 4764 | |
| 4765 | nla_nest_end(msg, config); |
| 4766 | |
| 4767 | if (params->mbssid_elem_count && params->mbssid_elem_len && |
| 4768 | params->mbssid_elem_offset && *params->mbssid_elem_offset) { |
| 4769 | u8 i, **offs = params->mbssid_elem_offset; |
| 4770 | |
| 4771 | elems = nla_nest_start(msg, NL80211_ATTR_MBSSID_ELEMS); |
| 4772 | if (!elems) |
| 4773 | return -1; |
| 4774 | |
| 4775 | for (i = 0; i < params->mbssid_elem_count - 1; i++) { |
| 4776 | if (nla_put(msg, i + 1, offs[i + 1] - offs[i], offs[i])) |
| 4777 | return -1; |
| 4778 | } |
| 4779 | |
| 4780 | if (nla_put(msg, i + 1, |
| 4781 | *offs + params->mbssid_elem_len - offs[i], |
| 4782 | offs[i])) |
| 4783 | return -1; |
| 4784 | |
| 4785 | nla_nest_end(msg, elems); |
| 4786 | } |
| 4787 | |
| 4788 | return 0; |
| 4789 | } |
| 4790 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4791 | #endif /* CONFIG_IEEE80211AX */ |
| 4792 | |
| 4793 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4794 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4795 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4796 | { |
| 4797 | struct i802_bss *bss = priv; |
| 4798 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4799 | struct nl_msg *msg; |
| 4800 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4801 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4802 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4803 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4804 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4805 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4806 | #ifdef CONFIG_MESH |
| 4807 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4808 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4809 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4810 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4811 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4812 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4813 | beacon_set); |
| 4814 | if (beacon_set) |
| 4815 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4816 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4817 | !nl80211_get_wiphy_data_ap(bss)) |
| 4818 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4819 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4820 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4821 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4822 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4823 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4824 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4825 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4826 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4827 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4828 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4829 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4830 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4831 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4832 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4833 | params->head) || |
| 4834 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4835 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4836 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4837 | nl80211_put_beacon_rate(msg, drv->capa.flags, drv->capa.flags2, |
| 4838 | params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4839 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4840 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4841 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4842 | if (params->proberesp && params->proberesp_len) { |
| 4843 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4844 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4845 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4846 | params->proberesp)) |
| 4847 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4848 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4849 | switch (params->hide_ssid) { |
| 4850 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4851 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4852 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4853 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4854 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4855 | break; |
| 4856 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4857 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4858 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4859 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4860 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4861 | break; |
| 4862 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4863 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4864 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4865 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4866 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4867 | break; |
| 4868 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4869 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4870 | if (params->privacy && |
| 4871 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4872 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4873 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4874 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4875 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4876 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4877 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4878 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4879 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4880 | goto fail; |
| 4881 | } else { |
| 4882 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4883 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4884 | goto fail; |
| 4885 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4886 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4887 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4888 | ver = 0; |
| 4889 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4890 | ver |= NL80211_WPA_VERSION_1; |
| 4891 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4892 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4893 | if (ver && |
| 4894 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4895 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4896 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4897 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4898 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4899 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 4900 | suites, ARRAY_SIZE(suites)); |
| 4901 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4902 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4903 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", |
| 4904 | num_suites); |
| 4905 | else if (num_suites && |
| 4906 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4907 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4908 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4909 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4910 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4911 | (!params->pairwise_ciphers || |
| 4912 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4913 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4914 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4915 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4916 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4917 | if (drv->device_ap_sme) { |
| 4918 | u32 flags = 0; |
| 4919 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4920 | if (params->key_mgmt_suites & (WPA_KEY_MGMT_SAE | |
| 4921 | WPA_KEY_MGMT_SAE_EXT_KEY)) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4922 | /* Add the previously used flag attribute to support |
| 4923 | * older kernel versions and the newer flag bit for |
| 4924 | * newer kernels. */ |
| 4925 | if (nla_put_flag(msg, |
| 4926 | NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4927 | goto fail; |
| 4928 | flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 4929 | } |
| 4930 | |
| 4931 | flags |= NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT; |
| 4932 | |
| 4933 | if (nla_put_u32(msg, NL80211_ATTR_AP_SETTINGS_FLAGS, flags)) |
| 4934 | goto fail; |
| 4935 | } |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4936 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4937 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4938 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4939 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4940 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4941 | if (num_suites && |
| 4942 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4943 | num_suites * sizeof(u32), suites)) |
| 4944 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4945 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4946 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4947 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4948 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4949 | if (suite && |
| 4950 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4951 | goto fail; |
| 4952 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4953 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4954 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4955 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4956 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4957 | wpabuf_len(params->beacon_ies), |
| 4958 | wpabuf_head(params->beacon_ies))) |
| 4959 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4960 | } |
| 4961 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4962 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4963 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4964 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4965 | wpabuf_len(params->proberesp_ies), |
| 4966 | wpabuf_head(params->proberesp_ies))) |
| 4967 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4968 | } |
| 4969 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4970 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4971 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4972 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4973 | wpabuf_len(params->assocresp_ies), |
| 4974 | wpabuf_head(params->assocresp_ies))) |
| 4975 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4976 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4977 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4978 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4979 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4980 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4981 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4982 | params->ap_max_inactivity)) |
| 4983 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4986 | #ifdef CONFIG_P2P |
| 4987 | if (params->p2p_go_ctwindow > 0) { |
| 4988 | if (drv->p2p_go_ctwindow_supported) { |
| 4989 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4990 | params->p2p_go_ctwindow); |
| 4991 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4992 | params->p2p_go_ctwindow)) |
| 4993 | goto fail; |
| 4994 | } else { |
| 4995 | wpa_printf(MSG_INFO, |
| 4996 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4997 | } |
| 4998 | } |
| 4999 | #endif /* CONFIG_P2P */ |
| 5000 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5001 | if (params->pbss) { |
| 5002 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 5003 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5004 | goto fail; |
| 5005 | } |
| 5006 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5007 | if (params->ftm_responder) { |
| 5008 | struct nlattr *ftm; |
| 5009 | |
| 5010 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 5011 | ret = -ENOTSUP; |
| 5012 | goto fail; |
| 5013 | } |
| 5014 | |
| 5015 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 5016 | if (!ftm || |
| 5017 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 5018 | (params->lci && |
| 5019 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 5020 | wpabuf_len(params->lci), |
| 5021 | wpabuf_head(params->lci))) || |
| 5022 | (params->civic && |
| 5023 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 5024 | wpabuf_len(params->civic), |
| 5025 | wpabuf_head(params->civic)))) |
| 5026 | goto fail; |
| 5027 | nla_nest_end(msg, ftm); |
| 5028 | } |
| 5029 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5030 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5031 | if (params->he_spr_ctrl) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5032 | struct nlattr *spr; |
| 5033 | |
| 5034 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5035 | wpa_printf(MSG_DEBUG, "nl80211: he_spr_ctrl=0x%x", |
| 5036 | params->he_spr_ctrl); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5037 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5038 | if (!spr || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5039 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_SR_CTRL, |
| 5040 | params->he_spr_ctrl) || |
| 5041 | ((params->he_spr_ctrl & |
| 5042 | SPATIAL_REUSE_NON_SRG_OFFSET_PRESENT) && |
| 5043 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET, |
| 5044 | params->he_spr_non_srg_obss_pd_max_offset))) |
| 5045 | goto fail; |
| 5046 | |
| 5047 | if ((params->he_spr_ctrl & |
| 5048 | SPATIAL_REUSE_SRG_INFORMATION_PRESENT) && |
| 5049 | (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
| 5050 | params->he_spr_srg_obss_pd_min_offset) || |
| 5051 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 5052 | params->he_spr_srg_obss_pd_max_offset) || |
| 5053 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP, |
| 5054 | sizeof(params->he_spr_bss_color_bitmap), |
| 5055 | params->he_spr_bss_color_bitmap) || |
| 5056 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP, |
| 5057 | sizeof(params->he_spr_partial_bssid_bitmap), |
| 5058 | params->he_spr_partial_bssid_bitmap))) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5059 | goto fail; |
| 5060 | |
| 5061 | nla_nest_end(msg, spr); |
| 5062 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5063 | |
| 5064 | if (params->freq && params->freq->he_enabled) { |
| 5065 | struct nlattr *bss_color; |
| 5066 | |
| 5067 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 5068 | if (!bss_color || |
| 5069 | (params->he_bss_color_disabled && |
| 5070 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 5071 | (params->he_bss_color_partial && |
| 5072 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 5073 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 5074 | params->he_bss_color)) |
| 5075 | goto fail; |
| 5076 | nla_nest_end(msg, bss_color); |
| 5077 | } |
| 5078 | |
| 5079 | if (params->twt_responder) { |
| 5080 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 5081 | params->twt_responder); |
| 5082 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 5083 | goto fail; |
| 5084 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5085 | |
| 5086 | if (params->unsol_bcast_probe_resp_interval && |
| 5087 | nl80211_unsol_bcast_probe_resp(bss, msg, params) < 0) |
| 5088 | goto fail; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 5089 | |
| 5090 | if (nl80211_mbssid(msg, params) < 0) |
| 5091 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5092 | #endif /* CONFIG_IEEE80211AX */ |
| 5093 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5094 | #ifdef CONFIG_SAE |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 5095 | if (wpa_key_mgmt_sae(params->key_mgmt_suites) && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5096 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 5097 | goto fail; |
| 5098 | #endif /* CONFIG_SAE */ |
| 5099 | |
| 5100 | #ifdef CONFIG_FILS |
| 5101 | if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
| 5102 | goto fail; |
| 5103 | #endif /* CONFIG_FILS */ |
| 5104 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5105 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5106 | if (ret) { |
| 5107 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 5108 | ret, strerror(-ret)); |
| 5109 | } else { |
| 5110 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5111 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 5112 | params->short_slot_time, params->ht_opmode, |
| 5113 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5114 | nl80211_set_multicast_to_unicast(bss, |
| 5115 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5116 | if (beacon_set && params->freq && |
| 5117 | params->freq->bandwidth != bss->bandwidth) { |
| 5118 | wpa_printf(MSG_DEBUG, |
| 5119 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 5120 | bss->ifname, bss->bandwidth, |
| 5121 | params->freq->bandwidth); |
| 5122 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 5123 | if (ret) { |
| 5124 | wpa_printf(MSG_DEBUG, |
| 5125 | "nl80211: Frequency set failed: %d (%s)", |
| 5126 | ret, strerror(-ret)); |
| 5127 | } else { |
| 5128 | wpa_printf(MSG_DEBUG, |
| 5129 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 5130 | bss->bandwidth = params->freq->bandwidth; |
| 5131 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5132 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5133 | /* |
| 5134 | * cfg80211 updates the driver on frequence change in AP |
| 5135 | * mode only at the point when beaconing is started, so |
| 5136 | * set the initial value here. |
| 5137 | */ |
| 5138 | bss->bandwidth = params->freq->bandwidth; |
| 5139 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5140 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5141 | |
| 5142 | #ifdef CONFIG_MESH |
| 5143 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 5144 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 5145 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 5146 | mesh_params.ht_opmode = params->ht_opmode; |
| 5147 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 5148 | if (ret < 0) |
| 5149 | return ret; |
| 5150 | } |
| 5151 | #endif /* CONFIG_MESH */ |
| 5152 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5153 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5154 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5155 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5156 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5160 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5161 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5162 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5163 | enum hostapd_hw_mode hw_mode; |
| 5164 | int is_24ghz; |
| 5165 | u8 channel; |
| 5166 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5167 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 5169 | return -ENOBUFS; |
| 5170 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5171 | wpa_printf(MSG_DEBUG, " * eht_enabled=%d", freq->eht_enabled); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5172 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5173 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 5174 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5175 | wpa_printf(MSG_DEBUG, " * radar_background=%d", |
| 5176 | freq->radar_background); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5177 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5178 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 5179 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 5180 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 5181 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5182 | if (freq->vht_enabled || |
| 5183 | ((freq->he_enabled || freq->eht_enabled) && !is_24ghz)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5184 | enum nl80211_chan_width cw; |
| 5185 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5186 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5187 | switch (freq->bandwidth) { |
| 5188 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5189 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5190 | break; |
| 5191 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5192 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5193 | break; |
| 5194 | case 80: |
| 5195 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5196 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5197 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5198 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5199 | break; |
| 5200 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5201 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5202 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5203 | case 320: |
| 5204 | cw = NL80211_CHAN_WIDTH_320; |
| 5205 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5206 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5207 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5208 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5209 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5210 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 5211 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 5212 | freq->center_freq1); |
| 5213 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 5214 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5215 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 5216 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 5217 | freq->center_freq1) || |
| 5218 | (freq->center_freq2 && |
| 5219 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 5220 | freq->center_freq2))) |
| 5221 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5222 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5223 | enum nl80211_channel_type ct; |
| 5224 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5225 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 5226 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5227 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5228 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5229 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5230 | break; |
| 5231 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5232 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5233 | break; |
| 5234 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5235 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5236 | break; |
| 5237 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5238 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5239 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5240 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 5241 | return -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5242 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 5243 | wpa_printf(MSG_DEBUG, |
| 5244 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5245 | freq->edmg.channels, freq->edmg.bw_config); |
| 5246 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5247 | freq->edmg.channels) || |
| 5248 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5249 | freq->edmg.bw_config)) |
| 5250 | return -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5251 | } else { |
| 5252 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 5253 | NL80211_CHAN_NO_HT); |
| 5254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 5255 | NL80211_CHAN_NO_HT)) |
| 5256 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5257 | } |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5258 | if (freq->radar_background && |
| 5259 | nla_put_flag(msg, NL80211_ATTR_RADAR_BACKGROUND)) |
| 5260 | return -ENOBUFS; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5261 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5262 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5266 | static int nl80211_set_channel(struct i802_bss *bss, |
| 5267 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5268 | { |
| 5269 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5270 | struct nl_msg *msg; |
| 5271 | int ret; |
| 5272 | |
| 5273 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5274 | "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)", |
| 5275 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 5276 | freq->he_enabled, freq->eht_enabled, freq->bandwidth, |
| 5277 | freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5278 | |
| 5279 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 5280 | NL80211_CMD_SET_WIPHY); |
| 5281 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 5282 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5283 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5284 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5285 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5286 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5287 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5288 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5289 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5290 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5291 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5292 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5293 | return -1; |
| 5294 | } |
| 5295 | |
| 5296 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5297 | static u32 sta_flags_nl80211(int flags) |
| 5298 | { |
| 5299 | u32 f = 0; |
| 5300 | |
| 5301 | if (flags & WPA_STA_AUTHORIZED) |
| 5302 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5303 | if (flags & WPA_STA_WMM) |
| 5304 | f |= BIT(NL80211_STA_FLAG_WME); |
| 5305 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 5306 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 5307 | if (flags & WPA_STA_MFP) |
| 5308 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 5309 | if (flags & WPA_STA_TDLS_PEER) |
| 5310 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5311 | if (flags & WPA_STA_AUTHENTICATED) |
| 5312 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5313 | if (flags & WPA_STA_ASSOCIATED) |
| 5314 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5315 | |
| 5316 | return f; |
| 5317 | } |
| 5318 | |
| 5319 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5320 | #ifdef CONFIG_MESH |
| 5321 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 5322 | { |
| 5323 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5324 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5325 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5326 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5327 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5328 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5329 | return NL80211_PLINK_OPN_RCVD; |
| 5330 | case PLINK_CNF_RCVD: |
| 5331 | return NL80211_PLINK_CNF_RCVD; |
| 5332 | case PLINK_ESTAB: |
| 5333 | return NL80211_PLINK_ESTAB; |
| 5334 | case PLINK_HOLDING: |
| 5335 | return NL80211_PLINK_HOLDING; |
| 5336 | case PLINK_BLOCKED: |
| 5337 | return NL80211_PLINK_BLOCKED; |
| 5338 | default: |
| 5339 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 5340 | state); |
| 5341 | } |
| 5342 | return -1; |
| 5343 | } |
| 5344 | #endif /* CONFIG_MESH */ |
| 5345 | |
| 5346 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5347 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 5348 | struct hostapd_sta_add_params *params) |
| 5349 | { |
| 5350 | struct i802_bss *bss = priv; |
| 5351 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5352 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5353 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5354 | int ret = -ENOBUFS; |
| 5355 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5356 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 5357 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 5358 | return -EOPNOTSUPP; |
| 5359 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5360 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 5361 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5362 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 5363 | NL80211_CMD_NEW_STATION); |
| 5364 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 5365 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5366 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5367 | /* |
| 5368 | * Set the below properties only in one of the following cases: |
| 5369 | * 1. New station is added, already associated. |
| 5370 | * 2. Set WPA_STA_TDLS_PEER station. |
| 5371 | * 3. Set an already added unassociated station, if driver supports |
| 5372 | * full AP client state. (Set these properties after station became |
| 5373 | * associated will be rejected by the driver). |
| 5374 | */ |
| 5375 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5376 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5377 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5378 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 5379 | params->supp_rates, params->supp_rates_len); |
| 5380 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 5381 | params->capability); |
| 5382 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 5383 | params->supp_rates_len, params->supp_rates) || |
| 5384 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 5385 | params->capability)) |
| 5386 | goto fail; |
| 5387 | |
| 5388 | if (params->ht_capabilities) { |
| 5389 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 5390 | (u8 *) params->ht_capabilities, |
| 5391 | sizeof(*params->ht_capabilities)); |
| 5392 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 5393 | sizeof(*params->ht_capabilities), |
| 5394 | params->ht_capabilities)) |
| 5395 | goto fail; |
| 5396 | } |
| 5397 | |
| 5398 | if (params->vht_capabilities) { |
| 5399 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 5400 | (u8 *) params->vht_capabilities, |
| 5401 | sizeof(*params->vht_capabilities)); |
| 5402 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 5403 | sizeof(*params->vht_capabilities), |
| 5404 | params->vht_capabilities)) |
| 5405 | goto fail; |
| 5406 | } |
| 5407 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5408 | if (params->he_capab) { |
| 5409 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 5410 | params->he_capab, params->he_capab_len); |
| 5411 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 5412 | params->he_capab_len, params->he_capab)) |
| 5413 | goto fail; |
| 5414 | } |
| 5415 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5416 | if (params->he_6ghz_capab) { |
| 5417 | wpa_hexdump(MSG_DEBUG, " * he_6ghz_capab", |
| 5418 | params->he_6ghz_capab, |
| 5419 | sizeof(*params->he_6ghz_capab)); |
| 5420 | if (nla_put(msg, NL80211_ATTR_HE_6GHZ_CAPABILITY, |
| 5421 | sizeof(*params->he_6ghz_capab), |
| 5422 | params->he_6ghz_capab)) |
| 5423 | goto fail; |
| 5424 | } |
| 5425 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5426 | if (params->eht_capab) { |
| 5427 | wpa_hexdump(MSG_DEBUG, " * eht_capab", |
| 5428 | params->eht_capab, params->eht_capab_len); |
| 5429 | if (nla_put(msg, NL80211_ATTR_EHT_CAPABILITY, |
| 5430 | params->eht_capab_len, params->eht_capab)) |
| 5431 | goto fail; |
| 5432 | } |
| 5433 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5434 | if (params->ext_capab) { |
| 5435 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 5436 | params->ext_capab, params->ext_capab_len); |
| 5437 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 5438 | params->ext_capab_len, params->ext_capab)) |
| 5439 | goto fail; |
| 5440 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5441 | |
| 5442 | if (is_ap_interface(drv->nlmode) && |
| 5443 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 5444 | params->support_p2p_ps ? |
| 5445 | NL80211_P2P_PS_SUPPORTED : |
| 5446 | NL80211_P2P_PS_UNSUPPORTED)) |
| 5447 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5448 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5449 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5450 | if (params->aid) { |
| 5451 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5452 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 5453 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5454 | } else { |
| 5455 | /* |
| 5456 | * cfg80211 validates that AID is non-zero, so we have |
| 5457 | * to make this a non-zero value for the TDLS case where |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5458 | * a stub STA entry is used for now and for a station |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5459 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5460 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5461 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 5462 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 5463 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5464 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 5465 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5466 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5467 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5468 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5469 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5470 | params->listen_interval)) |
| 5471 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5472 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 5473 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5474 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 5475 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5476 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5477 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 5478 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 5479 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5480 | params->listen_interval); |
| 5481 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 5482 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5483 | params->listen_interval)) |
| 5484 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 5487 | if (params->vht_opmode_enabled) { |
| 5488 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5489 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 5490 | params->vht_opmode)) |
| 5491 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5494 | if (params->supp_channels) { |
| 5495 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 5496 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5497 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 5498 | params->supp_channels_len, params->supp_channels)) |
| 5499 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | if (params->supp_oper_classes) { |
| 5503 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 5504 | params->supp_oper_classes, |
| 5505 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5506 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 5507 | params->supp_oper_classes_len, |
| 5508 | params->supp_oper_classes)) |
| 5509 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5510 | } |
| 5511 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5512 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5513 | upd.set = sta_flags_nl80211(params->flags); |
| 5514 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5515 | |
| 5516 | /* |
| 5517 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 5518 | * flags, as nl80211 driver moves a new station, by default, into |
| 5519 | * associated state. |
| 5520 | * |
| 5521 | * On the other hand, if the driver supports that feature and the |
| 5522 | * station is added in unauthenticated state, set the |
| 5523 | * authenticated/associated bits in the mask to prevent moving this |
| 5524 | * station to associated state before it is actually associated. |
| 5525 | * |
| 5526 | * This is irrelevant for mesh mode where the station is added to the |
| 5527 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 5528 | * nl80211 API. |
| 5529 | */ |
| 5530 | if (!is_mesh_interface(drv->nlmode)) { |
| 5531 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 5532 | wpa_printf(MSG_DEBUG, |
| 5533 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 5534 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5535 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 5536 | } else if (!params->set && |
| 5537 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 5538 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 5539 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 5540 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 5541 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 5542 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5543 | #ifdef CONFIG_MESH |
| 5544 | } else { |
| 5545 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 5546 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 5547 | params->peer_aid); |
| 5548 | if (ret) |
| 5549 | goto fail; |
| 5550 | } |
| 5551 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5554 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 5555 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5556 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5557 | goto fail; |
| 5558 | |
| 5559 | #ifdef CONFIG_MESH |
| 5560 | if (params->plink_state && |
| 5561 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 5562 | sta_plink_state_nl80211(params->plink_state))) |
| 5563 | goto fail; |
| 5564 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5565 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5566 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5567 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 5568 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5569 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 5570 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5571 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5572 | if (!wme || |
| 5573 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 5574 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 5575 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 5576 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 5577 | WMM_QOSINFO_STA_SP_MASK)) |
| 5578 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5579 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5580 | } |
| 5581 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5582 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5583 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5584 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5585 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 5586 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 5587 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5588 | if (ret == -EEXIST) |
| 5589 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5590 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5591 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5592 | return ret; |
| 5593 | } |
| 5594 | |
| 5595 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5596 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 5597 | { |
| 5598 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5599 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5600 | struct rtnl_neigh *rn; |
| 5601 | struct nl_addr *nl_addr; |
| 5602 | int err; |
| 5603 | |
| 5604 | rn = rtnl_neigh_alloc(); |
| 5605 | if (!rn) |
| 5606 | return; |
| 5607 | |
| 5608 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 5609 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 5610 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 5611 | if (!nl_addr) { |
| 5612 | rtnl_neigh_put(rn); |
| 5613 | return; |
| 5614 | } |
| 5615 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 5616 | |
| 5617 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 5618 | if (err < 0) { |
| 5619 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 5620 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 5621 | bss->ifindex, nl_geterror(err)); |
| 5622 | } else { |
| 5623 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 5624 | MACSTR, MAC2STR(addr)); |
| 5625 | } |
| 5626 | |
| 5627 | nl_addr_put(nl_addr); |
| 5628 | rtnl_neigh_put(rn); |
| 5629 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5630 | } |
| 5631 | |
| 5632 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5633 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 5634 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5635 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5636 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5637 | struct nl_msg *msg; |
| 5638 | int ret; |
| 5639 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5640 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 5641 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5642 | (deauth == 0 && |
| 5643 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5644 | WLAN_FC_STYPE_DISASSOC)) || |
| 5645 | (deauth == 1 && |
| 5646 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5647 | WLAN_FC_STYPE_DEAUTH)) || |
| 5648 | (reason_code && |
| 5649 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 5650 | nlmsg_free(msg); |
| 5651 | return -ENOBUFS; |
| 5652 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5653 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5654 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5655 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 5656 | " --> %d (%s)", |
| 5657 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5658 | |
| 5659 | if (drv->rtnl_sk) |
| 5660 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 5661 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5662 | if (ret == -ENOENT) |
| 5663 | return 0; |
| 5664 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5668 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5669 | { |
| 5670 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5671 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | |
| 5673 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 5674 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5675 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5676 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 5677 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5678 | { |
| 5679 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 5680 | /* Remove all bridges learned for this iface */ |
| 5681 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 5682 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5683 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5684 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5685 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5686 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5687 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 5688 | } |
| 5689 | |
| 5690 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5691 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5692 | { |
| 5693 | switch (mode) { |
| 5694 | case NL80211_IFTYPE_ADHOC: |
| 5695 | return "ADHOC"; |
| 5696 | case NL80211_IFTYPE_STATION: |
| 5697 | return "STATION"; |
| 5698 | case NL80211_IFTYPE_AP: |
| 5699 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5700 | case NL80211_IFTYPE_AP_VLAN: |
| 5701 | return "AP_VLAN"; |
| 5702 | case NL80211_IFTYPE_WDS: |
| 5703 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5704 | case NL80211_IFTYPE_MONITOR: |
| 5705 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5706 | case NL80211_IFTYPE_MESH_POINT: |
| 5707 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5708 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5709 | return "P2P_CLIENT"; |
| 5710 | case NL80211_IFTYPE_P2P_GO: |
| 5711 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5712 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5713 | return "P2P_DEVICE"; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5714 | case NL80211_IFTYPE_OCB: |
| 5715 | return "OCB"; |
| 5716 | case NL80211_IFTYPE_NAN: |
| 5717 | return "NAN"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5718 | default: |
| 5719 | return "unknown"; |
| 5720 | } |
| 5721 | } |
| 5722 | |
| 5723 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 5725 | const char *ifname, |
| 5726 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5727 | const u8 *addr, int wds, |
| 5728 | int (*handler)(struct nl_msg *, void *), |
| 5729 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5730 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5731 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5732 | int ifidx; |
| 5733 | int ret = -ENOBUFS; |
| 5734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5735 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 5736 | iftype, nl80211_iftype_str(iftype)); |
| 5737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5738 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 5739 | if (!msg || |
| 5740 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 5741 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 5742 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5743 | |
| 5744 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5745 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5746 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5747 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5748 | if (!flags || |
| 5749 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 5750 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5751 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5752 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5753 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5754 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 5755 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5756 | } |
| 5757 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5758 | /* |
| 5759 | * Tell cfg80211 that the interface belongs to the socket that created |
| 5760 | * it, and the interface should be deleted when the socket is closed. |
| 5761 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5762 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5763 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5764 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5765 | if ((addr && iftype == NL80211_IFTYPE_P2P_DEVICE) && |
| 5766 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5767 | goto fail; |
| 5768 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5769 | ret = send_and_recv_msgs(drv, msg, handler, arg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5770 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5771 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5772 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5773 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5774 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 5775 | ifname, ret, strerror(-ret)); |
| 5776 | return ret; |
| 5777 | } |
| 5778 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5779 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 5780 | return 0; |
| 5781 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5782 | ifidx = if_nametoindex(ifname); |
| 5783 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 5784 | ifname, ifidx); |
| 5785 | |
| 5786 | if (ifidx <= 0) |
| 5787 | return -1; |
| 5788 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5789 | /* |
| 5790 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5791 | * the parent interface. This is used mainly with hostapd. |
| 5792 | */ |
| 5793 | if (drv->hostapd || |
| 5794 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 5795 | iftype == NL80211_IFTYPE_WDS || |
| 5796 | iftype == NL80211_IFTYPE_MONITOR) { |
| 5797 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5798 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5799 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5800 | |
| 5801 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5802 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5803 | nl80211_remove_iface(drv, ifidx); |
| 5804 | return -1; |
| 5805 | } |
| 5806 | |
| 5807 | return ifidx; |
| 5808 | } |
| 5809 | |
| 5810 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5811 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 5812 | const char *ifname, enum nl80211_iftype iftype, |
| 5813 | const u8 *addr, int wds, |
| 5814 | int (*handler)(struct nl_msg *, void *), |
| 5815 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5816 | { |
| 5817 | int ret; |
| 5818 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5819 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 5820 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5821 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5822 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5823 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5824 | if (use_existing) { |
| 5825 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 5826 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5827 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 5828 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5829 | addr) < 0 && |
| 5830 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 5831 | ifname, 0) < 0 || |
| 5832 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5833 | addr) < 0 || |
| 5834 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 5835 | ifname, 1) < 0)) |
| 5836 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5837 | return -ENFILE; |
| 5838 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5839 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 5840 | |
| 5841 | /* Try to remove the interface that was already there. */ |
| 5842 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 5843 | |
| 5844 | /* Try to create the interface again */ |
| 5845 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5846 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5847 | } |
| 5848 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5849 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 5850 | wpa_printf(MSG_DEBUG, |
| 5851 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 5852 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5854 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5855 | |
| 5856 | return ret; |
| 5857 | } |
| 5858 | |
| 5859 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5860 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 5861 | { |
| 5862 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5863 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5864 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5865 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5866 | |
| 5867 | /* |
| 5868 | * Disable Probe Request reporting unless we need it in this way for |
| 5869 | * devices that include the AP SME, in the other case (unless using |
| 5870 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 5871 | */ |
| 5872 | if (!drv->device_ap_sme) |
| 5873 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5874 | |
| 5875 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5876 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5877 | return -1; |
| 5878 | |
| 5879 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5880 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5881 | wpa_printf(MSG_DEBUG, |
| 5882 | "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] | 5883 | |
| 5884 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5885 | nl80211_create_monitor_interface(drv) && |
| 5886 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5887 | return -1; |
| 5888 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5889 | if (drv->device_ap_sme && |
| 5890 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5891 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5892 | "Probe Request frame reporting in AP mode"); |
| 5893 | /* Try to survive without this */ |
| 5894 | } |
| 5895 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5896 | return 0; |
| 5897 | } |
| 5898 | |
| 5899 | |
| 5900 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5901 | { |
| 5902 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5903 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5904 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5905 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5906 | if (drv->device_ap_sme) { |
| 5907 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5908 | if (!drv->use_monitor) |
| 5909 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5910 | } else if (drv->use_monitor) |
| 5911 | nl80211_remove_monitor_interface(drv); |
| 5912 | else |
| 5913 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5914 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5915 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5916 | bss->beacon_set = 0; |
| 5917 | } |
| 5918 | |
| 5919 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5920 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 5921 | u16 proto, const u8 *buf, size_t len, |
| 5922 | int no_encrypt) |
| 5923 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5924 | struct nl80211_ack_ext_arg ext_arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5925 | struct i802_bss *bss = priv; |
| 5926 | struct nl_msg *msg; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5927 | u64 cookie = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5928 | int ret; |
| 5929 | |
| 5930 | wpa_printf(MSG_DEBUG, |
| 5931 | "nl80211: Send over control port dest=" MACSTR |
| 5932 | " proto=0x%04x len=%u no_encrypt=%d", |
| 5933 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 5934 | |
| 5935 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 5936 | if (!msg || |
| 5937 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 5938 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 5939 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 5940 | (no_encrypt && |
| 5941 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { |
| 5942 | nlmsg_free(msg); |
| 5943 | return -ENOBUFS; |
| 5944 | } |
| 5945 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5946 | os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg)); |
| 5947 | ext_arg.ext_data = &cookie; |
| 5948 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, |
| 5949 | ack_handler_cookie, &ext_arg); |
| 5950 | if (ret) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5951 | wpa_printf(MSG_DEBUG, |
| 5952 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 5953 | ret, strerror(-ret)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5954 | } else { |
| 5955 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5956 | |
| 5957 | wpa_printf(MSG_DEBUG, |
| 5958 | "nl80211: tx_control_port cookie=0x%llx", |
| 5959 | (long long unsigned int) cookie); |
| 5960 | drv->eapol_tx_cookie = cookie; |
| 5961 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5962 | |
| 5963 | return ret; |
| 5964 | } |
| 5965 | |
| 5966 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5967 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5968 | const u8 *addr, const u8 *data, |
| 5969 | size_t data_len) |
| 5970 | { |
| 5971 | struct sockaddr_ll ll; |
| 5972 | int ret; |
| 5973 | |
| 5974 | if (bss->drv->eapol_tx_sock < 0) { |
| 5975 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5976 | return -1; |
| 5977 | } |
| 5978 | |
| 5979 | os_memset(&ll, 0, sizeof(ll)); |
| 5980 | ll.sll_family = AF_PACKET; |
| 5981 | ll.sll_ifindex = bss->ifindex; |
| 5982 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5983 | ll.sll_halen = ETH_ALEN; |
| 5984 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5985 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5986 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5987 | if (ret < 0) |
| 5988 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5989 | strerror(errno)); |
| 5990 | |
| 5991 | return ret; |
| 5992 | } |
| 5993 | |
| 5994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5995 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5996 | |
| 5997 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5998 | void *priv, const u8 *addr, const u8 *data, |
| 5999 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 6000 | { |
| 6001 | struct i802_bss *bss = priv; |
| 6002 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6003 | struct ieee80211_hdr *hdr; |
| 6004 | size_t len; |
| 6005 | u8 *pos; |
| 6006 | int res; |
| 6007 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 6008 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6009 | /* For now, disable EAPOL TX over control port in AP mode by default |
| 6010 | * since it does not provide TX status notifications. */ |
| 6011 | if (drv->control_port_ap && |
| 6012 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6013 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
| 6014 | data, data_len, !encrypt); |
| 6015 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6016 | if (drv->device_ap_sme || !drv->use_monitor) |
| 6017 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 6018 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6019 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 6020 | data_len; |
| 6021 | hdr = os_zalloc(len); |
| 6022 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6023 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 6024 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6025 | return -1; |
| 6026 | } |
| 6027 | |
| 6028 | hdr->frame_control = |
| 6029 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 6030 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6031 | if (encrypt) |
| 6032 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 6033 | if (qos) { |
| 6034 | hdr->frame_control |= |
| 6035 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 6036 | } |
| 6037 | |
| 6038 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6039 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6040 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6041 | pos = (u8 *) (hdr + 1); |
| 6042 | |
| 6043 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6044 | /* Set highest priority in QoS header */ |
| 6045 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6046 | pos[1] = 0; |
| 6047 | pos += 2; |
| 6048 | } |
| 6049 | |
| 6050 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 6051 | pos += sizeof(rfc1042_header); |
| 6052 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 6053 | pos += 2; |
| 6054 | memcpy(pos, data, data_len); |
| 6055 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6056 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6057 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6058 | wpa_printf(MSG_ERROR, |
| 6059 | "hapd_send_eapol - packet len: %lu - failed", |
| 6060 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6061 | } |
| 6062 | os_free(hdr); |
| 6063 | |
| 6064 | return res; |
| 6065 | } |
| 6066 | |
| 6067 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6068 | 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] | 6069 | unsigned int total_flags, |
| 6070 | unsigned int flags_or, |
| 6071 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6072 | { |
| 6073 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6074 | struct nl_msg *msg; |
| 6075 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6076 | struct nl80211_sta_flag_update upd; |
| 6077 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6078 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 6079 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 6080 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 6081 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 6082 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6083 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6084 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 6085 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6086 | |
| 6087 | /* |
| 6088 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 6089 | * can be removed eventually. |
| 6090 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6091 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6092 | if (!flags || |
| 6093 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 6094 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 6095 | ((total_flags & WPA_STA_WMM) && |
| 6096 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 6097 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 6098 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 6099 | ((total_flags & WPA_STA_MFP) && |
| 6100 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 6101 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 6102 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 6103 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6104 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6105 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | |
| 6107 | os_memset(&upd, 0, sizeof(upd)); |
| 6108 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 6109 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6110 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 6111 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6112 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6113 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6114 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6115 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6116 | return -ENOBUFS; |
| 6117 | } |
| 6118 | |
| 6119 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6120 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 6121 | unsigned int weight) |
| 6122 | { |
| 6123 | struct i802_bss *bss = priv; |
| 6124 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6125 | int ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6126 | |
| 6127 | wpa_printf(MSG_DEBUG, |
| 6128 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 6129 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 6130 | |
| 6131 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6132 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6133 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 6134 | goto fail; |
| 6135 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6136 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
| 6137 | if (ret) { |
| 6138 | wpa_printf(MSG_DEBUG, |
| 6139 | "nl80211: SET_STATION[AIRTIME_WEIGHT] failed: ret=%d (%s)", |
| 6140 | ret, strerror(-ret)); |
| 6141 | } |
| 6142 | return ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6143 | fail: |
| 6144 | nlmsg_free(msg); |
| 6145 | return -ENOBUFS; |
| 6146 | } |
| 6147 | |
| 6148 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6149 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 6150 | struct wpa_driver_associate_params *params) |
| 6151 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6152 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6153 | |
| 6154 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6155 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 6156 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 6158 | } else |
| 6159 | nlmode = NL80211_IFTYPE_AP; |
| 6160 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6161 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6162 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6163 | nl80211_remove_monitor_interface(drv); |
| 6164 | return -1; |
| 6165 | } |
| 6166 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6167 | if (params->freq.freq && |
| 6168 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6169 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6170 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6171 | nl80211_remove_monitor_interface(drv); |
| 6172 | return -1; |
| 6173 | } |
| 6174 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6175 | return 0; |
| 6176 | } |
| 6177 | |
| 6178 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6179 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 6180 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6181 | { |
| 6182 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6183 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6184 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6185 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6186 | ret = send_and_recv_msgs_connect_handle(drv, msg, drv->first_bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6187 | if (ret) { |
| 6188 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 6189 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6190 | } else { |
| 6191 | wpa_printf(MSG_DEBUG, |
| 6192 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6195 | if (reset_mode && |
| 6196 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6197 | NL80211_IFTYPE_STATION)) { |
| 6198 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6199 | "station mode"); |
| 6200 | } |
| 6201 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6202 | return ret; |
| 6203 | } |
| 6204 | |
| 6205 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6206 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 6207 | struct wpa_driver_associate_params *params) |
| 6208 | { |
| 6209 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 6210 | return -1; |
| 6211 | |
| 6212 | if (params->htcaps && params->htcaps_mask) { |
| 6213 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 6214 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 6215 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 6216 | params->htcaps_mask, sz); |
| 6217 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 6218 | params->htcaps) || |
| 6219 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 6220 | params->htcaps_mask)) |
| 6221 | return -1; |
| 6222 | } |
| 6223 | |
| 6224 | #ifdef CONFIG_VHT_OVERRIDES |
| 6225 | if (params->disable_vht) { |
| 6226 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 6227 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 6228 | return -1; |
| 6229 | } |
| 6230 | |
| 6231 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 6232 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 6233 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 6234 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 6235 | params->vhtcaps_mask, sz); |
| 6236 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 6237 | params->vhtcaps) || |
| 6238 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 6239 | params->vhtcaps_mask)) |
| 6240 | return -1; |
| 6241 | } |
| 6242 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 6243 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6244 | #ifdef CONFIG_HE_OVERRIDES |
| 6245 | if (params->disable_he) { |
| 6246 | wpa_printf(MSG_DEBUG, " * HE disabled"); |
| 6247 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_HE)) |
| 6248 | return -1; |
| 6249 | } |
| 6250 | #endif /* CONFIG_HE_OVERRIDES */ |
| 6251 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 6252 | if (params->disable_eht) { |
| 6253 | wpa_printf(MSG_DEBUG, " * EHT disabled"); |
| 6254 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_EHT)) |
| 6255 | return -1; |
| 6256 | } |
| 6257 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6258 | return 0; |
| 6259 | } |
| 6260 | |
| 6261 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6262 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 6263 | struct wpa_driver_associate_params *params) |
| 6264 | { |
| 6265 | struct nl_msg *msg; |
| 6266 | int ret = -1; |
| 6267 | int count = 0; |
| 6268 | |
| 6269 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 6270 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6271 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6273 | "IBSS mode"); |
| 6274 | return -1; |
| 6275 | } |
| 6276 | |
| 6277 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6278 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 6279 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 6280 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6281 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6282 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6283 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6284 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 6285 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6287 | drv->ssid_len = params->ssid_len; |
| 6288 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6289 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 6290 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6291 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6292 | |
| 6293 | ret = nl80211_set_conn_keys(params, msg); |
| 6294 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6295 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6296 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6297 | if (params->bssid && params->fixed_bssid) { |
| 6298 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 6299 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6300 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6301 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6302 | } |
| 6303 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6304 | if (params->fixed_freq) { |
| 6305 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 6306 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 6307 | goto fail; |
| 6308 | } |
| 6309 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6310 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6311 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6312 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 6313 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6314 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6315 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6316 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6317 | } |
| 6318 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | if (params->wpa_ie) { |
| 6320 | wpa_hexdump(MSG_DEBUG, |
| 6321 | " * Extra IEs for Beacon/Probe Response frames", |
| 6322 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6323 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 6324 | params->wpa_ie)) |
| 6325 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 6328 | ret = nl80211_ht_vht_overrides(msg, params); |
| 6329 | if (ret < 0) |
| 6330 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6331 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6332 | ret = send_and_recv_msgs_connect_handle(drv, msg, drv->first_bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6333 | msg = NULL; |
| 6334 | if (ret) { |
| 6335 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 6336 | ret, strerror(-ret)); |
| 6337 | count++; |
| 6338 | if (ret == -EALREADY && count == 1) { |
| 6339 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 6340 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6341 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6342 | nlmsg_free(msg); |
| 6343 | goto retry; |
| 6344 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6345 | } else { |
| 6346 | wpa_printf(MSG_DEBUG, |
| 6347 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6348 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6349 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6350 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6351 | nlmsg_free(msg); |
| 6352 | return ret; |
| 6353 | } |
| 6354 | |
| 6355 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6356 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 6357 | struct wpa_driver_associate_params *params, |
| 6358 | struct nl_msg *msg) |
| 6359 | { |
| 6360 | if (params->fils_erp_username_len) { |
| 6361 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 6362 | params->fils_erp_username, |
| 6363 | params->fils_erp_username_len); |
| 6364 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 6365 | params->fils_erp_username_len, |
| 6366 | params->fils_erp_username)) |
| 6367 | return -1; |
| 6368 | } |
| 6369 | |
| 6370 | if (params->fils_erp_realm_len) { |
| 6371 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 6372 | params->fils_erp_realm, |
| 6373 | params->fils_erp_realm_len); |
| 6374 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 6375 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 6376 | return -1; |
| 6377 | } |
| 6378 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6379 | if (params->fils_erp_rrk_len) { |
Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 6380 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 6381 | params->fils_erp_next_seq_num); |
| 6382 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 6383 | params->fils_erp_next_seq_num)) |
| 6384 | return -1; |
| 6385 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6386 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 6387 | (unsigned long) params->fils_erp_rrk_len); |
| 6388 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 6389 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 6390 | return -1; |
| 6391 | } |
| 6392 | |
| 6393 | return 0; |
| 6394 | } |
| 6395 | |
| 6396 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6397 | static unsigned int num_bits_set(u32 val) |
| 6398 | { |
| 6399 | unsigned int c; |
| 6400 | |
| 6401 | for (c = 0; val; c++) |
| 6402 | val &= val - 1; |
| 6403 | |
| 6404 | return c; |
| 6405 | } |
| 6406 | |
| 6407 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6408 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 6409 | struct wpa_driver_associate_params *params, |
| 6410 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6411 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 6412 | if (params->mld_params.mld_addr && params->mld_params.valid_links > 0) { |
| 6413 | struct wpa_driver_mld_params *mld_params = ¶ms->mld_params; |
| 6414 | struct nlattr *links, *attr; |
| 6415 | int i; |
| 6416 | u8 link_id; |
| 6417 | |
| 6418 | wpa_printf(MSG_DEBUG, " * MLD: MLD addr=" MACSTR, |
| 6419 | MAC2STR(mld_params->mld_addr)); |
| 6420 | |
| 6421 | if (nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, |
| 6422 | mld_params->mld_addr) || |
| 6423 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 6424 | mld_params->assoc_link_id)) |
| 6425 | return -1; |
| 6426 | |
| 6427 | links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); |
| 6428 | if (!links) |
| 6429 | return -1; |
| 6430 | |
| 6431 | attr = nla_nest_start(msg, 0); |
| 6432 | if (!attr) |
| 6433 | return -1; |
| 6434 | |
| 6435 | /* First add the association link ID */ |
| 6436 | link_id = mld_params->assoc_link_id; |
| 6437 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id) || |
| 6438 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 6439 | mld_params->mld_links[link_id].bssid) || |
| 6440 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6441 | mld_params->mld_links[link_id].freq)) |
| 6442 | return -1; |
| 6443 | |
| 6444 | os_memcpy(drv->sta_mlo_info.links[link_id].bssid, |
| 6445 | mld_params->mld_links[link_id].bssid, ETH_ALEN); |
| 6446 | |
| 6447 | nla_nest_end(msg, attr); |
| 6448 | |
| 6449 | for (i = 1, link_id = 0; link_id < MAX_NUM_MLD_LINKS; |
| 6450 | link_id++) { |
| 6451 | if (!(mld_params->valid_links & BIT(link_id)) || |
| 6452 | link_id == mld_params->assoc_link_id) |
| 6453 | continue; |
| 6454 | |
| 6455 | attr = nla_nest_start(msg, i); |
| 6456 | if (!attr) |
| 6457 | return -1; |
| 6458 | |
| 6459 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, |
| 6460 | link_id) || |
| 6461 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 6462 | mld_params->mld_links[link_id].bssid) || |
| 6463 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6464 | mld_params->mld_links[link_id].freq) || |
| 6465 | (mld_params->mld_links[link_id].ies && |
| 6466 | mld_params->mld_links[i].ies_len && |
| 6467 | nla_put(msg, NL80211_ATTR_IE, |
| 6468 | mld_params->mld_links[link_id].ies_len, |
| 6469 | mld_params->mld_links[link_id].ies))) |
| 6470 | return -1; |
| 6471 | |
| 6472 | os_memcpy(drv->sta_mlo_info.links[link_id].bssid, |
| 6473 | mld_params->mld_links[link_id].bssid, |
| 6474 | ETH_ALEN); |
| 6475 | nla_nest_end(msg, attr); |
| 6476 | i++; |
| 6477 | } |
| 6478 | |
| 6479 | nla_nest_end(msg, links); |
| 6480 | |
| 6481 | os_memcpy(drv->sta_mlo_info.ap_mld_addr, |
| 6482 | params->mld_params.mld_addr, ETH_ALEN); |
| 6483 | drv->sta_mlo_info.assoc_link_id = mld_params->assoc_link_id; |
| 6484 | drv->sta_mlo_info.req_links = mld_params->valid_links; |
| 6485 | } |
| 6486 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6487 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 6488 | return -1; |
| 6489 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 6490 | if (params->bssid && !params->mld_params.mld_addr) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6491 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 6492 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6493 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6494 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6495 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6496 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6497 | if (params->bssid_hint) { |
| 6498 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 6499 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6500 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 6501 | params->bssid_hint)) |
| 6502 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6503 | } |
| 6504 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 6505 | if (params->freq.freq && !params->mld_params.mld_addr) { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6506 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6507 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6508 | params->freq.freq)) |
| 6509 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6510 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6511 | } else |
| 6512 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6513 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6514 | if (params->freq_hint) { |
| 6515 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 6517 | params->freq_hint)) |
| 6518 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6519 | } |
| 6520 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6521 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 6522 | wpa_printf(MSG_DEBUG, |
| 6523 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 6524 | params->freq.edmg.channels, |
| 6525 | params->freq.edmg.bw_config); |
| 6526 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 6527 | params->freq.edmg.channels) || |
| 6528 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 6529 | params->freq.edmg.bw_config)) |
| 6530 | return -1; |
| 6531 | } |
| 6532 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6533 | if (params->bg_scan_period >= 0) { |
| 6534 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 6535 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6536 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 6537 | params->bg_scan_period)) |
| 6538 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6539 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6542 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6543 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6544 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6545 | params->ssid)) |
| 6546 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6547 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6548 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6549 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6550 | drv->ssid_len = params->ssid_len; |
| 6551 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6552 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6553 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6554 | if (params->wpa_ie && |
| 6555 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 6556 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6557 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6558 | if (params->wpa_proto) { |
| 6559 | enum nl80211_wpa_versions ver = 0; |
| 6560 | |
| 6561 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 6562 | ver |= NL80211_WPA_VERSION_1; |
| 6563 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 6564 | ver |= NL80211_WPA_VERSION_2; |
| 6565 | |
| 6566 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6567 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 6568 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 6572 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 6573 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6574 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 6575 | cipher)) |
| 6576 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6577 | } |
| 6578 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6579 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 6580 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 6581 | /* |
| 6582 | * This is likely to work even though many drivers do not |
| 6583 | * advertise support for operations without GTK. |
| 6584 | */ |
| 6585 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 6586 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6587 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 6588 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6589 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 6590 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6594 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6595 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 6596 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6597 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6598 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 6599 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6600 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6601 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6602 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE_EXT_KEY || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6603 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6604 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE_EXT_KEY || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6605 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6606 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6607 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6608 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 6609 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 6610 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6611 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 6612 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 6613 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6614 | u32 *mgmt; |
| 6615 | unsigned int akm_count = 1, i; |
| 6616 | |
| 6617 | /* |
| 6618 | * Make sure the driver has capability to handle default AKM in |
| 6619 | * key_mgmt_suite plus allowed AKMs in allowed_key_mgmts. |
| 6620 | */ |
| 6621 | if (drv->capa.max_num_akms <= |
| 6622 | num_bits_set(params->allowed_key_mgmts)) { |
| 6623 | wpa_printf(MSG_INFO, |
| 6624 | "nl80211: Not enough support for the allowed AKMs (max_num_akms=%u <= num_bits_set=%u)", |
| 6625 | drv->capa.max_num_akms, |
| 6626 | num_bits_set(params->allowed_key_mgmts)); |
| 6627 | return -1; |
| 6628 | } |
| 6629 | |
| 6630 | mgmt = os_malloc(sizeof(u32) * drv->capa.max_num_akms); |
| 6631 | if (!mgmt) |
| 6632 | return -1; |
| 6633 | |
| 6634 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6635 | |
| 6636 | switch (params->key_mgmt_suite) { |
| 6637 | case WPA_KEY_MGMT_CCKM: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6638 | mgmt[0] = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6639 | break; |
| 6640 | case WPA_KEY_MGMT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6641 | mgmt[0] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6642 | break; |
| 6643 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6644 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6645 | break; |
| 6646 | case WPA_KEY_MGMT_FT_PSK: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6647 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6648 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6649 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6650 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6651 | break; |
| 6652 | case WPA_KEY_MGMT_PSK_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6653 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6654 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6655 | case WPA_KEY_MGMT_OSEN: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6656 | mgmt[0] = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6657 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6658 | case WPA_KEY_MGMT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6659 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE; |
| 6660 | break; |
| 6661 | case WPA_KEY_MGMT_SAE_EXT_KEY: |
| 6662 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6663 | break; |
| 6664 | case WPA_KEY_MGMT_FT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6665 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 6666 | break; |
| 6667 | case WPA_KEY_MGMT_FT_SAE_EXT_KEY: |
| 6668 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6669 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6670 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6671 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6672 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6673 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6674 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6675 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6676 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6677 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6678 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6679 | case WPA_KEY_MGMT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6680 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6681 | break; |
| 6682 | case WPA_KEY_MGMT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6683 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6684 | break; |
| 6685 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6686 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6687 | break; |
| 6688 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6689 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6690 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6691 | case WPA_KEY_MGMT_OWE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6692 | mgmt[0] = RSN_AUTH_KEY_MGMT_OWE; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6693 | break; |
| 6694 | case WPA_KEY_MGMT_DPP: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6695 | mgmt[0] = RSN_AUTH_KEY_MGMT_DPP; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6696 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6697 | case WPA_KEY_MGMT_PSK: |
| 6698 | default: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6699 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6700 | break; |
| 6701 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6702 | |
| 6703 | if (drv->capa.max_num_akms > 1) { |
| 6704 | akm_count += wpa_key_mgmt_to_suites( |
| 6705 | params->allowed_key_mgmts, &mgmt[1], |
| 6706 | drv->capa.max_num_akms - 1); |
| 6707 | } |
| 6708 | |
| 6709 | for (i = 0; i < akm_count; i++) |
| 6710 | wpa_printf(MSG_DEBUG, " * akm[%d]=0x%x", i, mgmt[i]); |
| 6711 | |
| 6712 | if (nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 6713 | akm_count * sizeof(u32), mgmt)) { |
| 6714 | os_free(mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6715 | return -1; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | os_free(mgmt); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6719 | } |
| 6720 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6721 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6722 | if (IS_CROSS_AKM_ROAM_KEY_MGMT(params->key_mgmt_suite)) { |
| 6723 | int num_suites; |
| 6724 | u32 suites[NL80211_MAX_NR_AKM_SUITES]; |
| 6725 | |
| 6726 | wpa_printf(MSG_INFO, "nl80211: key_mgmt_suites=0x%x", |
| 6727 | params->key_mgmt_suite); |
| 6728 | num_suites = wpa_cross_akm_key_mgmt_to_suites(params->key_mgmt_suite, |
| 6729 | suites, ARRAY_SIZE(suites)); |
| 6730 | if (num_suites && |
| 6731 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), suites)) { |
| 6732 | wpa_printf(MSG_ERROR, "Updating multi akm_suite failed"); |
| 6733 | return -1; |
| 6734 | } |
| 6735 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6736 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6737 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6738 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 6739 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 6740 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 6741 | return -1; |
| 6742 | } |
| 6743 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6744 | /* Add PSK in case of 4-way handshake offload */ |
| 6745 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6746 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6747 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 6748 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 6749 | return -1; |
| 6750 | } |
| 6751 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6752 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6753 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6754 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 6755 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 6756 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 6757 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 6758 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 6759 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 6760 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 6761 | return -1; |
| 6762 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6763 | if (params->rrm_used) { |
| 6764 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6765 | if ((!((drv_rrm_flags & |
| 6766 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 6767 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 6768 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6769 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 6770 | return -1; |
| 6771 | } |
| 6772 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6773 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6774 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6775 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6776 | if (params->p2p) |
| 6777 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 6778 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6779 | if (params->pbss) { |
| 6780 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 6781 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 6782 | return -1; |
| 6783 | } |
| 6784 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6785 | drv->connect_reassoc = 0; |
| 6786 | if (params->prev_bssid) { |
| 6787 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 6788 | MAC2STR(params->prev_bssid)); |
| 6789 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 6790 | params->prev_bssid)) |
| 6791 | return -1; |
| 6792 | drv->connect_reassoc = 1; |
| 6793 | } |
| 6794 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6795 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 6796 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 6797 | return -1; |
| 6798 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6799 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6800 | if (((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6801 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) && |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6802 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6803 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6804 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6805 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6806 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 6807 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 6808 | return -1; |
| 6809 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6810 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | |
| 6814 | static int wpa_driver_nl80211_try_connect( |
| 6815 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6816 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6817 | struct i802_bss *bss) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6818 | { |
| 6819 | struct nl_msg *msg; |
| 6820 | enum nl80211_auth_type type; |
| 6821 | int ret; |
| 6822 | int algs; |
| 6823 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6824 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6825 | if (params->req_key_mgmt_offload && params->psk && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6826 | (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suite) || |
| 6827 | wpa_key_mgmt_wpa_psk_no_sae(params->allowed_key_mgmts))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6828 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 6829 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 6830 | if (ret) |
| 6831 | return ret; |
| 6832 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6833 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6834 | |
| 6835 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 6836 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6837 | if (!msg) |
| 6838 | return -1; |
| 6839 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6840 | ret = nl80211_connect_common(drv, params, msg); |
| 6841 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6842 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6843 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6844 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6845 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6846 | goto fail; |
| 6847 | |
| 6848 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 6849 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 6850 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 6851 | goto fail; |
| 6852 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6853 | #ifdef CONFIG_SAE |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6854 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6855 | if (((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6856 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) && |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6857 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6858 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6859 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6860 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6861 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 6862 | goto fail; |
| 6863 | #endif /* CONFIG_SAE */ |
| 6864 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6865 | algs = 0; |
| 6866 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6867 | algs++; |
| 6868 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6869 | algs++; |
| 6870 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6871 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6872 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 6873 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6874 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6875 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6876 | if (algs > 1) { |
| 6877 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 6878 | "selection"); |
| 6879 | goto skip_auth_type; |
| 6880 | } |
| 6881 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6882 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6883 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6884 | if (type == NL80211_AUTHTYPE_MAX || |
| 6885 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6886 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6887 | |
| 6888 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6889 | ret = nl80211_set_conn_keys(params, msg); |
| 6890 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6891 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6892 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6893 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6894 | msg = NULL; |
| 6895 | if (ret) { |
| 6896 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 6897 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6898 | } else { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6899 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 6900 | drv->roam_indication_done = false; |
| 6901 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6902 | wpa_printf(MSG_DEBUG, |
| 6903 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6904 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6905 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6906 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6907 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6908 | nlmsg_free(msg); |
| 6909 | return ret; |
| 6910 | |
| 6911 | } |
| 6912 | |
| 6913 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6914 | static int wpa_driver_nl80211_connect( |
| 6915 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6916 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6917 | struct i802_bss *bss) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6918 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6919 | int ret; |
| 6920 | |
| 6921 | /* Store the connection attempted bssid for future use */ |
| 6922 | if (params->bssid) |
| 6923 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 6924 | else |
| 6925 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 6926 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6927 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6928 | if (ret == -EALREADY) { |
| 6929 | /* |
| 6930 | * cfg80211 does not currently accept new connections if |
| 6931 | * we are already connected. As a workaround, force |
| 6932 | * disconnection and try again. |
| 6933 | */ |
| 6934 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 6935 | "disconnecting before reassociation " |
| 6936 | "attempt"); |
| 6937 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6938 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, bss)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6939 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6940 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6941 | } |
| 6942 | return ret; |
| 6943 | } |
| 6944 | |
| 6945 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6946 | static int wpa_driver_nl80211_associate( |
| 6947 | void *priv, struct wpa_driver_associate_params *params) |
| 6948 | { |
| 6949 | struct i802_bss *bss = priv; |
| 6950 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6951 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6952 | struct nl_msg *msg; |
| 6953 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6954 | nl80211_unmask_11b_rates(bss); |
| 6955 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6956 | if (params->mode == IEEE80211_MODE_AP) |
| 6957 | return wpa_driver_nl80211_ap(drv, params); |
| 6958 | |
| 6959 | if (params->mode == IEEE80211_MODE_IBSS) |
| 6960 | return wpa_driver_nl80211_ibss(drv, params); |
| 6961 | |
| 6962 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6963 | enum nl80211_iftype nlmode = params->p2p ? |
| 6964 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 6965 | |
| 6966 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6967 | return -1; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6968 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6969 | if ((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6970 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6971 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6972 | if (wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6973 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 6974 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6975 | bss->use_nl_connect = 1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6976 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6977 | bss->use_nl_connect = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6978 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6979 | return wpa_driver_nl80211_connect(drv, params, bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6982 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6983 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6984 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 6985 | drv->ifindex); |
| 6986 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6987 | if (!msg) |
| 6988 | return -1; |
| 6989 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6990 | ret = nl80211_connect_common(drv, params, msg); |
| 6991 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6992 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6993 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6994 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6995 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6996 | goto fail; |
| 6997 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6998 | if (params->fils_kek) { |
| 6999 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 7000 | (unsigned int) params->fils_kek_len); |
| 7001 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 7002 | params->fils_kek)) |
| 7003 | goto fail; |
| 7004 | } |
| 7005 | if (params->fils_nonces) { |
| 7006 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 7007 | params->fils_nonces, |
| 7008 | params->fils_nonces_len); |
| 7009 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 7010 | params->fils_nonces_len, params->fils_nonces)) |
| 7011 | goto fail; |
| 7012 | } |
| 7013 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7014 | ret = send_and_recv_msgs_connect_handle(drv, msg, drv->first_bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7015 | msg = NULL; |
| 7016 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7017 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 7018 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 7019 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7020 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7021 | } else { |
| 7022 | wpa_printf(MSG_DEBUG, |
| 7023 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7024 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7025 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7026 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7027 | nlmsg_free(msg); |
| 7028 | return ret; |
| 7029 | } |
| 7030 | |
| 7031 | |
| 7032 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7033 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7034 | { |
| 7035 | struct nl_msg *msg; |
| 7036 | int ret = -ENOBUFS; |
| 7037 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7038 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 7039 | ifindex, mode, nl80211_iftype_str(mode)); |
| 7040 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7041 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 7042 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 7043 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7044 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7045 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7046 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7047 | if (!ret) |
| 7048 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7049 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7050 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7051 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 7052 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 7053 | return ret; |
| 7054 | } |
| 7055 | |
| 7056 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7057 | static int wpa_driver_nl80211_set_mode_impl( |
| 7058 | struct i802_bss *bss, |
| 7059 | enum nl80211_iftype nlmode, |
| 7060 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7061 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7062 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7063 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7064 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7065 | int was_ap = is_ap_interface(drv->nlmode); |
| 7066 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7067 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7068 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7069 | if (TEST_FAIL()) |
| 7070 | return -1; |
| 7071 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7072 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 7073 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 7074 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7075 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7076 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7077 | drv->nlmode = nlmode; |
| 7078 | ret = 0; |
| 7079 | goto done; |
| 7080 | } |
| 7081 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7082 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7083 | return -1; |
| 7084 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7085 | if (nlmode == drv->nlmode) { |
| 7086 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 7087 | "requested mode - ignore error"); |
| 7088 | ret = 0; |
| 7089 | goto done; /* Already in the requested mode */ |
| 7090 | } |
| 7091 | |
| 7092 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 7093 | * take the device down, try to set the mode again, and bring the |
| 7094 | * device back up. |
| 7095 | */ |
| 7096 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 7097 | "interface down"); |
| 7098 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7099 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7100 | if (res == -EACCES || res == -ENODEV) |
| 7101 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7102 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7103 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 7104 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7105 | os_sleep(0, 100000); |
| 7106 | continue; |
| 7107 | } |
| 7108 | |
| 7109 | /* |
| 7110 | * Setting the mode will fail for some drivers if the phy is |
| 7111 | * on a frequency that the mode is disallowed in. |
| 7112 | */ |
| 7113 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7114 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7115 | if (res) { |
| 7116 | wpa_printf(MSG_DEBUG, |
| 7117 | "nl80211: Failed to set frequency on interface"); |
| 7118 | } |
| 7119 | } |
| 7120 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7121 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && |
| 7122 | bss->brname[0] && |
| 7123 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 7124 | wpa_printf(MSG_DEBUG, |
| 7125 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", |
| 7126 | bss->ifname, bss->brname); |
| 7127 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 7128 | bss->brname, bss->ifname) < 0) |
| 7129 | wpa_printf(MSG_INFO, |
| 7130 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7131 | bss->ifname, bss->brname, |
| 7132 | strerror(errno)); |
| 7133 | } |
| 7134 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7135 | /* Try to set the mode again while the interface is down */ |
| 7136 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 7137 | if (mode_switch_res == -EBUSY) { |
| 7138 | wpa_printf(MSG_DEBUG, |
| 7139 | "nl80211: Delaying mode set while interface going down"); |
| 7140 | os_sleep(0, 100000); |
| 7141 | continue; |
| 7142 | } |
| 7143 | ret = mode_switch_res; |
| 7144 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | if (!ret) { |
| 7148 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 7149 | "interface is down"); |
| 7150 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7151 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7152 | } |
| 7153 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7154 | /* Bring the interface back up */ |
| 7155 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 7156 | if (res != 0) { |
| 7157 | wpa_printf(MSG_DEBUG, |
| 7158 | "nl80211: Failed to set interface up after switching mode"); |
| 7159 | ret = -1; |
| 7160 | } |
| 7161 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7162 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7163 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7164 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 7165 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7166 | return ret; |
| 7167 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7168 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7169 | if (is_p2p_net_interface(nlmode)) { |
| 7170 | wpa_printf(MSG_DEBUG, |
| 7171 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 7172 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7173 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7174 | } else if (drv->disabled_11b_rates) { |
| 7175 | wpa_printf(MSG_DEBUG, |
| 7176 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 7177 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7178 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7179 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7180 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7181 | if (is_ap_interface(nlmode)) { |
| 7182 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 7183 | /* Setup additional AP mode functionality if needed */ |
| 7184 | if (nl80211_setup_ap(bss)) |
| 7185 | return -1; |
| 7186 | } else if (was_ap) { |
| 7187 | /* Remove additional AP mode functionality */ |
| 7188 | nl80211_teardown_ap(bss); |
| 7189 | } else { |
| 7190 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 7191 | } |
| 7192 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7193 | if (is_mesh_interface(nlmode) && |
| 7194 | nl80211_mgmt_subscribe_mesh(bss)) |
| 7195 | return -1; |
| 7196 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7197 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7198 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7199 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 7200 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 7201 | "frame processing - ignore for now"); |
| 7202 | |
| 7203 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7207 | void nl80211_restore_ap_mode(struct i802_bss *bss) |
| 7208 | { |
| 7209 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7210 | int was_ap = is_ap_interface(drv->nlmode); |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7211 | int br_ifindex; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7212 | |
| 7213 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); |
| 7214 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && |
| 7215 | bss->brname[0] && |
| 7216 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 7217 | wpa_printf(MSG_DEBUG, |
| 7218 | "nl80211: Add AP interface %s back into the bridge %s", |
| 7219 | bss->ifname, bss->brname); |
| 7220 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, |
| 7221 | bss->ifname) < 0) { |
| 7222 | wpa_printf(MSG_WARNING, |
| 7223 | "nl80211: Failed to add interface %s into bridge %s: %s", |
| 7224 | bss->ifname, bss->brname, strerror(errno)); |
| 7225 | } |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7226 | br_ifindex = if_nametoindex(bss->brname); |
| 7227 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7228 | } |
| 7229 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
| 7230 | } |
| 7231 | |
| 7232 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7233 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 7234 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7235 | { |
| 7236 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 7237 | } |
| 7238 | |
| 7239 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7240 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 7241 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7242 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7243 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7244 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7248 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 7249 | struct wpa_driver_capa *capa) |
| 7250 | { |
| 7251 | struct i802_bss *bss = priv; |
| 7252 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 7253 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7254 | if (!drv->has_capability) |
| 7255 | return -1; |
| 7256 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7257 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 7258 | capa->extended_capa = drv->extended_capa; |
| 7259 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 7260 | capa->extended_capa_len = drv->extended_capa_len; |
| 7261 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7262 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7263 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | |
| 7267 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 7268 | { |
| 7269 | struct i802_bss *bss = priv; |
| 7270 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7271 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7272 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 7273 | bss->ifname, drv->operstate, state, |
| 7274 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7275 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7276 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7277 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 7278 | } |
| 7279 | |
| 7280 | |
| 7281 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 7282 | { |
| 7283 | struct i802_bss *bss = priv; |
| 7284 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7285 | struct nl_msg *msg; |
| 7286 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7287 | int ret; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7288 | const u8 *connected_addr = drv->sta_mlo_info.valid_links ? |
| 7289 | drv->sta_mlo_info.ap_mld_addr : drv->bssid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7290 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7291 | if (!drv->associated && is_zero_ether_addr(connected_addr) && |
| 7292 | !authorized) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7293 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 7294 | return 0; |
| 7295 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7296 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7297 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7298 | MACSTR, authorized ? "" : "un", MAC2STR(connected_addr)); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7299 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7300 | os_memset(&upd, 0, sizeof(upd)); |
| 7301 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7302 | if (authorized) |
| 7303 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7304 | |
| 7305 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7306 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7307 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 7308 | nlmsg_free(msg); |
| 7309 | return -ENOBUFS; |
| 7310 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7311 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7312 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7313 | if (!ret) |
| 7314 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7315 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 7316 | ret, strerror(-ret)); |
| 7317 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7318 | } |
| 7319 | |
| 7320 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7321 | /* Set kernel driver on given frequency (MHz) */ |
| 7322 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7323 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7324 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 7325 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7329 | static inline int min_int(int a, int b) |
| 7330 | { |
| 7331 | if (a < b) |
| 7332 | return a; |
| 7333 | return b; |
| 7334 | } |
| 7335 | |
| 7336 | |
| 7337 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 7338 | { |
| 7339 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7340 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7341 | |
| 7342 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7343 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7344 | |
| 7345 | /* |
| 7346 | * TODO: validate the key index and mac address! |
| 7347 | * Otherwise, there's a race condition as soon as |
| 7348 | * the kernel starts sending key notifications. |
| 7349 | */ |
| 7350 | |
| 7351 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 7352 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 7353 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7354 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7355 | return NL_SKIP; |
| 7356 | } |
| 7357 | |
| 7358 | |
| 7359 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 7360 | int idx, u8 *seq) |
| 7361 | { |
| 7362 | struct i802_bss *bss = priv; |
| 7363 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7364 | struct nl_msg *msg; |
| 7365 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7366 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 7367 | NL80211_CMD_GET_KEY); |
| 7368 | if (!msg || |
| 7369 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7370 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 7371 | nlmsg_free(msg); |
| 7372 | return -ENOBUFS; |
| 7373 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7374 | |
| 7375 | memset(seq, 0, 6); |
| 7376 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7377 | return send_and_recv_msgs(drv, msg, get_key_handler, seq, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7378 | } |
| 7379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7380 | |
| 7381 | static int i802_set_rts(void *priv, int rts) |
| 7382 | { |
| 7383 | struct i802_bss *bss = priv; |
| 7384 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7385 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7386 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7387 | u32 val; |
| 7388 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7389 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7390 | val = (u32) -1; |
| 7391 | else |
| 7392 | val = rts; |
| 7393 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7394 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7395 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 7396 | nlmsg_free(msg); |
| 7397 | return -ENOBUFS; |
| 7398 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7399 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7400 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7401 | if (!ret) |
| 7402 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7403 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 7404 | "%d (%s)", rts, ret, strerror(-ret)); |
| 7405 | return ret; |
| 7406 | } |
| 7407 | |
| 7408 | |
| 7409 | static int i802_set_frag(void *priv, int frag) |
| 7410 | { |
| 7411 | struct i802_bss *bss = priv; |
| 7412 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7413 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7414 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7415 | u32 val; |
| 7416 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7417 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7418 | val = (u32) -1; |
| 7419 | else |
| 7420 | val = frag; |
| 7421 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7422 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7423 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 7424 | nlmsg_free(msg); |
| 7425 | return -ENOBUFS; |
| 7426 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7427 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7428 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7429 | if (!ret) |
| 7430 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7431 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 7432 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 7433 | return ret; |
| 7434 | } |
| 7435 | |
| 7436 | |
| 7437 | static int i802_flush(void *priv) |
| 7438 | { |
| 7439 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7441 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7442 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7443 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 7444 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7445 | |
| 7446 | /* |
| 7447 | * XXX: FIX! this needs to flush all VLANs too |
| 7448 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7449 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7450 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7451 | if (res) { |
| 7452 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 7453 | "(%s)", res, strerror(-res)); |
| 7454 | } |
| 7455 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7456 | } |
| 7457 | |
| 7458 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7459 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 7460 | struct nlattr *attr) |
| 7461 | { |
| 7462 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 7463 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 7464 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 7465 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 7466 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 7467 | }; |
| 7468 | int rem; |
| 7469 | |
| 7470 | nla_for_each_nested(tidattr, attr, rem) { |
| 7471 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 7472 | tidattr, NULL) != 0 || |
| 7473 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 7474 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 7475 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 7476 | txq_stats_policy) != 0) |
| 7477 | continue; |
| 7478 | /* sum the backlogs over all TIDs for station */ |
| 7479 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 7480 | data->backlog_bytes += nla_get_u32( |
| 7481 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 7482 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 7483 | data->backlog_bytes += nla_get_u32( |
| 7484 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 7485 | } |
| 7486 | } |
| 7487 | |
| 7488 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7489 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 7490 | { |
| 7491 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7492 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7493 | struct hostap_sta_driver_data *data = arg; |
| 7494 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 7495 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 7496 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 7497 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 7498 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7499 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7500 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 7501 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7502 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7503 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7504 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
| 7505 | [NL80211_STA_INFO_CONNECTED_TIME] = { .type = NLA_U32 }, |
| 7506 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7507 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 7508 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7509 | [NL80211_STA_INFO_EXPECTED_THROUGHPUT] = { .type = NLA_U32 }, |
| 7510 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64 }, |
| 7511 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64 }, |
| 7512 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8}, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7513 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7514 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
| 7515 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_S8 }, |
| 7516 | [NL80211_STA_INFO_RX_MPDUS] = { .type = NLA_U32 }, |
| 7517 | [NL80211_STA_INFO_FCS_ERROR_COUNT] = { .type = NLA_U32 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7518 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7519 | }; |
| 7520 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 7521 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 7522 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 7523 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 7524 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 7525 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 7526 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 7527 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7528 | [NL80211_RATE_INFO_HE_MCS] = { .type = NLA_U8 }, |
| 7529 | [NL80211_RATE_INFO_HE_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7530 | }; |
| 7531 | |
| 7532 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7533 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7534 | |
| 7535 | /* |
| 7536 | * TODO: validate the interface and mac address! |
| 7537 | * Otherwise, there's a race condition as soon as |
| 7538 | * the kernel starts sending station notifications. |
| 7539 | */ |
| 7540 | |
| 7541 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 7542 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 7543 | return NL_SKIP; |
| 7544 | } |
| 7545 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 7546 | tb[NL80211_ATTR_STA_INFO], |
| 7547 | stats_policy)) { |
| 7548 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 7549 | return NL_SKIP; |
| 7550 | } |
| 7551 | |
| 7552 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 7553 | data->inactive_msec = |
| 7554 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7555 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7556 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 7557 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 7558 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 7559 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7560 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 7561 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 7562 | /* |
| 7563 | * The driver supports 64-bit counters, so use them to override |
| 7564 | * the 32-bit values. |
| 7565 | */ |
| 7566 | data->rx_bytes = |
| 7567 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 7568 | data->tx_bytes = |
| 7569 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 7570 | data->bytes_64bit = 1; |
| 7571 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7572 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 7573 | data->signal = (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7574 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 7575 | data->rx_packets = |
| 7576 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 7577 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 7578 | data->tx_packets = |
| 7579 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7580 | if (stats[NL80211_STA_INFO_TX_RETRIES]) |
| 7581 | data->tx_retry_count = |
| 7582 | nla_get_u32(stats[NL80211_STA_INFO_TX_RETRIES]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7583 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 7584 | data->tx_retry_failed = |
| 7585 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7586 | if (stats[NL80211_STA_INFO_SIGNAL_AVG]) |
| 7587 | data->avg_signal = |
| 7588 | (s8) nla_get_u8(stats[NL80211_STA_INFO_SIGNAL_AVG]); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7589 | if (stats[NL80211_STA_INFO_CONNECTED_TIME]) { |
| 7590 | data->connected_sec = |
| 7591 | nla_get_u32(stats[NL80211_STA_INFO_CONNECTED_TIME]); |
| 7592 | data->flags |= STA_DRV_DATA_CONN_TIME; |
| 7593 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7594 | if (stats[NL80211_STA_INFO_BEACON_LOSS]) |
| 7595 | data->beacon_loss_count = |
| 7596 | nla_get_u32(stats[NL80211_STA_INFO_BEACON_LOSS]); |
| 7597 | if (stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) |
| 7598 | data->expected_throughput = |
| 7599 | nla_get_u32(stats[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); |
| 7600 | if (stats[NL80211_STA_INFO_RX_DROP_MISC]) |
| 7601 | data->rx_drop_misc = |
| 7602 | nla_get_u64(stats[NL80211_STA_INFO_RX_DROP_MISC]); |
| 7603 | if (stats[NL80211_STA_INFO_BEACON_RX]) |
| 7604 | data->beacons_count = |
| 7605 | nla_get_u64(stats[NL80211_STA_INFO_BEACON_RX]); |
| 7606 | if (stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 7607 | data->avg_beacon_signal = |
| 7608 | (s8) nla_get_u8(stats[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 7609 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 7610 | data->rx_airtime = |
| 7611 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 7612 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 7613 | data->last_ack_rssi = |
| 7614 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 7615 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 7616 | } |
| 7617 | if (stats[NL80211_STA_INFO_ACK_SIGNAL_AVG]) |
| 7618 | data->avg_ack_signal = |
| 7619 | nla_get_s8(stats[NL80211_STA_INFO_ACK_SIGNAL_AVG]); |
| 7620 | if (stats[NL80211_STA_INFO_RX_MPDUS]) |
| 7621 | data->rx_mpdus = nla_get_u32(stats[NL80211_STA_INFO_RX_MPDUS]); |
| 7622 | if (stats[NL80211_STA_INFO_FCS_ERROR_COUNT]) |
| 7623 | data->fcs_error_count = |
| 7624 | nla_get_u32(stats[NL80211_STA_INFO_FCS_ERROR_COUNT]); |
| 7625 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 7626 | data->tx_airtime = |
| 7627 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7628 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7629 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 7630 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7631 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 7632 | rate_policy) == 0) { |
| 7633 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7634 | data->current_tx_rate = |
| 7635 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7636 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7637 | data->current_tx_rate = |
| 7638 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7639 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7640 | /* Convert from 100 kbps to kbps; it's a more convenient unit. |
| 7641 | * It's also safe up until ~1Tbps. */ |
| 7642 | data->current_tx_rate = data->current_tx_rate * 100; |
| 7643 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7644 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 7645 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 7646 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 7647 | } |
| 7648 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7649 | data->tx_vhtmcs = |
| 7650 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7651 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 7652 | } |
| 7653 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7654 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 7655 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7656 | data->tx_vht_nss = |
| 7657 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7658 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 7659 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7660 | if (rate[NL80211_RATE_INFO_HE_MCS]) { |
| 7661 | data->tx_hemcs = |
| 7662 | nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]); |
| 7663 | data->flags |= STA_DRV_DATA_TX_HE_MCS; |
| 7664 | } |
| 7665 | if (rate[NL80211_RATE_INFO_HE_NSS]) { |
| 7666 | data->tx_he_nss = |
| 7667 | nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]); |
| 7668 | data->flags |= STA_DRV_DATA_TX_HE_NSS; |
| 7669 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 7673 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7674 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 7675 | rate_policy) == 0) { |
| 7676 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7677 | data->current_rx_rate = |
| 7678 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7679 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7680 | data->current_rx_rate = |
| 7681 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7682 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7683 | /* Convert from 100 kbps to kbps; it's a more convenient unit. |
| 7684 | * It's also safe up until ~1Tbps. */ |
| 7685 | data->current_rx_rate = data->current_rx_rate * 100; |
| 7686 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7687 | if (rate[NL80211_RATE_INFO_MCS]) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7688 | data->rx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7689 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 7690 | } |
| 7691 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7692 | data->rx_vhtmcs = |
| 7693 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7694 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 7695 | } |
| 7696 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7697 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 7698 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7699 | data->rx_vht_nss = |
| 7700 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7701 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 7702 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7703 | if (rate[NL80211_RATE_INFO_HE_MCS]) { |
| 7704 | data->rx_hemcs = |
| 7705 | nla_get_u8(rate[NL80211_RATE_INFO_HE_MCS]); |
| 7706 | data->flags |= STA_DRV_DATA_RX_HE_MCS; |
| 7707 | } |
| 7708 | if (rate[NL80211_RATE_INFO_HE_NSS]) { |
| 7709 | data->rx_he_nss = |
| 7710 | nla_get_u8(rate[NL80211_RATE_INFO_HE_NSS]); |
| 7711 | data->flags |= STA_DRV_DATA_RX_HE_NSS; |
| 7712 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7713 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7714 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7715 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 7716 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 7717 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7718 | return NL_SKIP; |
| 7719 | } |
| 7720 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 7721 | |
| 7722 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 7723 | const u8 *bssid, |
| 7724 | struct hostap_sta_driver_data *data) |
| 7725 | { |
| 7726 | struct nl_msg *msg; |
| 7727 | |
| 7728 | data->signal = -WPA_INVALID_NOISE; |
| 7729 | data->current_tx_rate = 0; |
| 7730 | |
| 7731 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 7732 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) { |
| 7733 | nlmsg_free(msg); |
| 7734 | return -ENOBUFS; |
| 7735 | } |
| 7736 | |
| 7737 | return send_and_recv_msgs(drv, msg, get_sta_handler, data, NULL, NULL); |
| 7738 | } |
| 7739 | |
| 7740 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7741 | static int i802_read_sta_data(struct i802_bss *bss, |
| 7742 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7743 | const u8 *addr) |
| 7744 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7745 | struct nl_msg *msg; |
| 7746 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7747 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 7748 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7749 | nlmsg_free(msg); |
| 7750 | return -ENOBUFS; |
| 7751 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7752 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7753 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data, |
| 7754 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7755 | } |
| 7756 | |
| 7757 | |
| 7758 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 7759 | int cw_min, int cw_max, int burst_time) |
| 7760 | { |
| 7761 | struct i802_bss *bss = priv; |
| 7762 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7763 | struct nl_msg *msg; |
| 7764 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7765 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7766 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7767 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | if (!msg) |
| 7769 | return -1; |
| 7770 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7771 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 7772 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7773 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7774 | |
| 7775 | /* We are only sending parameters for a single TXQ at a time */ |
| 7776 | params = nla_nest_start(msg, 1); |
| 7777 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7778 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7779 | |
| 7780 | switch (queue) { |
| 7781 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7782 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 7783 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7784 | break; |
| 7785 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7786 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 7787 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7788 | break; |
| 7789 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7790 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 7791 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7792 | break; |
| 7793 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7794 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 7795 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7796 | break; |
| 7797 | } |
| 7798 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 7799 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7800 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 7801 | (burst_time * 100 + 16) / 32) || |
| 7802 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 7803 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 7804 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 7805 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7806 | |
| 7807 | nla_nest_end(msg, params); |
| 7808 | |
| 7809 | nla_nest_end(msg, txq); |
| 7810 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7811 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7812 | wpa_printf(MSG_DEBUG, |
| 7813 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 7814 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 7815 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7816 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7817 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7818 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7819 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7820 | return -1; |
| 7821 | } |
| 7822 | |
| 7823 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7824 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7825 | const char *ifname, int vlan_id) |
| 7826 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7827 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7828 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7829 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7830 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7831 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 7832 | ", ifname=%s[%d], vlan_id=%d)", |
| 7833 | bss->ifname, if_nametoindex(bss->ifname), |
| 7834 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7835 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 7836 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7837 | (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7838 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7839 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 7840 | nlmsg_free(msg); |
| 7841 | return -ENOBUFS; |
| 7842 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7843 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7844 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7845 | if (ret < 0) { |
| 7846 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 7847 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 7848 | MAC2STR(addr), ifname, vlan_id, ret, |
| 7849 | strerror(-ret)); |
| 7850 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7851 | return ret; |
| 7852 | } |
| 7853 | |
| 7854 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7855 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 7856 | { |
| 7857 | struct hostap_sta_driver_data data; |
| 7858 | int ret; |
| 7859 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 7860 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7861 | data.inactive_msec = (unsigned long) -1; |
| 7862 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7863 | if (ret == -ENOENT) |
| 7864 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7865 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 7866 | return -1; |
| 7867 | return data.inactive_msec / 1000; |
| 7868 | } |
| 7869 | |
| 7870 | |
| 7871 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 7872 | { |
| 7873 | #if 0 |
| 7874 | /* TODO */ |
| 7875 | #endif |
| 7876 | return 0; |
| 7877 | } |
| 7878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7879 | |
| 7880 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7881 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7882 | { |
| 7883 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7884 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7885 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 7886 | u8 channel; |
| 7887 | |
| 7888 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 7889 | HOSTAPD_MODE_IEEE80211AD) { |
| 7890 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 7891 | * disassociate the STA instead. */ |
| 7892 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 7893 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7894 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7895 | if (is_mesh_interface(drv->nlmode)) |
| 7896 | return -1; |
| 7897 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7898 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7899 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7900 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7901 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7902 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7903 | WLAN_FC_STYPE_DEAUTH); |
| 7904 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7905 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7906 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7907 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 7908 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7909 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7910 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7911 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | |
| 7915 | 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] | 7916 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7917 | { |
| 7918 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7920 | struct ieee80211_mgmt mgmt; |
| 7921 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7922 | if (is_mesh_interface(drv->nlmode)) |
| 7923 | return -1; |
| 7924 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7925 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7926 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7927 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7928 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7929 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7930 | WLAN_FC_STYPE_DISASSOC); |
| 7931 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7932 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7933 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7934 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 7935 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7936 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7937 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7938 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7939 | } |
| 7940 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7941 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7942 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 7943 | { |
| 7944 | char buf[200], *pos, *end; |
| 7945 | int i, res; |
| 7946 | |
| 7947 | pos = buf; |
| 7948 | end = pos + sizeof(buf); |
| 7949 | |
| 7950 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7951 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7952 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7953 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7954 | drv->if_indices[i].ifindex, |
| 7955 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7956 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7957 | break; |
| 7958 | pos += res; |
| 7959 | } |
| 7960 | *pos = '\0'; |
| 7961 | |
| 7962 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 7963 | drv->num_if_indices, buf); |
| 7964 | } |
| 7965 | |
| 7966 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7967 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7968 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7969 | { |
| 7970 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7971 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7972 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7973 | wpa_printf(MSG_DEBUG, |
| 7974 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 7975 | ifidx, ifidx_reason); |
| 7976 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7977 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 7978 | ifidx); |
| 7979 | return; |
| 7980 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7981 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7982 | if (drv->if_indices[i].ifindex == 0) { |
| 7983 | drv->if_indices[i].ifindex = ifidx; |
| 7984 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7985 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7986 | return; |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | if (drv->if_indices != drv->default_if_indices) |
| 7991 | old = drv->if_indices; |
| 7992 | else |
| 7993 | old = NULL; |
| 7994 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7995 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7996 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7997 | if (!drv->if_indices) { |
| 7998 | if (!old) |
| 7999 | drv->if_indices = drv->default_if_indices; |
| 8000 | else |
| 8001 | drv->if_indices = old; |
| 8002 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 8003 | "interfaces"); |
| 8004 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 8005 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8006 | } |
| 8007 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8008 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 8009 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8010 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 8011 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8012 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8013 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8014 | } |
| 8015 | |
| 8016 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8017 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 8018 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8019 | { |
| 8020 | int i; |
| 8021 | |
| 8022 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8023 | if ((drv->if_indices[i].ifindex == ifidx || |
| 8024 | ifidx == IFIDX_ANY) && |
| 8025 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8026 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8027 | drv->if_indices[i].ifindex = 0; |
| 8028 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8029 | break; |
| 8030 | } |
| 8031 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8032 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8033 | } |
| 8034 | |
| 8035 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8036 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 8037 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8038 | { |
| 8039 | int i; |
| 8040 | |
| 8041 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8042 | if (drv->if_indices[i].ifindex == ifidx && |
| 8043 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8044 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8045 | return 1; |
| 8046 | |
| 8047 | return 0; |
| 8048 | } |
| 8049 | |
| 8050 | |
| 8051 | 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] | 8052 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8053 | { |
| 8054 | struct i802_bss *bss = priv; |
| 8055 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8056 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8057 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8058 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8059 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8060 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 8061 | if (ret >= (int) sizeof(name)) |
| 8062 | wpa_printf(MSG_WARNING, |
| 8063 | "nl80211: WDS interface name was truncated"); |
| 8064 | else if (ret < 0) |
| 8065 | return ret; |
| 8066 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8067 | if (ifname_wds) |
| 8068 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 8069 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8070 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 8071 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 8072 | if (val) { |
| 8073 | if (!if_nametoindex(name)) { |
| 8074 | if (nl80211_create_iface(drv, name, |
| 8075 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8076 | bss->addr, 1, NULL, NULL, 0) < |
| 8077 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8078 | return -1; |
| 8079 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8080 | linux_br_add_if(drv->global->ioctl_sock, |
| 8081 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8082 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8083 | |
| 8084 | os_memset(&event, 0, sizeof(event)); |
| 8085 | event.wds_sta_interface.sta_addr = addr; |
| 8086 | event.wds_sta_interface.ifname = name; |
| 8087 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 8088 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8089 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 8090 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8091 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8092 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 8093 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 8094 | "interface %s up", name); |
| 8095 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8096 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 8097 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8098 | if (bridge_ifname && |
| 8099 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 8100 | name) < 0) |
| 8101 | wpa_printf(MSG_INFO, |
| 8102 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 8103 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8104 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8105 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8106 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8107 | os_memset(&event, 0, sizeof(event)); |
| 8108 | event.wds_sta_interface.sta_addr = addr; |
| 8109 | event.wds_sta_interface.ifname = name; |
| 8110 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 8111 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8112 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8113 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8114 | } |
| 8115 | } |
| 8116 | |
| 8117 | |
| 8118 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 8119 | { |
| 8120 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 8121 | struct sockaddr_ll lladdr; |
| 8122 | unsigned char buf[3000]; |
| 8123 | int len; |
| 8124 | socklen_t fromlen = sizeof(lladdr); |
| 8125 | |
| 8126 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 8127 | (struct sockaddr *)&lladdr, &fromlen); |
| 8128 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8129 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 8130 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8131 | return; |
| 8132 | } |
| 8133 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8134 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8135 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 8136 | } |
| 8137 | |
| 8138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8139 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 8140 | struct i802_bss *bss, |
| 8141 | const char *brname, const char *ifname) |
| 8142 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8143 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8144 | char in_br[IFNAMSIZ]; |
| 8145 | |
| 8146 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8147 | br_ifindex = if_nametoindex(brname); |
| 8148 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8149 | /* |
| 8150 | * Bridge was configured, but the bridge device does |
| 8151 | * not exist. Try to add it now. |
| 8152 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8153 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8154 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 8155 | "bridge interface %s: %s", |
| 8156 | brname, strerror(errno)); |
| 8157 | return -1; |
| 8158 | } |
| 8159 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8160 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8161 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8162 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8163 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8164 | |
| 8165 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8166 | if (os_strcmp(in_br, brname) == 0) { |
| 8167 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8168 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8169 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8170 | |
| 8171 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 8172 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8173 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 8174 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8175 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 8176 | "remove interface %s from bridge " |
| 8177 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8178 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8179 | return -1; |
| 8180 | } |
| 8181 | } |
| 8182 | |
| 8183 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 8184 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8185 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8186 | wpa_printf(MSG_WARNING, |
| 8187 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8188 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8189 | /* Try to continue without the interface being in a bridge. This |
| 8190 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 8191 | * an external component will need to handle bridge |
| 8192 | * configuration. */ |
| 8193 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8194 | } |
| 8195 | bss->added_if_into_bridge = 1; |
| 8196 | |
| 8197 | return 0; |
| 8198 | } |
| 8199 | |
| 8200 | |
| 8201 | static void *i802_init(struct hostapd_data *hapd, |
| 8202 | struct wpa_init_params *params) |
| 8203 | { |
| 8204 | struct wpa_driver_nl80211_data *drv; |
| 8205 | struct i802_bss *bss; |
| 8206 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8207 | char master_ifname[IFNAMSIZ]; |
| 8208 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8209 | int br_added = 0; |
| 8210 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8211 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 8212 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8213 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8214 | if (bss == NULL) |
| 8215 | return NULL; |
| 8216 | |
| 8217 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8218 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8219 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8220 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8221 | params->ifname, master_ifname); |
| 8222 | br_ifindex = if_nametoindex(master_ifname); |
| 8223 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 8224 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 8225 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 8226 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 8227 | params->ifname, master_ifname); |
| 8228 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8229 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 8230 | |
| 8231 | /* check if master itself is under bridge */ |
| 8232 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 8233 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 8234 | master_ifname); |
| 8235 | br_ifindex = if_nametoindex(master_ifname); |
| 8236 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 8237 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8238 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8239 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8240 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8241 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8242 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8243 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8244 | for (i = 0; i < params->num_bridge; i++) { |
| 8245 | if (params->bridge[i]) { |
| 8246 | ifindex = if_nametoindex(params->bridge[i]); |
| 8247 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8248 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8249 | if (ifindex == br_ifindex) |
| 8250 | br_added = 1; |
| 8251 | } |
| 8252 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8253 | |
| 8254 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8255 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8256 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8257 | if (params->num_bridge && params->bridge[0]) { |
| 8258 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 8259 | params->ifname) < 0) |
| 8260 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8261 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8262 | br_added = 1; |
| 8263 | } |
| 8264 | |
| 8265 | if (!br_added && br_ifindex && |
| 8266 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8267 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8268 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8269 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8270 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8271 | int err; |
| 8272 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8273 | drv->rtnl_sk = nl_socket_alloc(); |
| 8274 | if (drv->rtnl_sk == NULL) { |
| 8275 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 8276 | goto failed; |
| 8277 | } |
| 8278 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8279 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 8280 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8281 | 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] | 8282 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8283 | goto failed; |
| 8284 | } |
| 8285 | } |
| 8286 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8287 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8288 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |
| 8289 | wpa_printf(MSG_DEBUG, |
| 8290 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); |
| 8291 | goto skip_eapol_sock; |
| 8292 | } |
| 8293 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8294 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 8295 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8296 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 8297 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8298 | goto failed; |
| 8299 | } |
| 8300 | |
| 8301 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 8302 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8303 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8304 | goto failed; |
| 8305 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8306 | skip_eapol_sock: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8307 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8308 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8309 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8310 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8311 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8312 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8313 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 8314 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8315 | return bss; |
| 8316 | |
| 8317 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8318 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8319 | return NULL; |
| 8320 | } |
| 8321 | |
| 8322 | |
| 8323 | static void i802_deinit(void *priv) |
| 8324 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8325 | struct i802_bss *bss = priv; |
| 8326 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8327 | } |
| 8328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8329 | |
| 8330 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 8331 | enum wpa_driver_if_type type) |
| 8332 | { |
| 8333 | switch (type) { |
| 8334 | case WPA_IF_STATION: |
| 8335 | return NL80211_IFTYPE_STATION; |
| 8336 | case WPA_IF_P2P_CLIENT: |
| 8337 | case WPA_IF_P2P_GROUP: |
| 8338 | return NL80211_IFTYPE_P2P_CLIENT; |
| 8339 | case WPA_IF_AP_VLAN: |
| 8340 | return NL80211_IFTYPE_AP_VLAN; |
| 8341 | case WPA_IF_AP_BSS: |
| 8342 | return NL80211_IFTYPE_AP; |
| 8343 | case WPA_IF_P2P_GO: |
| 8344 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8345 | case WPA_IF_P2P_DEVICE: |
| 8346 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8347 | case WPA_IF_MESH: |
| 8348 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8349 | default: |
| 8350 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8351 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8355 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 8356 | { |
| 8357 | struct wpa_driver_nl80211_data *drv; |
| 8358 | dl_list_for_each(drv, &global->interfaces, |
| 8359 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8360 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8361 | return 1; |
| 8362 | } |
| 8363 | return 0; |
| 8364 | } |
| 8365 | |
| 8366 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8367 | 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] | 8368 | { |
| 8369 | unsigned int idx; |
| 8370 | |
| 8371 | if (!drv->global) |
| 8372 | return -1; |
| 8373 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8374 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8375 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8376 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8377 | new_addr[0] ^= idx << 2; |
| 8378 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 8379 | break; |
| 8380 | } |
| 8381 | if (idx == 64) |
| 8382 | return -1; |
| 8383 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8384 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8385 | MACSTR, MAC2STR(new_addr)); |
| 8386 | |
| 8387 | return 0; |
| 8388 | } |
| 8389 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8390 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8391 | struct wdev_info { |
| 8392 | u64 wdev_id; |
| 8393 | int wdev_id_set; |
| 8394 | u8 macaddr[ETH_ALEN]; |
| 8395 | }; |
| 8396 | |
| 8397 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 8398 | { |
| 8399 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8400 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8401 | struct wdev_info *wi = arg; |
| 8402 | |
| 8403 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8404 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8405 | if (tb[NL80211_ATTR_WDEV]) { |
| 8406 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 8407 | wi->wdev_id_set = 1; |
| 8408 | } |
| 8409 | |
| 8410 | if (tb[NL80211_ATTR_MAC]) |
| 8411 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 8412 | ETH_ALEN); |
| 8413 | |
| 8414 | return NL_SKIP; |
| 8415 | } |
| 8416 | |
| 8417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8418 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 8419 | const char *ifname, const u8 *addr, |
| 8420 | void *bss_ctx, void **drv_priv, |
| 8421 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8422 | const char *bridge, int use_existing, |
| 8423 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8424 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8425 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8426 | struct i802_bss *bss = priv; |
| 8427 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8428 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8429 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8430 | |
| 8431 | if (addr) |
| 8432 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8433 | nlmode = wpa_driver_nl80211_if_type(type); |
| 8434 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 8435 | struct wdev_info p2pdev_info; |
| 8436 | |
| 8437 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 8438 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 8439 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8440 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8441 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 8442 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 8443 | ifname); |
| 8444 | return -1; |
| 8445 | } |
| 8446 | |
| 8447 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 8448 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8449 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8450 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8451 | os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 8452 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8453 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 8454 | ifname, |
| 8455 | (long long unsigned int) p2pdev_info.wdev_id); |
| 8456 | } else { |
| 8457 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8458 | 0, NULL, NULL, use_existing); |
| 8459 | if (use_existing && ifidx == -ENFILE) { |
| 8460 | added = 0; |
| 8461 | ifidx = if_nametoindex(ifname); |
| 8462 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8463 | return -1; |
| 8464 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8465 | } |
| 8466 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8467 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8468 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8469 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 8470 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8471 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8472 | if (added) |
| 8473 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8474 | return -1; |
| 8475 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8476 | } |
| 8477 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8478 | if (!addr && |
| 8479 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8480 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 8481 | type == WPA_IF_STATION || type == WPA_IF_AP_BSS)) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8482 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8483 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8484 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8485 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8486 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8487 | if (added) |
| 8488 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8489 | return -1; |
| 8490 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8491 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8492 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8493 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8494 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8495 | if (added) |
| 8496 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8497 | return -1; |
| 8498 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8499 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8500 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8501 | if (added) |
| 8502 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8503 | return -1; |
| 8504 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8505 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8506 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8507 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8508 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8509 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8510 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 8511 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8512 | if (added) |
| 8513 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8514 | return -1; |
| 8515 | } |
| 8516 | |
| 8517 | if (bridge && |
| 8518 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 8519 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 8520 | "interface %s to a bridge %s", |
| 8521 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8522 | if (added) |
| 8523 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8524 | os_free(new_bss); |
| 8525 | return -1; |
| 8526 | } |
| 8527 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8528 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 8529 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8530 | if (added) |
| 8531 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8532 | os_free(new_bss); |
| 8533 | return -1; |
| 8534 | } |
| 8535 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8536 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8537 | new_bss->ifindex = ifidx; |
| 8538 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8539 | new_bss->next = drv->first_bss->next; |
| 8540 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8541 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8542 | new_bss->added_if = added; |
| 8543 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8544 | if (drv_priv) |
| 8545 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8546 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8547 | |
| 8548 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 8549 | if (nl80211_setup_ap(new_bss)) |
| 8550 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8551 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8552 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8553 | if (drv->global) |
| 8554 | drv->global->if_add_ifindex = ifidx; |
| 8555 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8556 | /* |
| 8557 | * Some virtual interfaces need to process EAPOL packets and events on |
| 8558 | * the parent interface. This is used mainly with hostapd. |
| 8559 | */ |
| 8560 | if (ifidx > 0 && |
| 8561 | (drv->hostapd || |
| 8562 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 8563 | nlmode == NL80211_IFTYPE_WDS || |
| 8564 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8565 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8566 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8567 | return 0; |
| 8568 | } |
| 8569 | |
| 8570 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8571 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8572 | enum wpa_driver_if_type type, |
| 8573 | const char *ifname) |
| 8574 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8575 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8576 | int ifindex = if_nametoindex(ifname); |
| 8577 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8578 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 8579 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8580 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8581 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8582 | else if (ifindex > 0 && !bss->added_if) { |
| 8583 | struct wpa_driver_nl80211_data *drv2; |
| 8584 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8585 | struct wpa_driver_nl80211_data, list) { |
| 8586 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 8587 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 8588 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8589 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8590 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8591 | if (type != WPA_IF_AP_BSS) |
| 8592 | return 0; |
| 8593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8594 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8595 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 8596 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8597 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8598 | "interface %s from bridge %s: %s", |
| 8599 | bss->ifname, bss->brname, strerror(errno)); |
| 8600 | } |
| 8601 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8602 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8603 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8604 | "bridge %s: %s", |
| 8605 | bss->brname, strerror(errno)); |
| 8606 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8607 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8608 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8609 | struct i802_bss *tbss; |
| 8610 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8611 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 8612 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8613 | if (tbss->next == bss) { |
| 8614 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8615 | /* Unsubscribe management frames */ |
| 8616 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8617 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8618 | if (!bss->added_if) |
| 8619 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8620 | os_free(bss); |
| 8621 | bss = NULL; |
| 8622 | break; |
| 8623 | } |
| 8624 | } |
| 8625 | if (bss) |
| 8626 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 8627 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8628 | } else { |
| 8629 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 8630 | nl80211_teardown_ap(bss); |
| 8631 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8632 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8633 | nl80211_destroy_bss(bss); |
| 8634 | if (!bss->added_if) |
| 8635 | i802_set_iface_flags(bss, 0); |
| 8636 | if (drv->first_bss->next) { |
| 8637 | drv->first_bss = drv->first_bss->next; |
| 8638 | drv->ctx = drv->first_bss->ctx; |
| 8639 | os_free(bss); |
| 8640 | } else { |
| 8641 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 8642 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8643 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8644 | |
| 8645 | return 0; |
| 8646 | } |
| 8647 | |
| 8648 | |
| 8649 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 8650 | { |
| 8651 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8652 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8653 | u64 *cookie = arg; |
| 8654 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8655 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8656 | if (tb[NL80211_ATTR_COOKIE]) |
| 8657 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 8658 | return NL_SKIP; |
| 8659 | } |
| 8660 | |
| 8661 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8662 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8663 | unsigned int freq, unsigned int wait, |
| 8664 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8665 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8666 | int offchanok, const u16 *csa_offs, |
| 8667 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8668 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8669 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8670 | struct nl_msg *msg; |
| 8671 | u64 cookie; |
| 8672 | int ret = -1; |
| 8673 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8674 | 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] | 8675 | "no_ack=%d offchanok=%d", |
| 8676 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8677 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8678 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8679 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 8680 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8681 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 8682 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8683 | drv->test_use_roc_tx) && |
| 8684 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 8685 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 8686 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8687 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 8688 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8689 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 8690 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8691 | |
| 8692 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8693 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8694 | msg = NULL; |
| 8695 | if (ret) { |
| 8696 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8697 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 8698 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8699 | } else { |
| 8700 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 8701 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 8702 | (long long unsigned int) cookie); |
| 8703 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8704 | if (save_cookie) |
| 8705 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8706 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8707 | if (!wait) { |
| 8708 | /* There is no need to store this cookie since there |
| 8709 | * is no wait that could be canceled later. */ |
| 8710 | goto fail; |
| 8711 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8712 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8713 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8714 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8715 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8716 | drv->send_frame_cookies[0]); |
| 8717 | os_memmove(&drv->send_frame_cookies[0], |
| 8718 | &drv->send_frame_cookies[1], |
| 8719 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8720 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8721 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8722 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8723 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 8724 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8725 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8726 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8727 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8728 | nlmsg_free(msg); |
| 8729 | return ret; |
| 8730 | } |
| 8731 | |
| 8732 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8733 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 8734 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8735 | unsigned int wait_time, |
| 8736 | const u8 *dst, const u8 *src, |
| 8737 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8738 | const u8 *data, size_t data_len, |
| 8739 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8740 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8741 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8742 | int ret = -1; |
| 8743 | u8 *buf; |
| 8744 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8745 | int offchanok = 1; |
| 8746 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8747 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq && |
| 8748 | bss->beacon_set) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8749 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8750 | |
| 8751 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8752 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
| 8753 | drv->ifindex, freq, wait_time, no_cck, offchanok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8754 | |
| 8755 | buf = os_zalloc(24 + data_len); |
| 8756 | if (buf == NULL) |
| 8757 | return ret; |
| 8758 | os_memcpy(buf + 24, data, data_len); |
| 8759 | hdr = (struct ieee80211_hdr *) buf; |
| 8760 | hdr->frame_control = |
| 8761 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 8762 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 8763 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 8764 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 8765 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8766 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 8767 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 8768 | MAC2STR(src)); |
| 8769 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 8770 | } else { |
| 8771 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 8772 | } |
| 8773 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8774 | #ifdef CONFIG_MESH |
| 8775 | if (is_mesh_interface(drv->nlmode)) { |
| 8776 | struct hostapd_hw_modes *modes; |
| 8777 | u16 num_modes, flags; |
| 8778 | u8 dfs_domain; |
| 8779 | int i; |
| 8780 | |
| 8781 | modes = nl80211_get_hw_feature_data(bss, &num_modes, |
| 8782 | &flags, &dfs_domain); |
| 8783 | if (dfs_domain != HOSTAPD_DFS_REGION_ETSI && |
| 8784 | ieee80211_is_dfs(bss->freq, modes, num_modes)) |
| 8785 | offchanok = 0; |
| 8786 | if (modes) { |
| 8787 | for (i = 0; i < num_modes; i++) { |
| 8788 | os_free(modes[i].channels); |
| 8789 | os_free(modes[i].rates); |
| 8790 | } |
| 8791 | os_free(modes); |
| 8792 | } |
| 8793 | } |
| 8794 | #endif /* CONFIG_MESH */ |
| 8795 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8796 | if (is_ap_interface(drv->nlmode) && |
| 8797 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8798 | (int) freq == bss->freq || drv->device_ap_sme || |
| 8799 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8800 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8801 | 0, freq, no_cck, offchanok, |
| 8802 | wait_time, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8803 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8804 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8805 | 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8806 | 1, no_cck, 0, offchanok, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8807 | |
| 8808 | os_free(buf); |
| 8809 | return ret; |
| 8810 | } |
| 8811 | |
| 8812 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8813 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8814 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8815 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8816 | struct nl_msg *msg; |
| 8817 | int ret; |
| 8818 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8819 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8820 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8821 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8822 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8823 | nlmsg_free(msg); |
| 8824 | return; |
| 8825 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8826 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8827 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8828 | if (ret) |
| 8829 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 8830 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8831 | } |
| 8832 | |
| 8833 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8834 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 8835 | { |
| 8836 | struct i802_bss *bss = priv; |
| 8837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8838 | unsigned int i; |
| 8839 | u64 cookie; |
| 8840 | |
| 8841 | /* Cancel the last pending TX cookie */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8842 | if (drv->send_frame_cookie != (u64) -1) |
| 8843 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8844 | |
| 8845 | /* |
| 8846 | * Cancel the other pending TX cookies, if any. This is needed since |
| 8847 | * the driver may keep a list of all pending offchannel TX operations |
| 8848 | * and free up the radio only once they have expired or cancelled. |
| 8849 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8850 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 8851 | cookie = drv->send_frame_cookies[i - 1]; |
| 8852 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8853 | nl80211_frame_wait_cancel(bss, cookie); |
| 8854 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8855 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8856 | } |
| 8857 | |
| 8858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8859 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 8860 | unsigned int duration) |
| 8861 | { |
| 8862 | struct i802_bss *bss = priv; |
| 8863 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8864 | struct nl_msg *msg; |
| 8865 | int ret; |
| 8866 | u64 cookie; |
| 8867 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8868 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 8869 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8870 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 8871 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8872 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8873 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8874 | |
| 8875 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8876 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8877 | if (ret == 0) { |
| 8878 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 8879 | "0x%llx for freq=%u MHz duration=%u", |
| 8880 | (long long unsigned int) cookie, freq, duration); |
| 8881 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8882 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8883 | return 0; |
| 8884 | } |
| 8885 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 8886 | "(freq=%d duration=%u): %d (%s)", |
| 8887 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8888 | return -1; |
| 8889 | } |
| 8890 | |
| 8891 | |
| 8892 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 8893 | { |
| 8894 | struct i802_bss *bss = priv; |
| 8895 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8896 | struct nl_msg *msg; |
| 8897 | int ret; |
| 8898 | |
| 8899 | if (!drv->pending_remain_on_chan) { |
| 8900 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 8901 | "to cancel"); |
| 8902 | return -1; |
| 8903 | } |
| 8904 | |
| 8905 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 8906 | "0x%llx", |
| 8907 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 8908 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8909 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 8910 | if (!msg || |
| 8911 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 8912 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8913 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8914 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8915 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8916 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8917 | if (ret == 0) |
| 8918 | return 0; |
| 8919 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 8920 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8921 | return -1; |
| 8922 | } |
| 8923 | |
| 8924 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8925 | 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] | 8926 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8927 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8928 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8929 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8930 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 8931 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 8932 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8933 | /* |
| 8934 | * Do not disable Probe Request reporting that was |
| 8935 | * enabled in nl80211_setup_ap(). |
| 8936 | */ |
| 8937 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 8938 | "Probe Request reporting nl_preq=%p while " |
| 8939 | "in AP mode", bss->nl_preq); |
| 8940 | } else if (bss->nl_preq) { |
| 8941 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 8942 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8943 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8944 | } |
| 8945 | return 0; |
| 8946 | } |
| 8947 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8948 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8949 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8950 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8951 | return 0; |
| 8952 | } |
| 8953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8954 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 8955 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8956 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8957 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 8958 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8959 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8960 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8961 | (WLAN_FC_TYPE_MGMT << 2) | |
| 8962 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8963 | NULL, 0, false) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8964 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 8965 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8966 | nl80211_register_eloop_read(&bss->nl_preq, |
| 8967 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8968 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8969 | |
| 8970 | return 0; |
| 8971 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8972 | out_err: |
| 8973 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8974 | return -1; |
| 8975 | } |
| 8976 | |
| 8977 | |
| 8978 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 8979 | int ifindex, int disabled) |
| 8980 | { |
| 8981 | struct nl_msg *msg; |
| 8982 | struct nlattr *bands, *band; |
| 8983 | int ret; |
| 8984 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8985 | wpa_printf(MSG_DEBUG, |
| 8986 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 8987 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 8988 | "no NL80211_TXRATE_LEGACY constraint"); |
| 8989 | |
| 8990 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 8991 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8992 | if (!msg) |
| 8993 | return -1; |
| 8994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8995 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 8996 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8997 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8998 | |
| 8999 | /* |
| 9000 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 9001 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 9002 | * rates. All 5 GHz rates are left enabled. |
| 9003 | */ |
| 9004 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9005 | if (!band || |
| 9006 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 9007 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 9008 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9009 | nla_nest_end(msg, band); |
| 9010 | |
| 9011 | nla_nest_end(msg, bands); |
| 9012 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9013 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9014 | if (ret) { |
| 9015 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 9016 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9017 | } else |
| 9018 | drv->disabled_11b_rates = disabled; |
| 9019 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9020 | return ret; |
| 9021 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9022 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9023 | nlmsg_free(msg); |
| 9024 | return -1; |
| 9025 | } |
| 9026 | |
| 9027 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9028 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 9029 | { |
| 9030 | struct i802_bss *bss = priv; |
| 9031 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9032 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9033 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9034 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9035 | |
| 9036 | /* |
| 9037 | * If the P2P GO interface was dynamically added, then it is |
| 9038 | * possible that the interface change to station is not possible. |
| 9039 | */ |
| 9040 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 9041 | return 0; |
| 9042 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9043 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9044 | } |
| 9045 | |
| 9046 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9047 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 9048 | { |
| 9049 | struct i802_bss *bss = priv; |
| 9050 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9051 | if (!is_ap_interface(drv->nlmode)) |
| 9052 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9053 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9054 | return 0; |
| 9055 | } |
| 9056 | |
| 9057 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9058 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 9059 | { |
| 9060 | struct i802_bss *bss = priv; |
| 9061 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9062 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 9063 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9064 | |
| 9065 | /* |
| 9066 | * If the P2P Client interface was dynamically added, then it is |
| 9067 | * possible that the interface change to station is not possible. |
| 9068 | */ |
| 9069 | if (bss->if_dynamic) |
| 9070 | return 0; |
| 9071 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9072 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 9073 | } |
| 9074 | |
| 9075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9076 | static void wpa_driver_nl80211_resume(void *priv) |
| 9077 | { |
| 9078 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9079 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9080 | |
| 9081 | if (i802_set_iface_flags(bss, 1)) |
| 9082 | 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] | 9083 | |
| 9084 | if (is_p2p_net_interface(nlmode)) |
| 9085 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9089 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 9090 | { |
| 9091 | struct i802_bss *bss = priv; |
| 9092 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9093 | struct nl_msg *msg; |
| 9094 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9095 | |
| 9096 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 9097 | "hysteresis=%d", threshold, hysteresis); |
| 9098 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9099 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 9100 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 9101 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 9102 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 9103 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9104 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9105 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9106 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9107 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9108 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9109 | } |
| 9110 | |
| 9111 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9112 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 9113 | { |
| 9114 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9115 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9116 | struct wpa_signal_info *sig_change = arg; |
| 9117 | |
| 9118 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9119 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9120 | |
| 9121 | sig_change->center_frq1 = -1; |
| 9122 | sig_change->center_frq2 = -1; |
| 9123 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 9124 | |
| 9125 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 9126 | sig_change->chanwidth = convert2width( |
| 9127 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 9128 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 9129 | sig_change->center_frq1 = |
| 9130 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 9131 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 9132 | sig_change->center_frq2 = |
| 9133 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 9134 | } |
| 9135 | |
| 9136 | return NL_SKIP; |
| 9137 | } |
| 9138 | |
| 9139 | |
| 9140 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 9141 | struct wpa_signal_info *sig) |
| 9142 | { |
| 9143 | struct nl_msg *msg; |
| 9144 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9145 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9146 | return send_and_recv_msgs(drv, msg, get_channel_width, sig, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9147 | } |
| 9148 | |
| 9149 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9150 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 9151 | { |
| 9152 | struct i802_bss *bss = priv; |
| 9153 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9154 | int res; |
| 9155 | |
| 9156 | os_memset(si, 0, sizeof(*si)); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9157 | res = nl80211_get_link_signal(drv, drv->bssid, &si->data); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9158 | if (res) { |
| 9159 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 9160 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 9161 | return res; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9162 | si->data.signal = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9163 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9164 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9165 | res = nl80211_get_channel_width(drv, si); |
| 9166 | if (res != 0) |
| 9167 | return res; |
| 9168 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9169 | return nl80211_get_link_noise(drv, si); |
| 9170 | } |
| 9171 | |
| 9172 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9173 | static int get_links_noise(struct nl_msg *msg, void *arg) |
| 9174 | { |
| 9175 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9176 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9177 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 9178 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 9179 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 9180 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 9181 | }; |
| 9182 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 9183 | int i; |
| 9184 | |
| 9185 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9186 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9187 | |
| 9188 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 9189 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); |
| 9190 | return NL_SKIP; |
| 9191 | } |
| 9192 | |
| 9193 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 9194 | tb[NL80211_ATTR_SURVEY_INFO], |
| 9195 | survey_policy)) { |
| 9196 | wpa_printf(MSG_DEBUG, |
| 9197 | "nl80211: Failed to parse nested attributes"); |
| 9198 | return NL_SKIP; |
| 9199 | } |
| 9200 | |
| 9201 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 9202 | return NL_SKIP; |
| 9203 | |
| 9204 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 9205 | return NL_SKIP; |
| 9206 | |
| 9207 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 9208 | if (!(mlo_sig->valid_links & BIT(i))) |
| 9209 | continue; |
| 9210 | |
| 9211 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 9212 | mlo_sig->links[i].frequency) |
| 9213 | continue; |
| 9214 | |
| 9215 | mlo_sig->links[i].current_noise = |
| 9216 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 9217 | break; |
| 9218 | } |
| 9219 | |
| 9220 | return NL_SKIP; |
| 9221 | } |
| 9222 | |
| 9223 | |
| 9224 | static int nl80211_get_links_noise(struct wpa_driver_nl80211_data *drv, |
| 9225 | struct wpa_mlo_signal_info *mlo_sig) |
| 9226 | { |
| 9227 | struct nl_msg *msg; |
| 9228 | |
| 9229 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 9230 | return send_and_recv_msgs(drv, msg, get_links_noise, mlo_sig, |
| 9231 | NULL, NULL); |
| 9232 | } |
| 9233 | |
| 9234 | |
| 9235 | static int get_links_channel_width(struct nl_msg *msg, void *arg) |
| 9236 | { |
| 9237 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9238 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9239 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 9240 | struct nlattr *link; |
| 9241 | int rem_links; |
| 9242 | |
| 9243 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9244 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9245 | |
| 9246 | if (!tb[NL80211_ATTR_MLO_LINKS]) |
| 9247 | return NL_SKIP; |
| 9248 | |
| 9249 | nla_for_each_nested(link, tb[NL80211_ATTR_MLO_LINKS], rem_links) { |
| 9250 | struct nlattr *tb2[NL80211_ATTR_MAX + 1]; |
| 9251 | int link_id; |
| 9252 | |
| 9253 | nla_parse(tb2, NL80211_ATTR_MAX, nla_data(link), nla_len(link), |
| 9254 | NULL); |
| 9255 | |
| 9256 | if (!tb2[NL80211_ATTR_MLO_LINK_ID]) |
| 9257 | continue; |
| 9258 | |
| 9259 | link_id = nla_get_u8(tb2[NL80211_ATTR_MLO_LINK_ID]); |
| 9260 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 9261 | continue; |
| 9262 | |
| 9263 | if (!tb2[NL80211_ATTR_CHANNEL_WIDTH]) |
| 9264 | continue; |
| 9265 | mlo_sig->links[link_id].chanwidth = convert2width( |
| 9266 | nla_get_u32(tb2[NL80211_ATTR_CHANNEL_WIDTH])); |
| 9267 | if (tb2[NL80211_ATTR_CENTER_FREQ1]) |
| 9268 | mlo_sig->links[link_id].center_frq1 = |
| 9269 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ1]); |
| 9270 | if (tb2[NL80211_ATTR_CENTER_FREQ2]) |
| 9271 | mlo_sig->links[link_id].center_frq2 = |
| 9272 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ2]); |
| 9273 | } |
| 9274 | |
| 9275 | return NL_SKIP; |
| 9276 | } |
| 9277 | |
| 9278 | |
| 9279 | static int nl80211_get_links_channel_width(struct wpa_driver_nl80211_data *drv, |
| 9280 | struct wpa_mlo_signal_info *mlo_sig) |
| 9281 | { |
| 9282 | struct nl_msg *msg; |
| 9283 | |
| 9284 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
| 9285 | return send_and_recv_msgs(drv, msg, get_links_channel_width, mlo_sig, |
| 9286 | NULL, NULL); |
| 9287 | } |
| 9288 | |
| 9289 | |
| 9290 | static int nl80211_mlo_signal_poll(void *priv, |
| 9291 | struct wpa_mlo_signal_info *mlo_si) |
| 9292 | { |
| 9293 | struct i802_bss *bss = priv; |
| 9294 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9295 | int res; |
| 9296 | int i; |
| 9297 | |
| 9298 | if (drv->nlmode != NL80211_IFTYPE_STATION || |
| 9299 | !drv->sta_mlo_info.valid_links) |
| 9300 | return -1; |
| 9301 | |
| 9302 | os_memset(mlo_si, 0, sizeof(*mlo_si)); |
| 9303 | mlo_si->valid_links = drv->sta_mlo_info.valid_links; |
| 9304 | |
| 9305 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 9306 | if (!(mlo_si->valid_links & BIT(i))) |
| 9307 | continue; |
| 9308 | |
| 9309 | res = nl80211_get_link_signal(drv, |
| 9310 | drv->sta_mlo_info.links[i].bssid, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9311 | &mlo_si->links[i].data); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9312 | if (res != 0) |
| 9313 | return res; |
| 9314 | |
| 9315 | mlo_si->links[i].center_frq1 = -1; |
| 9316 | mlo_si->links[i].center_frq2 = -1; |
| 9317 | mlo_si->links[i].chanwidth = CHAN_WIDTH_UNKNOWN; |
| 9318 | mlo_si->links[i].current_noise = WPA_INVALID_NOISE; |
| 9319 | mlo_si->links[i].frequency = drv->sta_mlo_info.links[i].freq; |
| 9320 | } |
| 9321 | |
| 9322 | res = nl80211_get_links_channel_width(drv, mlo_si); |
| 9323 | if (res != 0) |
| 9324 | return res; |
| 9325 | |
| 9326 | return nl80211_get_links_noise(drv, mlo_si); |
| 9327 | } |
| 9328 | |
| 9329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9330 | static int nl80211_set_param(void *priv, const char *param) |
| 9331 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9332 | struct i802_bss *bss = priv; |
| 9333 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9334 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9335 | if (param == NULL) |
| 9336 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9337 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9338 | |
| 9339 | #ifdef CONFIG_P2P |
| 9340 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9341 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 9342 | "interface"); |
| 9343 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 9344 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 9345 | } |
| 9346 | #endif /* CONFIG_P2P */ |
| 9347 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9348 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9349 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9350 | |
| 9351 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9352 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9353 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9354 | } |
| 9355 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9356 | if (os_strstr(param, "force_bss_selection=1")) |
| 9357 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 9358 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9359 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9360 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 9361 | drv->test_use_roc_tx = 1; |
| 9362 | } |
| 9363 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9364 | if (os_strstr(param, "control_port=0")) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9365 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9366 | drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX | |
| 9367 | WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS); |
| 9368 | drv->control_port_ap = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9369 | } |
| 9370 | |
| 9371 | if (os_strstr(param, "control_port_ap=1")) |
| 9372 | drv->control_port_ap = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9373 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9374 | if (os_strstr(param, "control_port_ap=0")) { |
| 9375 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS; |
| 9376 | drv->control_port_ap = 0; |
| 9377 | } |
| 9378 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9379 | if (os_strstr(param, "full_ap_client_state=0")) |
| 9380 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 9381 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9382 | if (os_strstr(param, "no_rrm=1")) { |
| 9383 | drv->no_rrm = 1; |
| 9384 | |
| 9385 | if (!bss->in_deinit && !is_ap_interface(drv->nlmode) && |
| 9386 | !is_mesh_interface(drv->nlmode)) { |
| 9387 | nl80211_mgmt_unsubscribe(bss, "no_rrm=1"); |
| 9388 | if (nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 9389 | wpa_printf(MSG_DEBUG, |
| 9390 | "nl80211: Failed to re-register Action frame processing - ignore for now"); |
| 9391 | } |
| 9392 | } |
| 9393 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9394 | return 0; |
| 9395 | } |
| 9396 | |
| 9397 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9398 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9399 | { |
| 9400 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9401 | struct netlink_config *cfg; |
| 9402 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9403 | global = os_zalloc(sizeof(*global)); |
| 9404 | if (global == NULL) |
| 9405 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9406 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9407 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9408 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9409 | global->if_add_ifindex = -1; |
| 9410 | |
| 9411 | cfg = os_zalloc(sizeof(*cfg)); |
| 9412 | if (cfg == NULL) |
| 9413 | goto err; |
| 9414 | |
| 9415 | cfg->ctx = global; |
| 9416 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 9417 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 9418 | global->netlink = netlink_init(cfg); |
| 9419 | if (global->netlink == NULL) { |
| 9420 | os_free(cfg); |
| 9421 | goto err; |
| 9422 | } |
| 9423 | |
| 9424 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 9425 | goto err; |
| 9426 | |
| 9427 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 9428 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9429 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 9430 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9431 | goto err; |
| 9432 | } |
| 9433 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9434 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9435 | |
| 9436 | err: |
| 9437 | nl80211_global_deinit(global); |
| 9438 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9439 | } |
| 9440 | |
| 9441 | |
| 9442 | static void nl80211_global_deinit(void *priv) |
| 9443 | { |
| 9444 | struct nl80211_global *global = priv; |
| 9445 | if (global == NULL) |
| 9446 | return; |
| 9447 | if (!dl_list_empty(&global->interfaces)) { |
| 9448 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 9449 | "nl80211_global_deinit", |
| 9450 | dl_list_len(&global->interfaces)); |
| 9451 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9452 | |
| 9453 | if (global->netlink) |
| 9454 | netlink_deinit(global->netlink); |
| 9455 | |
| 9456 | nl_destroy_handles(&global->nl); |
| 9457 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9458 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9459 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9460 | |
| 9461 | nl_cb_put(global->nl_cb); |
| 9462 | |
| 9463 | if (global->ioctl_sock >= 0) |
| 9464 | close(global->ioctl_sock); |
| 9465 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9466 | os_free(global); |
| 9467 | } |
| 9468 | |
| 9469 | |
| 9470 | static const char * nl80211_get_radio_name(void *priv) |
| 9471 | { |
| 9472 | struct i802_bss *bss = priv; |
| 9473 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9474 | return drv->phyname; |
| 9475 | } |
| 9476 | |
| 9477 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9478 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9479 | struct wpa_pmkid_params *params, bool skip_pmk) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9480 | { |
| 9481 | struct nl_msg *msg; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9482 | |
| 9483 | if (cmd == NL80211_CMD_SET_PMKSA) |
| 9484 | wpa_printf(MSG_DEBUG, |
| 9485 | "nl80211: NL80211_CMD_SET_PMKSA with skip_pmk=%s pmk_len=%zu", |
| 9486 | skip_pmk ? "true" : "false", params->pmk_len); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9487 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9488 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9489 | (params->pmkid && |
| 9490 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 9491 | (params->bssid && |
| 9492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 9493 | (params->ssid_len && |
| 9494 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 9495 | (params->fils_cache_id && |
| 9496 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 9497 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9498 | (params->pmk_lifetime && |
| 9499 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 9500 | params->pmk_lifetime)) || |
| 9501 | (params->pmk_reauth_threshold && |
| 9502 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 9503 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 9504 | (cmd != NL80211_CMD_DEL_PMKSA && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9505 | params->pmk_len && !skip_pmk && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9506 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9507 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9508 | nlmsg_free(msg); |
| 9509 | return -ENOBUFS; |
| 9510 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9511 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9512 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9513 | } |
| 9514 | |
| 9515 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9516 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9517 | { |
| 9518 | struct i802_bss *bss = priv; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9519 | const size_t PMK_MAX_LEN = 64; /* current cfg80211 limit */ |
| 9520 | const size_t LEGACY_PMK_MAX_LEN = 48; /* old cfg80211 limit */ |
| 9521 | bool skip_pmk = params->pmk_len > PMK_MAX_LEN; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9522 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9523 | |
| 9524 | if (params->bssid) |
| 9525 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 9526 | MAC2STR(params->bssid)); |
| 9527 | else if (params->fils_cache_id && params->ssid_len) { |
| 9528 | wpa_printf(MSG_DEBUG, |
| 9529 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 9530 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 9531 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 9532 | } |
| 9533 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9534 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, skip_pmk); |
| 9535 | /* |
| 9536 | * Try again by skipping PMK if the first attempt failed with ERANGE |
| 9537 | * error, PMK was not skipped, and PMK length is greater than the |
| 9538 | * legacy kernel maximum allowed limit. |
| 9539 | */ |
| 9540 | if (ret == -ERANGE && !skip_pmk && |
| 9541 | params->pmk_len > LEGACY_PMK_MAX_LEN) |
| 9542 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params, true); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9543 | if (ret < 0) { |
| 9544 | wpa_printf(MSG_DEBUG, |
| 9545 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 9546 | ret, strerror(-ret)); |
| 9547 | } |
| 9548 | |
| 9549 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9550 | } |
| 9551 | |
| 9552 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9553 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9554 | { |
| 9555 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9556 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9557 | |
| 9558 | if (params->bssid) |
| 9559 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 9560 | MAC2STR(params->bssid)); |
| 9561 | else if (params->fils_cache_id && params->ssid_len) { |
| 9562 | wpa_printf(MSG_DEBUG, |
| 9563 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 9564 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 9565 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 9566 | } |
| 9567 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 9568 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params, true); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9569 | if (ret < 0) { |
| 9570 | wpa_printf(MSG_DEBUG, |
| 9571 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 9572 | ret, strerror(-ret)); |
| 9573 | } |
| 9574 | |
| 9575 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9576 | } |
| 9577 | |
| 9578 | |
| 9579 | static int nl80211_flush_pmkid(void *priv) |
| 9580 | { |
| 9581 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9582 | struct nl_msg *msg; |
| 9583 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9584 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9585 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 9586 | if (!msg) |
| 9587 | return -ENOBUFS; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9588 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9589 | } |
| 9590 | |
| 9591 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9592 | static void clean_survey_results(struct survey_results *survey_results) |
| 9593 | { |
| 9594 | struct freq_survey *survey, *tmp; |
| 9595 | |
| 9596 | if (dl_list_empty(&survey_results->survey_list)) |
| 9597 | return; |
| 9598 | |
| 9599 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 9600 | struct freq_survey, list) { |
| 9601 | dl_list_del(&survey->list); |
| 9602 | os_free(survey); |
| 9603 | } |
| 9604 | } |
| 9605 | |
| 9606 | |
| 9607 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 9608 | struct dl_list *survey_list) |
| 9609 | { |
| 9610 | struct freq_survey *survey; |
| 9611 | |
| 9612 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 9613 | if (!survey) |
| 9614 | return; |
| 9615 | |
| 9616 | survey->ifidx = ifidx; |
| 9617 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 9618 | survey->filled = 0; |
| 9619 | |
| 9620 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 9621 | survey->nf = (int8_t) |
| 9622 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 9623 | survey->filled |= SURVEY_HAS_NF; |
| 9624 | } |
| 9625 | |
| 9626 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 9627 | survey->channel_time = |
| 9628 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 9629 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 9630 | } |
| 9631 | |
| 9632 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 9633 | survey->channel_time_busy = |
| 9634 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 9635 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 9636 | } |
| 9637 | |
| 9638 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 9639 | survey->channel_time_rx = |
| 9640 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 9641 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 9642 | } |
| 9643 | |
| 9644 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 9645 | survey->channel_time_tx = |
| 9646 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 9647 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 9648 | } |
| 9649 | |
| 9650 | 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)", |
| 9651 | survey->freq, |
| 9652 | survey->nf, |
| 9653 | (unsigned long int) survey->channel_time, |
| 9654 | (unsigned long int) survey->channel_time_busy, |
| 9655 | (unsigned long int) survey->channel_time_tx, |
| 9656 | (unsigned long int) survey->channel_time_rx, |
| 9657 | survey->filled); |
| 9658 | |
| 9659 | dl_list_add_tail(survey_list, &survey->list); |
| 9660 | } |
| 9661 | |
| 9662 | |
| 9663 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 9664 | unsigned int freq_filter) |
| 9665 | { |
| 9666 | if (!freq_filter) |
| 9667 | return 1; |
| 9668 | |
| 9669 | return freq_filter == surveyed_freq; |
| 9670 | } |
| 9671 | |
| 9672 | |
| 9673 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 9674 | { |
| 9675 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9676 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9677 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 9678 | struct survey_results *survey_results; |
| 9679 | u32 surveyed_freq = 0; |
| 9680 | u32 ifidx; |
| 9681 | |
| 9682 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 9683 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 9684 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 9685 | }; |
| 9686 | |
| 9687 | survey_results = (struct survey_results *) arg; |
| 9688 | |
| 9689 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9690 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9691 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 9692 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 9693 | return NL_SKIP; |
| 9694 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9695 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 9696 | |
| 9697 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 9698 | return NL_SKIP; |
| 9699 | |
| 9700 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 9701 | tb[NL80211_ATTR_SURVEY_INFO], |
| 9702 | survey_policy)) |
| 9703 | return NL_SKIP; |
| 9704 | |
| 9705 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 9706 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 9707 | return NL_SKIP; |
| 9708 | } |
| 9709 | |
| 9710 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 9711 | |
| 9712 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 9713 | survey_results->freq_filter)) |
| 9714 | return NL_SKIP; |
| 9715 | |
| 9716 | if (survey_results->freq_filter && |
| 9717 | survey_results->freq_filter != surveyed_freq) { |
| 9718 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 9719 | surveyed_freq); |
| 9720 | return NL_SKIP; |
| 9721 | } |
| 9722 | |
| 9723 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 9724 | |
| 9725 | return NL_SKIP; |
| 9726 | } |
| 9727 | |
| 9728 | |
| 9729 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 9730 | { |
| 9731 | struct i802_bss *bss = priv; |
| 9732 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9733 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9734 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9735 | union wpa_event_data data; |
| 9736 | struct survey_results *survey_results; |
| 9737 | |
| 9738 | os_memset(&data, 0, sizeof(data)); |
| 9739 | survey_results = &data.survey_results; |
| 9740 | |
| 9741 | dl_list_init(&survey_results->survey_list); |
| 9742 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9743 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9744 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9745 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9746 | |
| 9747 | if (freq) |
| 9748 | data.survey_results.freq_filter = freq; |
| 9749 | |
| 9750 | do { |
| 9751 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 9752 | err = send_and_recv_msgs(drv, msg, survey_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9753 | survey_results, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9754 | } while (err > 0); |
| 9755 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9756 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9757 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9758 | else |
| 9759 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9760 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9761 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9762 | return err; |
| 9763 | } |
| 9764 | |
| 9765 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9766 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 9767 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9768 | const u8 *replay_ctr) |
| 9769 | { |
| 9770 | struct i802_bss *bss = priv; |
| 9771 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9772 | struct nlattr *replay_nested; |
| 9773 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9774 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9775 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9776 | if (!drv->set_rekey_offload) |
| 9777 | return; |
| 9778 | |
| 9779 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9780 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 9781 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9782 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9783 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9784 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 9785 | replay_ctr)) { |
| 9786 | nl80211_nlmsg_clear(msg); |
| 9787 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9788 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9789 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9790 | |
| 9791 | nla_nest_end(msg, replay_nested); |
| 9792 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9793 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9794 | if (ret == -EOPNOTSUPP) { |
| 9795 | wpa_printf(MSG_DEBUG, |
| 9796 | "nl80211: Driver does not support rekey offload"); |
| 9797 | drv->set_rekey_offload = 0; |
| 9798 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9799 | } |
| 9800 | |
| 9801 | |
| 9802 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 9803 | const u8 *addr, int qos) |
| 9804 | { |
| 9805 | /* send data frame to poll STA and check whether |
| 9806 | * this frame is ACKed */ |
| 9807 | struct { |
| 9808 | struct ieee80211_hdr hdr; |
| 9809 | u16 qos_ctl; |
| 9810 | } STRUCT_PACKED nulldata; |
| 9811 | size_t size; |
| 9812 | |
| 9813 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 9814 | |
| 9815 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 9816 | |
| 9817 | if (qos) { |
| 9818 | nulldata.hdr.frame_control = |
| 9819 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9820 | WLAN_FC_STYPE_QOS_NULL); |
| 9821 | size = sizeof(nulldata); |
| 9822 | } else { |
| 9823 | nulldata.hdr.frame_control = |
| 9824 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9825 | WLAN_FC_STYPE_NULLFUNC); |
| 9826 | size = sizeof(struct ieee80211_hdr); |
| 9827 | } |
| 9828 | |
| 9829 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 9830 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 9831 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 9832 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 9833 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9834 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9835 | 0, 0, NULL, 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9836 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 9837 | "send poll frame"); |
| 9838 | } |
| 9839 | |
| 9840 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 9841 | int qos) |
| 9842 | { |
| 9843 | struct i802_bss *bss = priv; |
| 9844 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9845 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9846 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9847 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9848 | |
| 9849 | if (!drv->poll_command_supported) { |
| 9850 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 9851 | return; |
| 9852 | } |
| 9853 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9854 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 9855 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9856 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9857 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9858 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9859 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9860 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9861 | if (ret < 0) { |
| 9862 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 9863 | MACSTR " failed: ret=%d (%s)", |
| 9864 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9865 | } else { |
| 9866 | wpa_printf(MSG_DEBUG, |
| 9867 | "nl80211: Client probe request addr=" MACSTR |
| 9868 | " cookie=%llu", MAC2STR(addr), |
| 9869 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9870 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9871 | } |
| 9872 | |
| 9873 | |
| 9874 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 9875 | { |
| 9876 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9877 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9878 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9879 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 9880 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 9881 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 9882 | nlmsg_free(msg); |
| 9883 | return -ENOBUFS; |
| 9884 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9885 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9886 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9887 | if (ret < 0) { |
| 9888 | wpa_printf(MSG_DEBUG, |
| 9889 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 9890 | enabled ? "enabled" : "disabled", |
| 9891 | ret, strerror(-ret)); |
| 9892 | } |
| 9893 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9894 | } |
| 9895 | |
| 9896 | |
| 9897 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 9898 | int ctwindow) |
| 9899 | { |
| 9900 | struct i802_bss *bss = priv; |
| 9901 | |
| 9902 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 9903 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 9904 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9905 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9906 | #ifdef ANDROID_P2P |
| 9907 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9908 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9909 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9910 | #endif /* ANDROID_P2P */ |
| 9911 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9912 | |
| 9913 | if (legacy_ps == -1) |
| 9914 | return 0; |
| 9915 | if (legacy_ps != 0 && legacy_ps != 1) |
| 9916 | return -1; /* Not yet supported */ |
| 9917 | |
| 9918 | return nl80211_set_power_save(bss, legacy_ps); |
| 9919 | } |
| 9920 | |
| 9921 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9922 | static int nl80211_start_radar_detection(void *priv, |
| 9923 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9924 | { |
| 9925 | struct i802_bss *bss = priv; |
| 9926 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9927 | struct nl_msg *msg; |
| 9928 | int ret; |
| 9929 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9930 | 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)", |
| 9931 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9932 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 9933 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9934 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 9935 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 9936 | "detection"); |
| 9937 | return -1; |
| 9938 | } |
| 9939 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9940 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 9941 | nl80211_put_freq_params(msg, freq) < 0) { |
| 9942 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9943 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9944 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9945 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9946 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9947 | if (ret == 0) |
| 9948 | return 0; |
| 9949 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 9950 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9951 | return -1; |
| 9952 | } |
| 9953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9954 | #ifdef CONFIG_TDLS |
| 9955 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9956 | static int nl80211_add_peer_capab(struct nl_msg *msg, |
| 9957 | enum tdls_peer_capability capa) |
| 9958 | { |
| 9959 | u32 peer_capab = 0; |
| 9960 | |
| 9961 | if (!capa) |
| 9962 | return 0; |
| 9963 | |
| 9964 | if (capa & TDLS_PEER_HT) |
| 9965 | peer_capab |= NL80211_TDLS_PEER_HT; |
| 9966 | if (capa & TDLS_PEER_VHT) |
| 9967 | peer_capab |= NL80211_TDLS_PEER_VHT; |
| 9968 | if (capa & TDLS_PEER_WMM) |
| 9969 | peer_capab |= NL80211_TDLS_PEER_WMM; |
| 9970 | if (capa & TDLS_PEER_HE) |
| 9971 | peer_capab |= NL80211_TDLS_PEER_HE; |
| 9972 | |
| 9973 | return nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 9974 | peer_capab); |
| 9975 | } |
| 9976 | |
| 9977 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9978 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 9979 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 9980 | u32 peer_capab, int initiator, const u8 *buf, |
| 9981 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9982 | { |
| 9983 | struct i802_bss *bss = priv; |
| 9984 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9985 | struct nl_msg *msg; |
| 9986 | |
| 9987 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9988 | return -EOPNOTSUPP; |
| 9989 | |
| 9990 | if (!dst) |
| 9991 | return -EINVAL; |
| 9992 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9993 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 9994 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 9995 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 9996 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9997 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code) || |
| 9998 | nl80211_add_peer_capab(msg, peer_capab) || |
| 9999 | (initiator && nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10000 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 10001 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10002 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10003 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10004 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10005 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10006 | nlmsg_free(msg); |
| 10007 | return -ENOBUFS; |
| 10008 | } |
| 10009 | |
| 10010 | |
| 10011 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 10012 | { |
| 10013 | struct i802_bss *bss = priv; |
| 10014 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10015 | struct nl_msg *msg; |
| 10016 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10017 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10018 | |
| 10019 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 10020 | return -EOPNOTSUPP; |
| 10021 | |
| 10022 | switch (oper) { |
| 10023 | case TDLS_DISCOVERY_REQ: |
| 10024 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 10025 | break; |
| 10026 | case TDLS_SETUP: |
| 10027 | nl80211_oper = NL80211_TDLS_SETUP; |
| 10028 | break; |
| 10029 | case TDLS_TEARDOWN: |
| 10030 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 10031 | break; |
| 10032 | case TDLS_ENABLE_LINK: |
| 10033 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 10034 | break; |
| 10035 | case TDLS_DISABLE_LINK: |
| 10036 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 10037 | break; |
| 10038 | case TDLS_ENABLE: |
| 10039 | return 0; |
| 10040 | case TDLS_DISABLE: |
| 10041 | return 0; |
| 10042 | default: |
| 10043 | return -EINVAL; |
| 10044 | } |
| 10045 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10046 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 10047 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 10048 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 10049 | nlmsg_free(msg); |
| 10050 | return -ENOBUFS; |
| 10051 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10052 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10053 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10054 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 10055 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 10056 | strerror(-res)); |
| 10057 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10058 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10059 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10060 | |
| 10061 | static int |
| 10062 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 10063 | const struct hostapd_freq_params *params) |
| 10064 | { |
| 10065 | struct i802_bss *bss = priv; |
| 10066 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10067 | struct nl_msg *msg; |
| 10068 | int ret = -ENOBUFS; |
| 10069 | |
| 10070 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 10071 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 10072 | return -EOPNOTSUPP; |
| 10073 | |
| 10074 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 10075 | " oper_class=%u freq=%u", |
| 10076 | MAC2STR(addr), oper_class, params->freq); |
| 10077 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 10078 | if (!msg || |
| 10079 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10080 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 10081 | (ret = nl80211_put_freq_params(msg, params))) { |
| 10082 | nlmsg_free(msg); |
| 10083 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 10084 | return ret; |
| 10085 | } |
| 10086 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10087 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10088 | } |
| 10089 | |
| 10090 | |
| 10091 | static int |
| 10092 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 10093 | { |
| 10094 | struct i802_bss *bss = priv; |
| 10095 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10096 | struct nl_msg *msg; |
| 10097 | |
| 10098 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 10099 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 10100 | return -EOPNOTSUPP; |
| 10101 | |
| 10102 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 10103 | MAC2STR(addr)); |
| 10104 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 10105 | if (!msg || |
| 10106 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10107 | nlmsg_free(msg); |
| 10108 | wpa_printf(MSG_DEBUG, |
| 10109 | "nl80211: Could not build TDLS cancel chan switch"); |
| 10110 | return -ENOBUFS; |
| 10111 | } |
| 10112 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10113 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10114 | } |
| 10115 | |
| 10116 | #endif /* CONFIG TDLS */ |
| 10117 | |
| 10118 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10119 | static int driver_nl80211_set_key(void *priv, |
| 10120 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10121 | { |
| 10122 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10123 | |
| 10124 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10125 | } |
| 10126 | |
| 10127 | |
| 10128 | static int driver_nl80211_scan2(void *priv, |
| 10129 | struct wpa_driver_scan_params *params) |
| 10130 | { |
| 10131 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10132 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10133 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10134 | |
| 10135 | /* |
| 10136 | * Do a vendor specific scan if possible. If only_new_results is |
| 10137 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 10138 | * cannot be achieved through a vendor scan. The below condition may |
| 10139 | * need to be modified if new scan flags are added in the future whose |
| 10140 | * functionality can only be achieved through a normal scan. |
| 10141 | */ |
| 10142 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 10143 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 10144 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10145 | return wpa_driver_nl80211_scan(bss, params); |
| 10146 | } |
| 10147 | |
| 10148 | |
| 10149 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10150 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10151 | { |
| 10152 | struct i802_bss *bss = priv; |
| 10153 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 10154 | } |
| 10155 | |
| 10156 | |
| 10157 | static int driver_nl80211_authenticate(void *priv, |
| 10158 | struct wpa_driver_auth_params *params) |
| 10159 | { |
| 10160 | struct i802_bss *bss = priv; |
| 10161 | return wpa_driver_nl80211_authenticate(bss, params); |
| 10162 | } |
| 10163 | |
| 10164 | |
| 10165 | static void driver_nl80211_deinit(void *priv) |
| 10166 | { |
| 10167 | struct i802_bss *bss = priv; |
| 10168 | wpa_driver_nl80211_deinit(bss); |
| 10169 | } |
| 10170 | |
| 10171 | |
| 10172 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 10173 | const char *ifname) |
| 10174 | { |
| 10175 | struct i802_bss *bss = priv; |
| 10176 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 10177 | } |
| 10178 | |
| 10179 | |
| 10180 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 10181 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10182 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10183 | const u16 *csa_offs, size_t csa_offs_len, |
| 10184 | int no_encrypt, unsigned int wait) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10185 | { |
| 10186 | struct i802_bss *bss = priv; |
| 10187 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10188 | freq, 0, 0, wait, csa_offs, |
| 10189 | csa_offs_len, no_encrypt); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10190 | } |
| 10191 | |
| 10192 | |
| 10193 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 10194 | { |
| 10195 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10196 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10197 | } |
| 10198 | |
| 10199 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10200 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 10201 | const char *ifname, int vlan_id) |
| 10202 | { |
| 10203 | struct i802_bss *bss = priv; |
| 10204 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 10205 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10206 | |
| 10207 | |
| 10208 | static int driver_nl80211_read_sta_data(void *priv, |
| 10209 | struct hostap_sta_driver_data *data, |
| 10210 | const u8 *addr) |
| 10211 | { |
| 10212 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 10213 | |
| 10214 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10215 | return i802_read_sta_data(bss, data, addr); |
| 10216 | } |
| 10217 | |
| 10218 | |
| 10219 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 10220 | unsigned int wait_time, |
| 10221 | const u8 *dst, const u8 *src, |
| 10222 | const u8 *bssid, |
| 10223 | const u8 *data, size_t data_len, |
| 10224 | int no_cck) |
| 10225 | { |
| 10226 | struct i802_bss *bss = priv; |
| 10227 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 10228 | bssid, data, data_len, no_cck); |
| 10229 | } |
| 10230 | |
| 10231 | |
| 10232 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 10233 | { |
| 10234 | struct i802_bss *bss = priv; |
| 10235 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 10236 | } |
| 10237 | |
| 10238 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10239 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 10240 | const u8 *ies, size_t ies_len) |
| 10241 | { |
| 10242 | int ret; |
| 10243 | struct nl_msg *msg; |
| 10244 | struct i802_bss *bss = priv; |
| 10245 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10246 | u16 mdid = WPA_GET_LE16(md); |
| 10247 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10248 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10249 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 10250 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 10251 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 10252 | nlmsg_free(msg); |
| 10253 | return -ENOBUFS; |
| 10254 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10255 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10256 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10257 | if (ret) { |
| 10258 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 10259 | "err=%d (%s)", ret, strerror(-ret)); |
| 10260 | } |
| 10261 | |
| 10262 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10263 | } |
| 10264 | |
| 10265 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10266 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 10267 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 10268 | { |
| 10269 | int ret; |
| 10270 | struct nl_msg *msg; |
| 10271 | struct i802_bss *bss = priv; |
| 10272 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10273 | |
| 10274 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 10275 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 10276 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 10277 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 10278 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 10279 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 10280 | nlmsg_free(msg); |
| 10281 | return -ENOBUFS; |
| 10282 | } |
| 10283 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10284 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10285 | if (ret) { |
| 10286 | wpa_printf(MSG_DEBUG, |
| 10287 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 10288 | ret, strerror(-ret)); |
| 10289 | } |
| 10290 | |
| 10291 | return ret; |
| 10292 | } |
| 10293 | |
| 10294 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 10295 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10296 | { |
| 10297 | struct i802_bss *bss = priv; |
| 10298 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10299 | |
| 10300 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 10301 | return NULL; |
| 10302 | |
| 10303 | return bss->addr; |
| 10304 | } |
| 10305 | |
| 10306 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10307 | static const char * scan_state_str(enum scan_states scan_state) |
| 10308 | { |
| 10309 | switch (scan_state) { |
| 10310 | case NO_SCAN: |
| 10311 | return "NO_SCAN"; |
| 10312 | case SCAN_REQUESTED: |
| 10313 | return "SCAN_REQUESTED"; |
| 10314 | case SCAN_STARTED: |
| 10315 | return "SCAN_STARTED"; |
| 10316 | case SCAN_COMPLETED: |
| 10317 | return "SCAN_COMPLETED"; |
| 10318 | case SCAN_ABORTED: |
| 10319 | return "SCAN_ABORTED"; |
| 10320 | case SCHED_SCAN_STARTED: |
| 10321 | return "SCHED_SCAN_STARTED"; |
| 10322 | case SCHED_SCAN_STOPPED: |
| 10323 | return "SCHED_SCAN_STOPPED"; |
| 10324 | case SCHED_SCAN_RESULTS: |
| 10325 | return "SCHED_SCAN_RESULTS"; |
| 10326 | } |
| 10327 | |
| 10328 | return "??"; |
| 10329 | } |
| 10330 | |
| 10331 | |
| 10332 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 10333 | { |
| 10334 | struct i802_bss *bss = priv; |
| 10335 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10336 | int res; |
| 10337 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10338 | struct nl_msg *msg; |
| 10339 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10340 | |
| 10341 | pos = buf; |
| 10342 | end = buf + buflen; |
| 10343 | |
| 10344 | res = os_snprintf(pos, end - pos, |
| 10345 | "ifindex=%d\n" |
| 10346 | "ifname=%s\n" |
| 10347 | "brname=%s\n" |
| 10348 | "addr=" MACSTR "\n" |
| 10349 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 10350 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10351 | bss->ifindex, |
| 10352 | bss->ifname, |
| 10353 | bss->brname, |
| 10354 | MAC2STR(bss->addr), |
| 10355 | bss->freq, |
| 10356 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 10357 | bss->added_if_into_bridge ? |
| 10358 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 10359 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10360 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 10361 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 10362 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10363 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10364 | return pos - buf; |
| 10365 | pos += res; |
| 10366 | |
| 10367 | if (bss->wdev_id_set) { |
| 10368 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 10369 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10370 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10371 | return pos - buf; |
| 10372 | pos += res; |
| 10373 | } |
| 10374 | |
| 10375 | res = os_snprintf(pos, end - pos, |
| 10376 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10377 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10378 | "drv_ifindex=%d\n" |
| 10379 | "operstate=%d\n" |
| 10380 | "scan_state=%s\n" |
| 10381 | "auth_bssid=" MACSTR "\n" |
| 10382 | "auth_attempt_bssid=" MACSTR "\n" |
| 10383 | "bssid=" MACSTR "\n" |
| 10384 | "prev_bssid=" MACSTR "\n" |
| 10385 | "associated=%d\n" |
| 10386 | "assoc_freq=%u\n" |
| 10387 | "monitor_sock=%d\n" |
| 10388 | "monitor_ifidx=%d\n" |
| 10389 | "monitor_refcount=%d\n" |
| 10390 | "last_mgmt_freq=%u\n" |
| 10391 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10392 | "%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] | 10393 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10394 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10395 | drv->ifindex, |
| 10396 | drv->operstate, |
| 10397 | scan_state_str(drv->scan_state), |
| 10398 | MAC2STR(drv->auth_bssid), |
| 10399 | MAC2STR(drv->auth_attempt_bssid), |
| 10400 | MAC2STR(drv->bssid), |
| 10401 | MAC2STR(drv->prev_bssid), |
| 10402 | drv->associated, |
| 10403 | drv->assoc_freq, |
| 10404 | drv->monitor_sock, |
| 10405 | drv->monitor_ifidx, |
| 10406 | drv->monitor_refcount, |
| 10407 | drv->last_mgmt_freq, |
| 10408 | drv->eapol_tx_sock, |
| 10409 | drv->ignore_if_down_event ? |
| 10410 | "ignore_if_down_event=1\n" : "", |
| 10411 | drv->scan_complete_events ? |
| 10412 | "scan_complete_events=1\n" : "", |
| 10413 | drv->disabled_11b_rates ? |
| 10414 | "disabled_11b_rates=1\n" : "", |
| 10415 | drv->pending_remain_on_chan ? |
| 10416 | "pending_remain_on_chan=1\n" : "", |
| 10417 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 10418 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 10419 | drv->poll_command_supported ? |
| 10420 | "poll_command_supported=1\n" : "", |
| 10421 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 10422 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 10423 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 10424 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 10425 | drv->ignore_next_local_disconnect ? |
| 10426 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 10427 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10428 | "ignore_next_local_deauth=1\n" : ""); |
| 10429 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10430 | return pos - buf; |
| 10431 | pos += res; |
| 10432 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 10433 | if (drv->sta_mlo_info.valid_links) { |
| 10434 | int i; |
| 10435 | struct driver_sta_mlo_info *mlo = &drv->sta_mlo_info; |
| 10436 | |
| 10437 | res = os_snprintf(pos, end - pos, |
| 10438 | "ap_mld_addr=" MACSTR "\n", |
| 10439 | MAC2STR(mlo->ap_mld_addr)); |
| 10440 | if (os_snprintf_error(end - pos, res)) |
| 10441 | return pos - buf; |
| 10442 | pos += res; |
| 10443 | |
| 10444 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 10445 | if (!(mlo->valid_links & BIT(i))) |
| 10446 | continue; |
| 10447 | |
| 10448 | res = os_snprintf(pos, end - pos, |
| 10449 | "link_addr[%u]=" MACSTR "\n" |
| 10450 | "link_bssid[%u]=" MACSTR "\n" |
| 10451 | "link_freq[%u]=%u\n", |
| 10452 | i, MAC2STR(mlo->links[i].addr), |
| 10453 | i, MAC2STR(mlo->links[i].bssid), |
| 10454 | i, mlo->links[i].freq); |
| 10455 | if (os_snprintf_error(end - pos, res)) |
| 10456 | return pos - buf; |
| 10457 | pos += res; |
| 10458 | } |
| 10459 | } |
| 10460 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10461 | if (drv->has_capability) { |
| 10462 | res = os_snprintf(pos, end - pos, |
| 10463 | "capa.key_mgmt=0x%x\n" |
| 10464 | "capa.enc=0x%x\n" |
| 10465 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10466 | "capa.flags=0x%llx\n" |
| 10467 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10468 | "capa.max_scan_ssids=%d\n" |
| 10469 | "capa.max_sched_scan_ssids=%d\n" |
| 10470 | "capa.sched_scan_supported=%d\n" |
| 10471 | "capa.max_match_sets=%d\n" |
| 10472 | "capa.max_remain_on_chan=%u\n" |
| 10473 | "capa.max_stations=%u\n" |
| 10474 | "capa.probe_resp_offloads=0x%x\n" |
| 10475 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10476 | "capa.num_multichan_concurrent=%u\n" |
| 10477 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10478 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 10479 | "capa.conc_capab=%u\n" |
| 10480 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10481 | "capa.max_conc_chan_5_0=%u\n" |
| 10482 | "capa.max_sched_scan_plans=%u\n" |
| 10483 | "capa.max_sched_scan_plan_interval=%u\n" |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 10484 | "capa.max_sched_scan_plan_iterations=%u\n" |
| 10485 | "capa.mbssid_max_interfaces=%u\n" |
| 10486 | "capa.ema_max_periodicity=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10487 | drv->capa.key_mgmt, |
| 10488 | drv->capa.enc, |
| 10489 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10490 | (unsigned long long) drv->capa.flags, |
| 10491 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10492 | drv->capa.max_scan_ssids, |
| 10493 | drv->capa.max_sched_scan_ssids, |
| 10494 | drv->capa.sched_scan_supported, |
| 10495 | drv->capa.max_match_sets, |
| 10496 | drv->capa.max_remain_on_chan, |
| 10497 | drv->capa.max_stations, |
| 10498 | drv->capa.probe_resp_offloads, |
| 10499 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10500 | drv->capa.num_multichan_concurrent, |
| 10501 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10502 | drv->capa.mac_addr_rand_scan_supported, |
| 10503 | drv->capa.conc_capab, |
| 10504 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10505 | drv->capa.max_conc_chan_5_0, |
| 10506 | drv->capa.max_sched_scan_plans, |
| 10507 | drv->capa.max_sched_scan_plan_interval, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 10508 | drv->capa.max_sched_scan_plan_iterations, |
| 10509 | drv->capa.mbssid_max_interfaces, |
| 10510 | drv->capa.ema_max_periodicity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10511 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10512 | return pos - buf; |
| 10513 | pos += res; |
| 10514 | } |
| 10515 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10516 | msg = nlmsg_alloc(); |
| 10517 | if (msg && |
| 10518 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 10519 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 10520 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10521 | alpha2, NULL, NULL) == 0 && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10522 | alpha2[0]) { |
| 10523 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 10524 | alpha2); |
| 10525 | if (os_snprintf_error(end - pos, res)) |
| 10526 | return pos - buf; |
| 10527 | pos += res; |
| 10528 | } |
| 10529 | } else { |
| 10530 | nlmsg_free(msg); |
| 10531 | } |
| 10532 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10533 | return pos - buf; |
| 10534 | } |
| 10535 | |
| 10536 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10537 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 10538 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10539 | if ((settings->head && |
| 10540 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 10541 | settings->head_len, settings->head)) || |
| 10542 | (settings->tail && |
| 10543 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 10544 | settings->tail_len, settings->tail)) || |
| 10545 | (settings->beacon_ies && |
| 10546 | nla_put(msg, NL80211_ATTR_IE, |
| 10547 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 10548 | (settings->proberesp_ies && |
| 10549 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 10550 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 10551 | (settings->assocresp_ies && |
| 10552 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 10553 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 10554 | (settings->probe_resp && |
| 10555 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 10556 | settings->probe_resp_len, settings->probe_resp))) |
| 10557 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10558 | |
| 10559 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10560 | } |
| 10561 | |
| 10562 | |
| 10563 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 10564 | { |
| 10565 | struct nl_msg *msg; |
| 10566 | struct i802_bss *bss = priv; |
| 10567 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10568 | struct nlattr *beacon_csa; |
| 10569 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10570 | int csa_off_len = 0; |
| 10571 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10572 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10573 | wpa_printf(MSG_DEBUG, |
| 10574 | "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d channel=%d sec_channel_offset=%d width=%d cf1=%d cf2=%d%s%s%s)", |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10575 | settings->cs_count, settings->block_tx, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10576 | settings->freq_params.freq, |
| 10577 | settings->freq_params.channel, |
| 10578 | settings->freq_params.sec_channel_offset, |
| 10579 | settings->freq_params.bandwidth, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 10580 | settings->freq_params.center_freq1, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10581 | settings->freq_params.center_freq2, |
| 10582 | settings->freq_params.ht_enabled ? " ht" : "", |
| 10583 | settings->freq_params.vht_enabled ? " vht" : "", |
| 10584 | settings->freq_params.he_enabled ? " he" : ""); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10585 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10586 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10587 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 10588 | return -EOPNOTSUPP; |
| 10589 | } |
| 10590 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10591 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 10592 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 10593 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10594 | return -EOPNOTSUPP; |
| 10595 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10596 | /* |
| 10597 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 10598 | * counters match. This implementation assumes that there are only two |
| 10599 | * counters. |
| 10600 | */ |
| 10601 | if (settings->counter_offset_beacon[0] && |
| 10602 | !settings->counter_offset_beacon[1]) { |
| 10603 | csa_off_len = 1; |
| 10604 | } else if (settings->counter_offset_beacon[1] && |
| 10605 | !settings->counter_offset_beacon[0]) { |
| 10606 | csa_off_len = 1; |
| 10607 | settings->counter_offset_beacon[0] = |
| 10608 | settings->counter_offset_beacon[1]; |
| 10609 | settings->counter_offset_presp[0] = |
| 10610 | settings->counter_offset_presp[1]; |
| 10611 | } else if (settings->counter_offset_beacon[1] && |
| 10612 | settings->counter_offset_beacon[0]) { |
| 10613 | csa_off_len = 2; |
| 10614 | } else { |
| 10615 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 10616 | return -EINVAL; |
| 10617 | } |
| 10618 | |
| 10619 | /* Check CSA counters validity */ |
| 10620 | if (drv->capa.max_csa_counters && |
| 10621 | csa_off_len > drv->capa.max_csa_counters) { |
| 10622 | wpa_printf(MSG_ERROR, |
| 10623 | "nl80211: Too many CSA counters provided"); |
| 10624 | return -EINVAL; |
| 10625 | } |
| 10626 | |
| 10627 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10628 | return -EINVAL; |
| 10629 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10630 | for (i = 0; i < csa_off_len; i++) { |
| 10631 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 10632 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 10633 | |
| 10634 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 10635 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 10636 | settings->cs_count)) |
| 10637 | return -EINVAL; |
| 10638 | |
| 10639 | if (settings->beacon_csa.probe_resp && |
| 10640 | ((settings->beacon_csa.probe_resp_len <= |
| 10641 | csa_c_off_presp) || |
| 10642 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 10643 | settings->cs_count))) |
| 10644 | return -EINVAL; |
| 10645 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10646 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10647 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 10648 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 10649 | settings->cs_count) || |
| 10650 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 10651 | (settings->block_tx && |
| 10652 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10653 | goto error; |
| 10654 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10655 | /* beacon_after params */ |
| 10656 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 10657 | if (ret) |
| 10658 | goto error; |
| 10659 | |
| 10660 | /* beacon_csa params */ |
| 10661 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 10662 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10663 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10664 | |
| 10665 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 10666 | if (ret) |
| 10667 | goto error; |
| 10668 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10669 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 10670 | csa_off_len * sizeof(u16), |
| 10671 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10672 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10673 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 10674 | csa_off_len * sizeof(u16), |
| 10675 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10676 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10677 | |
| 10678 | nla_nest_end(msg, beacon_csa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10679 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10680 | if (ret) { |
| 10681 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 10682 | ret, strerror(-ret)); |
| 10683 | } |
| 10684 | return ret; |
| 10685 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10686 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10687 | ret = -ENOBUFS; |
| 10688 | error: |
| 10689 | nlmsg_free(msg); |
| 10690 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 10691 | return ret; |
| 10692 | } |
| 10693 | |
| 10694 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10695 | #ifdef CONFIG_IEEE80211AX |
| 10696 | static int nl80211_switch_color(void *priv, struct cca_settings *settings) |
| 10697 | { |
| 10698 | struct i802_bss *bss = priv; |
| 10699 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10700 | struct nlattr *beacon_cca; |
| 10701 | struct nl_msg *msg; |
| 10702 | int ret = -ENOBUFS; |
| 10703 | |
| 10704 | wpa_printf(MSG_DEBUG, |
| 10705 | "nl80211: Color change request (cca_count=%u color=%d)", |
| 10706 | settings->cca_count, settings->cca_color); |
| 10707 | |
| 10708 | if (drv->nlmode != NL80211_IFTYPE_AP) |
| 10709 | return -EOPNOTSUPP; |
| 10710 | |
| 10711 | if (!settings->beacon_cca.tail) |
| 10712 | return -EINVAL; |
| 10713 | |
| 10714 | if (settings->beacon_cca.tail_len <= settings->counter_offset_beacon || |
| 10715 | settings->beacon_cca.tail[settings->counter_offset_beacon] != |
| 10716 | settings->cca_count) |
| 10717 | return -EINVAL; |
| 10718 | |
| 10719 | if (settings->beacon_cca.probe_resp && |
| 10720 | (settings->beacon_cca.probe_resp_len <= |
| 10721 | settings->counter_offset_presp || |
| 10722 | settings->beacon_cca.probe_resp[settings->counter_offset_presp] != |
| 10723 | settings->cca_count)) |
| 10724 | return -EINVAL; |
| 10725 | |
| 10726 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_COLOR_CHANGE_REQUEST); |
| 10727 | if (!msg || |
| 10728 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, |
| 10729 | settings->cca_count) || |
| 10730 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COLOR, |
| 10731 | settings->cca_color)) |
| 10732 | goto error; |
| 10733 | |
| 10734 | /* beacon_after params */ |
| 10735 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 10736 | if (ret) |
| 10737 | goto error; |
| 10738 | |
| 10739 | /* beacon_csa params */ |
| 10740 | beacon_cca = nla_nest_start(msg, NL80211_ATTR_COLOR_CHANGE_ELEMS); |
| 10741 | if (!beacon_cca) { |
| 10742 | ret = -ENOBUFS; |
| 10743 | goto error; |
| 10744 | } |
| 10745 | |
| 10746 | ret = set_beacon_data(msg, &settings->beacon_cca); |
| 10747 | if (ret) |
| 10748 | goto error; |
| 10749 | |
| 10750 | if (nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_BEACON, |
| 10751 | settings->counter_offset_beacon) || |
| 10752 | (settings->beacon_cca.probe_resp && |
| 10753 | nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_PRESP, |
| 10754 | settings->counter_offset_presp))) { |
| 10755 | ret = -ENOBUFS; |
| 10756 | goto error; |
| 10757 | } |
| 10758 | |
| 10759 | nla_nest_end(msg, beacon_cca); |
| 10760 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 10761 | if (ret) { |
| 10762 | wpa_printf(MSG_DEBUG, |
| 10763 | "nl80211: switch_color failed err=%d (%s)", |
| 10764 | ret, strerror(-ret)); |
| 10765 | } |
| 10766 | return ret; |
| 10767 | |
| 10768 | error: |
| 10769 | nlmsg_free(msg); |
| 10770 | wpa_printf(MSG_DEBUG, "nl80211: Could not build color switch request"); |
| 10771 | return ret; |
| 10772 | } |
| 10773 | #endif /* CONFIG_IEEE80211AX */ |
| 10774 | |
| 10775 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10776 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 10777 | u8 user_priority, u16 admitted_time) |
| 10778 | { |
| 10779 | struct i802_bss *bss = priv; |
| 10780 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10781 | struct nl_msg *msg; |
| 10782 | int ret; |
| 10783 | |
| 10784 | wpa_printf(MSG_DEBUG, |
| 10785 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 10786 | tsid, admitted_time, user_priority); |
| 10787 | |
| 10788 | if (!is_sta_interface(drv->nlmode)) |
| 10789 | return -ENOTSUP; |
| 10790 | |
| 10791 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 10792 | if (!msg || |
| 10793 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10794 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10795 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 10796 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 10797 | nlmsg_free(msg); |
| 10798 | return -ENOBUFS; |
| 10799 | } |
| 10800 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10801 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10802 | if (ret) |
| 10803 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 10804 | ret, strerror(-ret)); |
| 10805 | return ret; |
| 10806 | } |
| 10807 | |
| 10808 | |
| 10809 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 10810 | { |
| 10811 | struct i802_bss *bss = priv; |
| 10812 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10813 | struct nl_msg *msg; |
| 10814 | int ret; |
| 10815 | |
| 10816 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 10817 | |
| 10818 | if (!is_sta_interface(drv->nlmode)) |
| 10819 | return -ENOTSUP; |
| 10820 | |
| 10821 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 10822 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10823 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10824 | nlmsg_free(msg); |
| 10825 | return -ENOBUFS; |
| 10826 | } |
| 10827 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10828 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10829 | if (ret) |
| 10830 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 10831 | ret, strerror(-ret)); |
| 10832 | return ret; |
| 10833 | } |
| 10834 | |
| 10835 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10836 | #ifdef CONFIG_TESTING_OPTIONS |
| 10837 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 10838 | { |
| 10839 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10840 | struct wpabuf *buf = arg; |
| 10841 | |
| 10842 | if (!buf) |
| 10843 | return NL_SKIP; |
| 10844 | |
| 10845 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 10846 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 10847 | return NL_SKIP; |
| 10848 | } |
| 10849 | |
| 10850 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 10851 | genlmsg_attrlen(gnlh, 0)); |
| 10852 | |
| 10853 | return NL_SKIP; |
| 10854 | } |
| 10855 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10856 | |
| 10857 | |
| 10858 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 10859 | { |
| 10860 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10861 | struct nlattr *nl_vendor_reply, *nl; |
| 10862 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10863 | struct wpabuf *buf = arg; |
| 10864 | int rem; |
| 10865 | |
| 10866 | if (!buf) |
| 10867 | return NL_SKIP; |
| 10868 | |
| 10869 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10870 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10871 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10872 | |
| 10873 | if (!nl_vendor_reply) |
| 10874 | return NL_SKIP; |
| 10875 | |
| 10876 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 10877 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 10878 | return NL_SKIP; |
| 10879 | } |
| 10880 | |
| 10881 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 10882 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 10883 | } |
| 10884 | |
| 10885 | return NL_SKIP; |
| 10886 | } |
| 10887 | |
| 10888 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10889 | static bool is_cmd_with_nested_attrs(unsigned int vendor_id, |
| 10890 | unsigned int subcmd) |
| 10891 | { |
| 10892 | if (vendor_id != OUI_QCA) |
| 10893 | return true; |
| 10894 | |
| 10895 | switch (subcmd) { |
| 10896 | case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY: |
| 10897 | case QCA_NL80211_VENDOR_SUBCMD_STATS_EXT: |
| 10898 | case QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI: |
| 10899 | case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY: |
| 10900 | case QCA_NL80211_VENDOR_SUBCMD_SPECTRAL_SCAN_GET_STATUS: |
| 10901 | case QCA_NL80211_VENDOR_SUBCMD_NAN: |
| 10902 | return false; |
| 10903 | default: |
| 10904 | return true; |
| 10905 | } |
| 10906 | } |
| 10907 | |
| 10908 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10909 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 10910 | unsigned int subcmd, const u8 *data, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10911 | size_t data_len, enum nested_attr nested_attr, |
| 10912 | struct wpabuf *buf) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10913 | { |
| 10914 | struct i802_bss *bss = priv; |
| 10915 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10916 | struct nl_msg *msg; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10917 | int ret, nla_flag; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10918 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10919 | #ifdef CONFIG_TESTING_OPTIONS |
| 10920 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10921 | msg = nlmsg_alloc(); |
| 10922 | if (!msg) |
| 10923 | return -ENOMEM; |
| 10924 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10925 | nl80211_cmd(drv, msg, 0, subcmd); |
| 10926 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 10927 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10928 | goto fail; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10929 | /* This test vendor_cmd can be used with nl80211 commands that |
| 10930 | * need the connect nl_sock, so use the owner-setting variant |
| 10931 | * of send_and_recv_msgs(). */ |
| 10932 | ret = send_and_recv_msgs_owner(drv, msg, |
| 10933 | get_connect_handle(bss), 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10934 | cmd_reply_handler, buf, |
| 10935 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10936 | if (ret) |
| 10937 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 10938 | ret); |
| 10939 | return ret; |
| 10940 | } |
| 10941 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10942 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10943 | if (nested_attr == NESTED_ATTR_USED) |
| 10944 | nla_flag = NLA_F_NESTED; |
| 10945 | else if (nested_attr == NESTED_ATTR_UNSPECIFIED && |
| 10946 | is_cmd_with_nested_attrs(vendor_id, subcmd)) |
| 10947 | nla_flag = NLA_F_NESTED; |
| 10948 | else |
| 10949 | nla_flag = 0; |
| 10950 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10951 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 10952 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 10953 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 10954 | (data && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10955 | nla_put(msg, nla_flag | NL80211_ATTR_VENDOR_DATA, |
| 10956 | data_len, data))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10957 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10958 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10959 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf, |
| 10960 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10961 | if (ret) |
| 10962 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 10963 | ret); |
| 10964 | return ret; |
| 10965 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10966 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10967 | nlmsg_free(msg); |
| 10968 | return -ENOBUFS; |
| 10969 | } |
| 10970 | |
| 10971 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10972 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 10973 | u8 qos_map_set_len) |
| 10974 | { |
| 10975 | struct i802_bss *bss = priv; |
| 10976 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10977 | struct nl_msg *msg; |
| 10978 | int ret; |
| 10979 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10980 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 10981 | qos_map_set, qos_map_set_len); |
| 10982 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10983 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 10984 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 10985 | nlmsg_free(msg); |
| 10986 | return -ENOBUFS; |
| 10987 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10988 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10989 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10990 | if (ret) |
| 10991 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 10992 | |
| 10993 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10994 | } |
| 10995 | |
| 10996 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10997 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 10998 | { |
| 10999 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11000 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11001 | int *wowlan_enabled = arg; |
| 11002 | |
| 11003 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11004 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11005 | |
| 11006 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 11007 | |
| 11008 | return NL_SKIP; |
| 11009 | } |
| 11010 | |
| 11011 | |
| 11012 | static int nl80211_get_wowlan(void *priv) |
| 11013 | { |
| 11014 | struct i802_bss *bss = priv; |
| 11015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11016 | struct nl_msg *msg; |
| 11017 | int wowlan_enabled; |
| 11018 | int ret; |
| 11019 | |
| 11020 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 11021 | |
| 11022 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 11023 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11024 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled, |
| 11025 | NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11026 | if (ret) { |
| 11027 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 11028 | return 0; |
| 11029 | } |
| 11030 | |
| 11031 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 11032 | wowlan_enabled ? "enabled" : "disabled"); |
| 11033 | |
| 11034 | return wowlan_enabled; |
| 11035 | } |
| 11036 | |
| 11037 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11038 | static int nl80211_set_wowlan(void *priv, |
| 11039 | const struct wowlan_triggers *triggers) |
| 11040 | { |
| 11041 | struct i802_bss *bss = priv; |
| 11042 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11043 | struct nl_msg *msg; |
| 11044 | struct nlattr *wowlan_triggers; |
| 11045 | int ret; |
| 11046 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11047 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 11048 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 11049 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11050 | !(wowlan_triggers = nla_nest_start(msg, |
| 11051 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 11052 | (triggers->any && |
| 11053 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 11054 | (triggers->disconnect && |
| 11055 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 11056 | (triggers->magic_pkt && |
| 11057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 11058 | (triggers->gtk_rekey_failure && |
| 11059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 11060 | (triggers->eap_identity_req && |
| 11061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 11062 | (triggers->four_way_handshake && |
| 11063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 11064 | (triggers->rfkill_release && |
| 11065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 11066 | nlmsg_free(msg); |
| 11067 | return -ENOBUFS; |
| 11068 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11069 | |
| 11070 | nla_nest_end(msg, wowlan_triggers); |
| 11071 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11072 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11073 | if (ret) |
| 11074 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 11075 | |
| 11076 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11077 | } |
| 11078 | |
| 11079 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11080 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11081 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 11082 | { |
| 11083 | struct i802_bss *bss = priv; |
| 11084 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11085 | struct nl_msg *msg; |
| 11086 | struct nlattr *params; |
| 11087 | |
| 11088 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 11089 | |
| 11090 | if (!drv->roaming_vendor_cmd_avail) { |
| 11091 | wpa_printf(MSG_DEBUG, |
| 11092 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 11093 | return -1; |
| 11094 | } |
| 11095 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11096 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11097 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11098 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11099 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 11100 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11101 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 11102 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 11103 | QCA_ROAMING_NOT_ALLOWED) || |
| 11104 | (bssid && |
| 11105 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 11106 | nlmsg_free(msg); |
| 11107 | return -1; |
| 11108 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11109 | nla_nest_end(msg, params); |
| 11110 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11111 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11112 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11113 | |
| 11114 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11115 | static int nl80211_disable_fils(void *priv, int disable) |
| 11116 | { |
| 11117 | struct i802_bss *bss = priv; |
| 11118 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11119 | struct nl_msg *msg; |
| 11120 | struct nlattr *params; |
| 11121 | |
| 11122 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 11123 | |
| 11124 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 11125 | return -1; |
| 11126 | |
| 11127 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11128 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11129 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11130 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 11131 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11132 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 11133 | disable)) { |
| 11134 | nlmsg_free(msg); |
| 11135 | return -1; |
| 11136 | } |
| 11137 | nla_nest_end(msg, params); |
| 11138 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11139 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11140 | } |
| 11141 | |
| 11142 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11143 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 11144 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 11145 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11146 | static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid, |
| 11147 | const u8 *bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11148 | { |
| 11149 | struct i802_bss *bss = priv; |
| 11150 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11151 | struct nl_msg *msg; |
| 11152 | struct nlattr *params, *nlbssids, *attr; |
| 11153 | unsigned int i; |
| 11154 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11155 | wpa_printf(MSG_DEBUG, |
| 11156 | "nl80211: Set temporarily disallowed BSSIDs (num=%u)", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11157 | num_bssid); |
| 11158 | |
| 11159 | if (!drv->roam_vendor_cmd_avail) |
| 11160 | return -1; |
| 11161 | |
| 11162 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11163 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11164 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11165 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 11166 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11167 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11168 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11169 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 11170 | WPA_SUPPLICANT_CLIENT_ID) || |
| 11171 | nla_put_u32(msg, |
| 11172 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 11173 | num_bssid)) |
| 11174 | goto fail; |
| 11175 | |
| 11176 | nlbssids = nla_nest_start( |
| 11177 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 11178 | if (!nlbssids) |
| 11179 | goto fail; |
| 11180 | |
| 11181 | for (i = 0; i < num_bssid; i++) { |
| 11182 | attr = nla_nest_start(msg, i); |
| 11183 | if (!attr) |
| 11184 | goto fail; |
| 11185 | if (nla_put(msg, |
| 11186 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 11187 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 11188 | goto fail; |
| 11189 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 11190 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 11191 | nla_nest_end(msg, attr); |
| 11192 | } |
| 11193 | nla_nest_end(msg, nlbssids); |
| 11194 | nla_nest_end(msg, params); |
| 11195 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11196 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11197 | |
| 11198 | fail: |
| 11199 | nlmsg_free(msg); |
| 11200 | return -1; |
| 11201 | } |
| 11202 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11203 | |
| 11204 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 11205 | { |
| 11206 | struct i802_bss *bss = priv; |
| 11207 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11208 | struct nl_msg *msg; |
| 11209 | struct nlattr *params; |
| 11210 | |
| 11211 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 11212 | return -EOPNOTSUPP; |
| 11213 | |
| 11214 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 11215 | |
| 11216 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11217 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11218 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11219 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 11220 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11221 | (addr && |
| 11222 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 11223 | addr)) || |
| 11224 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 11225 | auth_alg)) { |
| 11226 | nlmsg_free(msg); |
| 11227 | wpa_printf(MSG_ERROR, |
| 11228 | "%s: err in adding vendor_cmd and vendor_data", |
| 11229 | __func__); |
| 11230 | return -1; |
| 11231 | } |
| 11232 | nla_nest_end(msg, params); |
| 11233 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11234 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11235 | } |
| 11236 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11237 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11238 | |
| 11239 | |
| 11240 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 11241 | { |
| 11242 | struct i802_bss *bss = priv; |
| 11243 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11244 | int new_addr = addr != NULL; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11245 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11246 | struct nl_msg *msg; |
| 11247 | struct nlattr *params; |
| 11248 | int ret; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11249 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11250 | wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11251 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11252 | if (TEST_FAIL()) |
| 11253 | return -1; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11254 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11255 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11256 | if (!addr ) { |
| 11257 | addr = drv->global->p2p_perm_addr; |
| 11258 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11259 | |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11260 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 11261 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 11262 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11263 | BRCM_VENDOR_SCMD_SET_MAC) || |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11264 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11265 | nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) { |
| 11266 | wpa_printf(MSG_ERROR, "failed to put p2p randmac"); |
| 11267 | nl80211_nlmsg_clear(msg); |
| 11268 | nlmsg_free(msg); |
| 11269 | return -ENOBUFS; |
| 11270 | } |
| 11271 | nla_nest_end(msg, params); |
| 11272 | |
| 11273 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 11274 | if (ret) { |
| 11275 | wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)", |
| 11276 | ret, strerror(-ret)); |
| 11277 | } |
| 11278 | memcpy(bss->addr, addr, ETH_ALEN); |
| 11279 | return ret; |
| 11280 | #else |
| 11281 | return -ENOTSUP; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11282 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11283 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11284 | if (!addr) |
| 11285 | addr = drv->perm_addr; |
| 11286 | |
| 11287 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 11288 | return -1; |
| 11289 | |
| 11290 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 11291 | { |
| 11292 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11293 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 11294 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11295 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11296 | 1) < 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11297 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11298 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11299 | } |
| 11300 | return -1; |
| 11301 | } |
| 11302 | |
| 11303 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11304 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11305 | drv->addr_changed = new_addr; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 11306 | os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11307 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 11308 | |
| 11309 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 11310 | { |
| 11311 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11312 | "nl80211: Could not restore interface UP after set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11313 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11314 | return 0; |
| 11315 | } |
| 11316 | |
| 11317 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11318 | #ifdef CONFIG_MESH |
| 11319 | |
| 11320 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 11321 | { |
| 11322 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 11323 | wpa_printf(MSG_INFO, |
| 11324 | "nl80211: Failed to set interface into mesh mode"); |
| 11325 | return -1; |
| 11326 | } |
| 11327 | return 0; |
| 11328 | } |
| 11329 | |
| 11330 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11331 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 11332 | size_t mesh_id_len) |
| 11333 | { |
| 11334 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11335 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 11336 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11337 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 11338 | } |
| 11339 | |
| 11340 | return 0; |
| 11341 | } |
| 11342 | |
| 11343 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11344 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 11345 | struct wpa_driver_mesh_bss_params *params) |
| 11346 | { |
| 11347 | struct nlattr *container; |
| 11348 | |
| 11349 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 11350 | if (!container) |
| 11351 | return -1; |
| 11352 | |
| 11353 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11354 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 11355 | params->auto_plinks)) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11356 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) && |
| 11357 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 11358 | params->forwarding)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11359 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 11360 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11361 | params->max_peer_links)) || |
| 11362 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 11363 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 11364 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11365 | return -1; |
| 11366 | |
| 11367 | /* |
| 11368 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 11369 | * the timer could disconnect stations even in that case. |
| 11370 | */ |
| 11371 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 11372 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 11373 | params->peer_link_timeout)) { |
| 11374 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 11375 | return -1; |
| 11376 | } |
| 11377 | |
| 11378 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 11379 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 11380 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 11381 | return -1; |
| 11382 | } |
| 11383 | |
| 11384 | nla_nest_end(msg, container); |
| 11385 | |
| 11386 | return 0; |
| 11387 | } |
| 11388 | |
| 11389 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11390 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11391 | struct wpa_driver_mesh_join_params *params) |
| 11392 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11393 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11394 | struct nl_msg *msg; |
| 11395 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 11396 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11397 | |
| 11398 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 11399 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11400 | if (!msg || |
| 11401 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 11402 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 11403 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11404 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 11405 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11406 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11407 | |
| 11408 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 11409 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11410 | if (params->handle_dfs && nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS)) |
| 11411 | goto fail; |
| 11412 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11413 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 11414 | if (!container) |
| 11415 | goto fail; |
| 11416 | |
| 11417 | if (params->ies) { |
| 11418 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 11419 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 11420 | params->ies)) |
| 11421 | goto fail; |
| 11422 | } |
| 11423 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 11424 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 11425 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 11426 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 11427 | goto fail; |
| 11428 | } |
| 11429 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 11430 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 11431 | goto fail; |
| 11432 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 11433 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 11434 | goto fail; |
| 11435 | nla_nest_end(msg, container); |
| 11436 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11437 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 11438 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 11439 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 11440 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11441 | goto fail; |
| 11442 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11443 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11444 | msg = NULL; |
| 11445 | if (ret) { |
| 11446 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 11447 | ret, strerror(-ret)); |
| 11448 | goto fail; |
| 11449 | } |
| 11450 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11451 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11452 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 11453 | |
| 11454 | fail: |
| 11455 | nlmsg_free(msg); |
| 11456 | return ret; |
| 11457 | } |
| 11458 | |
| 11459 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11460 | static int |
| 11461 | wpa_driver_nl80211_join_mesh(void *priv, |
| 11462 | struct wpa_driver_mesh_join_params *params) |
| 11463 | { |
| 11464 | struct i802_bss *bss = priv; |
| 11465 | int ret, timeout; |
| 11466 | |
| 11467 | timeout = params->conf.peer_link_timeout; |
| 11468 | |
| 11469 | /* Disable kernel inactivity timer */ |
| 11470 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 11471 | params->conf.peer_link_timeout = 0; |
| 11472 | |
| 11473 | ret = nl80211_join_mesh(bss, params); |
| 11474 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 11475 | wpa_printf(MSG_DEBUG, |
| 11476 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 11477 | /* |
| 11478 | * Old kernel does not support setting |
| 11479 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 11480 | * into future from peer_link_timeout. |
| 11481 | */ |
| 11482 | params->conf.peer_link_timeout = timeout + 60; |
| 11483 | ret = nl80211_join_mesh(priv, params); |
| 11484 | } |
| 11485 | |
| 11486 | params->conf.peer_link_timeout = timeout; |
| 11487 | return ret; |
| 11488 | } |
| 11489 | |
| 11490 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11491 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 11492 | { |
| 11493 | struct i802_bss *bss = priv; |
| 11494 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11495 | struct nl_msg *msg; |
| 11496 | int ret; |
| 11497 | |
| 11498 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 11499 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11500 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11501 | if (ret) { |
| 11502 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 11503 | ret, strerror(-ret)); |
| 11504 | } else { |
| 11505 | wpa_printf(MSG_DEBUG, |
| 11506 | "nl80211: mesh leave request send successfully"); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11507 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11508 | } |
| 11509 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11510 | if (drv->start_mode_sta && |
| 11511 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11512 | NL80211_IFTYPE_STATION)) { |
| 11513 | wpa_printf(MSG_INFO, |
| 11514 | "nl80211: Failed to set interface into station mode"); |
| 11515 | } |
| 11516 | return ret; |
| 11517 | } |
| 11518 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11519 | |
| 11520 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 11521 | size_t len) |
| 11522 | { |
| 11523 | struct i802_bss *bss = priv; |
| 11524 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11525 | struct nl_msg *msg; |
| 11526 | int ret; |
| 11527 | |
| 11528 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 11529 | if (!msg || |
| 11530 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11531 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 11532 | nlmsg_free(msg); |
| 11533 | return -ENOBUFS; |
| 11534 | } |
| 11535 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11536 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11537 | if (ret) { |
| 11538 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 11539 | " failed: ret=%d (%s)", |
| 11540 | MAC2STR(addr), ret, strerror(-ret)); |
| 11541 | } else { |
| 11542 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 11543 | " probed successfully", MAC2STR(addr)); |
| 11544 | } |
| 11545 | |
| 11546 | return ret; |
| 11547 | } |
| 11548 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11549 | #endif /* CONFIG_MESH */ |
| 11550 | |
| 11551 | |
| 11552 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 11553 | const u8 *ipaddr, int prefixlen, |
| 11554 | const u8 *addr) |
| 11555 | { |
| 11556 | #ifdef CONFIG_LIBNL3_ROUTE |
| 11557 | struct i802_bss *bss = priv; |
| 11558 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11559 | struct rtnl_neigh *rn; |
| 11560 | struct nl_addr *nl_ipaddr = NULL; |
| 11561 | struct nl_addr *nl_lladdr = NULL; |
| 11562 | int family, addrsize; |
| 11563 | int res; |
| 11564 | |
| 11565 | if (!ipaddr || prefixlen == 0 || !addr) |
| 11566 | return -EINVAL; |
| 11567 | |
| 11568 | if (bss->br_ifindex == 0) { |
| 11569 | wpa_printf(MSG_DEBUG, |
| 11570 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 11571 | return -1; |
| 11572 | } |
| 11573 | |
| 11574 | if (!drv->rtnl_sk) { |
| 11575 | wpa_printf(MSG_DEBUG, |
| 11576 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 11577 | return -1; |
| 11578 | } |
| 11579 | |
| 11580 | if (version == 4) { |
| 11581 | family = AF_INET; |
| 11582 | addrsize = 4; |
| 11583 | } else if (version == 6) { |
| 11584 | family = AF_INET6; |
| 11585 | addrsize = 16; |
| 11586 | } else { |
| 11587 | return -EINVAL; |
| 11588 | } |
| 11589 | |
| 11590 | rn = rtnl_neigh_alloc(); |
| 11591 | if (rn == NULL) |
| 11592 | return -ENOMEM; |
| 11593 | |
| 11594 | /* set the destination ip address for neigh */ |
| 11595 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 11596 | if (nl_ipaddr == NULL) { |
| 11597 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 11598 | res = -ENOMEM; |
| 11599 | goto errout; |
| 11600 | } |
| 11601 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 11602 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 11603 | if (res) { |
| 11604 | wpa_printf(MSG_DEBUG, |
| 11605 | "nl80211: neigh set destination addr failed"); |
| 11606 | goto errout; |
| 11607 | } |
| 11608 | |
| 11609 | /* set the corresponding lladdr for neigh */ |
| 11610 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 11611 | if (nl_lladdr == NULL) { |
| 11612 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 11613 | res = -ENOMEM; |
| 11614 | goto errout; |
| 11615 | } |
| 11616 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 11617 | |
| 11618 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 11619 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 11620 | |
| 11621 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 11622 | if (res) { |
| 11623 | wpa_printf(MSG_DEBUG, |
| 11624 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11625 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11626 | } |
| 11627 | errout: |
| 11628 | if (nl_lladdr) |
| 11629 | nl_addr_put(nl_lladdr); |
| 11630 | if (nl_ipaddr) |
| 11631 | nl_addr_put(nl_ipaddr); |
| 11632 | if (rn) |
| 11633 | rtnl_neigh_put(rn); |
| 11634 | return res; |
| 11635 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 11636 | return -1; |
| 11637 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 11638 | } |
| 11639 | |
| 11640 | |
| 11641 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 11642 | const u8 *ipaddr) |
| 11643 | { |
| 11644 | #ifdef CONFIG_LIBNL3_ROUTE |
| 11645 | struct i802_bss *bss = priv; |
| 11646 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11647 | struct rtnl_neigh *rn; |
| 11648 | struct nl_addr *nl_ipaddr; |
| 11649 | int family, addrsize; |
| 11650 | int res; |
| 11651 | |
| 11652 | if (!ipaddr) |
| 11653 | return -EINVAL; |
| 11654 | |
| 11655 | if (version == 4) { |
| 11656 | family = AF_INET; |
| 11657 | addrsize = 4; |
| 11658 | } else if (version == 6) { |
| 11659 | family = AF_INET6; |
| 11660 | addrsize = 16; |
| 11661 | } else { |
| 11662 | return -EINVAL; |
| 11663 | } |
| 11664 | |
| 11665 | if (bss->br_ifindex == 0) { |
| 11666 | wpa_printf(MSG_DEBUG, |
| 11667 | "nl80211: bridge must be set to delete an ip neigh"); |
| 11668 | return -1; |
| 11669 | } |
| 11670 | |
| 11671 | if (!drv->rtnl_sk) { |
| 11672 | wpa_printf(MSG_DEBUG, |
| 11673 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 11674 | return -1; |
| 11675 | } |
| 11676 | |
| 11677 | rn = rtnl_neigh_alloc(); |
| 11678 | if (rn == NULL) |
| 11679 | return -ENOMEM; |
| 11680 | |
| 11681 | /* set the destination ip address for neigh */ |
| 11682 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 11683 | if (nl_ipaddr == NULL) { |
| 11684 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 11685 | res = -ENOMEM; |
| 11686 | goto errout; |
| 11687 | } |
| 11688 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 11689 | if (res) { |
| 11690 | wpa_printf(MSG_DEBUG, |
| 11691 | "nl80211: neigh set destination addr failed"); |
| 11692 | goto errout; |
| 11693 | } |
| 11694 | |
| 11695 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 11696 | |
| 11697 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 11698 | if (res) { |
| 11699 | wpa_printf(MSG_DEBUG, |
| 11700 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11701 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11702 | } |
| 11703 | errout: |
| 11704 | if (nl_ipaddr) |
| 11705 | nl_addr_put(nl_ipaddr); |
| 11706 | if (rn) |
| 11707 | rtnl_neigh_put(rn); |
| 11708 | return res; |
| 11709 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 11710 | return -1; |
| 11711 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 11712 | } |
| 11713 | |
| 11714 | |
| 11715 | static int linux_write_system_file(const char *path, unsigned int val) |
| 11716 | { |
| 11717 | char buf[50]; |
| 11718 | int fd, len; |
| 11719 | |
| 11720 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 11721 | if (os_snprintf_error(sizeof(buf), len)) |
| 11722 | return -1; |
| 11723 | |
| 11724 | fd = open(path, O_WRONLY); |
| 11725 | if (fd < 0) |
| 11726 | return -1; |
| 11727 | |
| 11728 | if (write(fd, buf, len) < 0) { |
| 11729 | wpa_printf(MSG_DEBUG, |
| 11730 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 11731 | path, val); |
| 11732 | close(fd); |
| 11733 | return -1; |
| 11734 | } |
| 11735 | close(fd); |
| 11736 | |
| 11737 | return 0; |
| 11738 | } |
| 11739 | |
| 11740 | |
| 11741 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 11742 | { |
| 11743 | switch (attr) { |
| 11744 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 11745 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11746 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 11747 | return "hairpin_mode"; |
| 11748 | } |
| 11749 | |
| 11750 | return NULL; |
| 11751 | } |
| 11752 | |
| 11753 | |
| 11754 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 11755 | unsigned int val) |
| 11756 | { |
| 11757 | struct i802_bss *bss = priv; |
| 11758 | char path[128]; |
| 11759 | const char *attr_txt; |
| 11760 | |
| 11761 | attr_txt = drv_br_port_attr_str(attr); |
| 11762 | if (attr_txt == NULL) |
| 11763 | return -EINVAL; |
| 11764 | |
| 11765 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 11766 | bss->ifname, attr_txt); |
| 11767 | |
| 11768 | if (linux_write_system_file(path, val)) |
| 11769 | return -1; |
| 11770 | |
| 11771 | return 0; |
| 11772 | } |
| 11773 | |
| 11774 | |
| 11775 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 11776 | { |
| 11777 | switch (param) { |
| 11778 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11779 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11780 | default: |
| 11781 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11782 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11783 | } |
| 11784 | |
| 11785 | |
| 11786 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 11787 | unsigned int val) |
| 11788 | { |
| 11789 | struct i802_bss *bss = priv; |
| 11790 | char path[128]; |
| 11791 | const char *param_txt; |
| 11792 | int ip_version = 4; |
| 11793 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11794 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 11795 | os_snprintf(path, sizeof(path), |
| 11796 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 11797 | bss->brname); |
| 11798 | goto set_val; |
| 11799 | } |
| 11800 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11801 | param_txt = drv_br_net_param_str(param); |
| 11802 | if (param_txt == NULL) |
| 11803 | return -EINVAL; |
| 11804 | |
| 11805 | switch (param) { |
| 11806 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11807 | ip_version = 4; |
| 11808 | break; |
| 11809 | default: |
| 11810 | return -EINVAL; |
| 11811 | } |
| 11812 | |
| 11813 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 11814 | ip_version, bss->brname, param_txt); |
| 11815 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11816 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11817 | if (linux_write_system_file(path, val)) |
| 11818 | return -1; |
| 11819 | |
| 11820 | return 0; |
| 11821 | } |
| 11822 | |
| 11823 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11824 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 11825 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11826 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 11827 | { |
| 11828 | switch (hw_mode) { |
| 11829 | case HOSTAPD_MODE_IEEE80211B: |
| 11830 | return QCA_ACS_MODE_IEEE80211B; |
| 11831 | case HOSTAPD_MODE_IEEE80211G: |
| 11832 | return QCA_ACS_MODE_IEEE80211G; |
| 11833 | case HOSTAPD_MODE_IEEE80211A: |
| 11834 | return QCA_ACS_MODE_IEEE80211A; |
| 11835 | case HOSTAPD_MODE_IEEE80211AD: |
| 11836 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 11837 | case HOSTAPD_MODE_IEEE80211ANY: |
| 11838 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11839 | default: |
| 11840 | return -1; |
| 11841 | } |
| 11842 | } |
| 11843 | |
| 11844 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11845 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 11846 | { |
| 11847 | int num_channels = 0, num_freqs; |
| 11848 | u8 *ch_list; |
| 11849 | enum hostapd_hw_mode hw_mode; |
| 11850 | int ret = 0; |
| 11851 | int i; |
| 11852 | |
| 11853 | if (!freq_list) |
| 11854 | return 0; |
| 11855 | |
| 11856 | num_freqs = int_array_len(freq_list); |
| 11857 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 11858 | if (!ch_list) |
| 11859 | return -1; |
| 11860 | |
| 11861 | for (i = 0; i < num_freqs; i++) { |
| 11862 | const int freq = freq_list[i]; |
| 11863 | |
| 11864 | if (freq == 0) |
| 11865 | break; |
| 11866 | /* Send 2.4 GHz and 5 GHz channels with |
| 11867 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 11868 | * compatibility. |
| 11869 | */ |
| 11870 | if (!(freq >= 2412 && freq <= 2484) && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11871 | !(freq >= 5180 && freq <= 5900) && |
| 11872 | !(freq >= 5945 && freq <= 7115)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11873 | continue; |
| 11874 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 11875 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 11876 | num_channels++; |
| 11877 | } |
| 11878 | |
| 11879 | if (num_channels) |
| 11880 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 11881 | num_channels, ch_list); |
| 11882 | |
| 11883 | os_free(ch_list); |
| 11884 | return ret; |
| 11885 | } |
| 11886 | |
| 11887 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11888 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 11889 | { |
| 11890 | int i, len, ret; |
| 11891 | u32 *freqs; |
| 11892 | |
| 11893 | if (!freq_list) |
| 11894 | return 0; |
| 11895 | len = int_array_len(freq_list); |
| 11896 | freqs = os_malloc(sizeof(u32) * len); |
| 11897 | if (!freqs) |
| 11898 | return -1; |
| 11899 | for (i = 0; i < len; i++) |
| 11900 | freqs[i] = freq_list[i]; |
| 11901 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 11902 | sizeof(u32) * len, freqs); |
| 11903 | os_free(freqs); |
| 11904 | return ret; |
| 11905 | } |
| 11906 | |
| 11907 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11908 | static int nl80211_qca_do_acs(struct wpa_driver_nl80211_data *drv, |
| 11909 | struct drv_acs_params *params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11910 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11911 | struct nl_msg *msg; |
| 11912 | struct nlattr *data; |
| 11913 | int ret; |
| 11914 | int mode; |
| 11915 | |
| 11916 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 11917 | if (mode < 0) |
| 11918 | return -1; |
| 11919 | |
| 11920 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11921 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11922 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11923 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 11924 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11925 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 11926 | (params->ht_enabled && |
| 11927 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 11928 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11929 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 11930 | (params->vht_enabled && |
| 11931 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11932 | (params->eht_enabled && |
| 11933 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EHT_ENABLED)) || |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11934 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 11935 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11936 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11937 | add_acs_freq_list(msg, params->freq_list) || |
| 11938 | (params->edmg_enabled && |
| 11939 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11940 | nlmsg_free(msg); |
| 11941 | return -ENOBUFS; |
| 11942 | } |
| 11943 | nla_nest_end(msg, data); |
| 11944 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11945 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11946 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d EHT: %d BW: %d EDMG: %d", |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11947 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11948 | params->vht_enabled, params->eht_enabled, params->ch_width, |
| 11949 | params->edmg_enabled); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11950 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11951 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11952 | if (ret) { |
| 11953 | wpa_printf(MSG_DEBUG, |
| 11954 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11955 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11956 | } |
| 11957 | return ret; |
| 11958 | } |
| 11959 | |
| 11960 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11961 | static int nl80211_set_band(void *priv, u32 band_mask) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11962 | { |
| 11963 | struct i802_bss *bss = priv; |
| 11964 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11965 | struct nl_msg *msg; |
| 11966 | struct nlattr *data; |
| 11967 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11968 | enum qca_set_band qca_band_value; |
| 11969 | u32 qca_band_mask = QCA_SETBAND_AUTO; |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11970 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11971 | if (!drv->setband_vendor_cmd_avail || |
| 11972 | (band_mask > (WPA_SETBAND_2G | WPA_SETBAND_5G | WPA_SETBAND_6G))) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11973 | return -1; |
| 11974 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11975 | if (band_mask & WPA_SETBAND_5G) |
| 11976 | qca_band_mask |= QCA_SETBAND_5G; |
| 11977 | if (band_mask & WPA_SETBAND_2G) |
| 11978 | qca_band_mask |= QCA_SETBAND_2G; |
| 11979 | if (band_mask & WPA_SETBAND_6G) |
| 11980 | qca_band_mask |= QCA_SETBAND_6G; |
| 11981 | |
| 11982 | /* |
| 11983 | * QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE is a legacy interface hence make |
| 11984 | * it suite to its values (AUTO/5G/2G) for backwards compatibility. |
| 11985 | */ |
| 11986 | qca_band_value = ((qca_band_mask & QCA_SETBAND_5G) && |
| 11987 | (qca_band_mask & QCA_SETBAND_2G)) ? |
| 11988 | QCA_SETBAND_AUTO : |
| 11989 | qca_band_mask & ~QCA_SETBAND_6G; |
| 11990 | |
| 11991 | wpa_printf(MSG_DEBUG, |
| 11992 | "nl80211: QCA_BAND_MASK = 0x%x, QCA_BAND_VALUE = %d", |
| 11993 | qca_band_mask, qca_band_value); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11994 | |
| 11995 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11996 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11997 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11998 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 11999 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12000 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, |
| 12001 | qca_band_value) || |
| 12002 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_MASK, |
| 12003 | qca_band_mask)) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12004 | nlmsg_free(msg); |
| 12005 | return -ENOBUFS; |
| 12006 | } |
| 12007 | nla_nest_end(msg, data); |
| 12008 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12009 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12010 | if (ret) { |
| 12011 | wpa_printf(MSG_DEBUG, |
| 12012 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12013 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12014 | } |
| 12015 | return ret; |
| 12016 | } |
| 12017 | |
| 12018 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12019 | struct nl80211_pcl { |
| 12020 | unsigned int num; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12021 | struct weighted_pcl *freq_list; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12022 | }; |
| 12023 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12024 | static void get_pcl_attr_values(struct weighted_pcl *wpcl, struct nlattr *nl[]) |
| 12025 | { |
| 12026 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]) |
| 12027 | wpcl->freq = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]); |
| 12028 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]) |
| 12029 | wpcl->weight = nla_get_u8(nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]); |
| 12030 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]) { |
| 12031 | u32 flags = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]); |
| 12032 | |
| 12033 | wpcl->flag = 0; |
| 12034 | if (flags & BIT(0)) |
| 12035 | wpcl->flag |= WEIGHTED_PCL_GO; |
| 12036 | if (flags & BIT(1)) |
| 12037 | wpcl->flag |= WEIGHTED_PCL_CLI; |
| 12038 | if (flags & BIT(2)) |
| 12039 | wpcl->flag |= WEIGHTED_PCL_MUST_CONSIDER; |
| 12040 | if (flags & BIT(3)) |
| 12041 | wpcl->flag |= WEIGHTED_PCL_EXCLUDE; |
| 12042 | } else { |
| 12043 | wpcl->flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 12044 | } |
| 12045 | } |
| 12046 | |
| 12047 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12048 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 12049 | { |
| 12050 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 12051 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 12052 | struct nl80211_pcl *param = arg; |
| 12053 | struct nlattr *nl_vend, *attr; |
| 12054 | enum qca_iface_type iface_type; |
| 12055 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12056 | struct nlattr *nl_pcl[QCA_WLAN_VENDOR_ATTR_PCL_MAX + 1]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12057 | unsigned int num, max_num; |
| 12058 | u32 *freqs; |
| 12059 | |
| 12060 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 12061 | genlmsg_attrlen(gnlh, 0), NULL); |
| 12062 | |
| 12063 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 12064 | if (!nl_vend) |
| 12065 | return NL_SKIP; |
| 12066 | |
| 12067 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 12068 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 12069 | |
| 12070 | attr = tb_vendor[ |
| 12071 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 12072 | if (!attr) { |
| 12073 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 12074 | param->num = 0; |
| 12075 | return NL_SKIP; |
| 12076 | } |
| 12077 | |
| 12078 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 12079 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 12080 | iface_type); |
| 12081 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12082 | attr = tb_vendor[ |
| 12083 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_WEIGHED_PCL]; |
| 12084 | if (attr) { |
| 12085 | int rem; |
| 12086 | struct nlattr *wpcl = attr; |
| 12087 | unsigned int i; |
| 12088 | |
| 12089 | num = 0; |
| 12090 | nla_for_each_nested(attr, wpcl, rem) { |
| 12091 | if (num == param->num) |
| 12092 | break; /* not enough room for all entries */ |
| 12093 | if (nla_parse(nl_pcl, QCA_WLAN_VENDOR_ATTR_PCL_MAX, |
| 12094 | nla_data(attr), nla_len(attr), NULL)) { |
| 12095 | wpa_printf(MSG_ERROR, |
| 12096 | "nl80211: Failed to parse PCL info"); |
| 12097 | param->num = 0; |
| 12098 | return NL_SKIP; |
| 12099 | } |
| 12100 | get_pcl_attr_values(¶m->freq_list[num], nl_pcl); |
| 12101 | num++; |
| 12102 | } |
| 12103 | param->num = num; |
| 12104 | |
| 12105 | /* Sort frequencies based on their weight */ |
| 12106 | for (i = 0; i < num; i++) { |
| 12107 | unsigned int j; |
| 12108 | |
| 12109 | for (j = i + 1; j < num; j++) { |
| 12110 | if (param->freq_list[i].weight < |
| 12111 | param->freq_list[j].weight) { |
| 12112 | struct weighted_pcl tmp; |
| 12113 | |
| 12114 | tmp = param->freq_list[i]; |
| 12115 | param->freq_list[i] = |
| 12116 | param->freq_list[j]; |
| 12117 | param->freq_list[j] = tmp; |
| 12118 | } |
| 12119 | } |
| 12120 | } |
| 12121 | } else if (tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]) { |
| 12122 | wpa_printf(MSG_DEBUG, |
| 12123 | "nl80211: Driver does not provide weighted PCL; use the non-weighted variant"); |
| 12124 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 12125 | /* |
| 12126 | * param->num has the maximum number of entries for which there |
| 12127 | * is room in the freq_list provided by the caller. |
| 12128 | */ |
| 12129 | freqs = nla_data(attr); |
| 12130 | max_num = nla_len(attr) / sizeof(u32); |
| 12131 | if (max_num > param->num) |
| 12132 | max_num = param->num; |
| 12133 | for (num = 0; num < max_num; num++) { |
| 12134 | param->freq_list[num].freq = freqs[num]; |
| 12135 | param->freq_list[num].flag = |
| 12136 | WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 12137 | } |
| 12138 | param->num = num; |
| 12139 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12140 | wpa_printf(MSG_ERROR, |
| 12141 | "nl80211: preferred_freq_list couldn't be found"); |
| 12142 | param->num = 0; |
| 12143 | return NL_SKIP; |
| 12144 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12145 | return NL_SKIP; |
| 12146 | } |
| 12147 | |
| 12148 | |
| 12149 | static int nl80211_get_pref_freq_list(void *priv, |
| 12150 | enum wpa_driver_if_type if_type, |
| 12151 | unsigned int *num, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12152 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12153 | { |
| 12154 | struct i802_bss *bss = priv; |
| 12155 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12156 | struct nl_msg *msg; |
| 12157 | int ret; |
| 12158 | unsigned int i; |
| 12159 | struct nlattr *params; |
| 12160 | struct nl80211_pcl param; |
| 12161 | enum qca_iface_type iface_type; |
| 12162 | |
| 12163 | if (!drv->get_pref_freq_list) |
| 12164 | return -1; |
| 12165 | |
| 12166 | switch (if_type) { |
| 12167 | case WPA_IF_STATION: |
| 12168 | iface_type = QCA_IFACE_TYPE_STA; |
| 12169 | break; |
| 12170 | case WPA_IF_AP_BSS: |
| 12171 | iface_type = QCA_IFACE_TYPE_AP; |
| 12172 | break; |
| 12173 | case WPA_IF_P2P_GO: |
| 12174 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 12175 | break; |
| 12176 | case WPA_IF_P2P_CLIENT: |
| 12177 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 12178 | break; |
| 12179 | case WPA_IF_IBSS: |
| 12180 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 12181 | break; |
| 12182 | case WPA_IF_TDLS: |
| 12183 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 12184 | break; |
| 12185 | default: |
| 12186 | return -1; |
| 12187 | } |
| 12188 | |
| 12189 | param.num = *num; |
| 12190 | param.freq_list = freq_list; |
| 12191 | |
| 12192 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 12194 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12195 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12196 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 12197 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12198 | nla_put_u32(msg, |
| 12199 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 12200 | iface_type)) { |
| 12201 | wpa_printf(MSG_ERROR, |
| 12202 | "%s: err in adding vendor_cmd and vendor_data", |
| 12203 | __func__); |
| 12204 | nlmsg_free(msg); |
| 12205 | return -1; |
| 12206 | } |
| 12207 | nla_nest_end(msg, params); |
| 12208 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12209 | if (freq_list) |
| 12210 | os_memset(freq_list, 0, *num * sizeof(struct weighted_pcl)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12211 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m, |
| 12212 | NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12213 | if (ret) { |
| 12214 | wpa_printf(MSG_ERROR, |
| 12215 | "%s: err in send_and_recv_msgs", __func__); |
| 12216 | return ret; |
| 12217 | } |
| 12218 | |
| 12219 | *num = param.num; |
| 12220 | |
| 12221 | for (i = 0; i < *num; i++) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 12222 | wpa_printf(MSG_DEBUG, |
| 12223 | "nl80211: preferred_channel_list[%d]=%d[%d]:0x%x", |
| 12224 | i, freq_list[i].freq, freq_list[i].weight, |
| 12225 | freq_list[i].flag); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12226 | } |
| 12227 | |
| 12228 | return 0; |
| 12229 | } |
| 12230 | |
| 12231 | |
| 12232 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 12233 | { |
| 12234 | struct i802_bss *bss = priv; |
| 12235 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12236 | struct nl_msg *msg; |
| 12237 | int ret; |
| 12238 | struct nlattr *params; |
| 12239 | |
| 12240 | if (!drv->set_prob_oper_freq) |
| 12241 | return -1; |
| 12242 | |
| 12243 | wpa_printf(MSG_DEBUG, |
| 12244 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 12245 | freq, bss->ifindex); |
| 12246 | |
| 12247 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12248 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12249 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12250 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 12251 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12252 | nla_put_u32(msg, |
| 12253 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 12254 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 12255 | nla_put_u32(msg, |
| 12256 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 12257 | freq)) { |
| 12258 | wpa_printf(MSG_ERROR, |
| 12259 | "%s: err in adding vendor_cmd and vendor_data", |
| 12260 | __func__); |
| 12261 | nlmsg_free(msg); |
| 12262 | return -1; |
| 12263 | } |
| 12264 | nla_nest_end(msg, params); |
| 12265 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12266 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12267 | msg = NULL; |
| 12268 | if (ret) { |
| 12269 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 12270 | __func__); |
| 12271 | return ret; |
| 12272 | } |
| 12273 | nlmsg_free(msg); |
| 12274 | return 0; |
| 12275 | } |
| 12276 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12277 | |
| 12278 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 12279 | unsigned int period, unsigned int interval, |
| 12280 | unsigned int count, const u8 *device_types, |
| 12281 | size_t dev_types_len, |
| 12282 | const u8 *ies, size_t ies_len) |
| 12283 | { |
| 12284 | struct i802_bss *bss = priv; |
| 12285 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12286 | struct nl_msg *msg; |
| 12287 | struct nlattr *container; |
| 12288 | int ret; |
| 12289 | |
| 12290 | wpa_printf(MSG_DEBUG, |
| 12291 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 12292 | freq, period, interval, count); |
| 12293 | |
| 12294 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 12295 | return -1; |
| 12296 | |
| 12297 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12298 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12299 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12300 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 12301 | goto fail; |
| 12302 | |
| 12303 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12304 | if (!container) |
| 12305 | goto fail; |
| 12306 | |
| 12307 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 12308 | freq) || |
| 12309 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 12310 | period) || |
| 12311 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 12312 | interval) || |
| 12313 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 12314 | count) || |
| 12315 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 12316 | dev_types_len, device_types) || |
| 12317 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 12318 | ies_len, ies)) |
| 12319 | goto fail; |
| 12320 | |
| 12321 | nla_nest_end(msg, container); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12322 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12323 | msg = NULL; |
| 12324 | if (ret) { |
| 12325 | wpa_printf(MSG_DEBUG, |
| 12326 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 12327 | goto fail; |
| 12328 | } |
| 12329 | |
| 12330 | return 0; |
| 12331 | |
| 12332 | fail: |
| 12333 | nlmsg_free(msg); |
| 12334 | return -1; |
| 12335 | } |
| 12336 | |
| 12337 | |
| 12338 | static int nl80211_p2p_lo_stop(void *priv) |
| 12339 | { |
| 12340 | struct i802_bss *bss = priv; |
| 12341 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12342 | struct nl_msg *msg; |
| 12343 | |
| 12344 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 12345 | |
| 12346 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 12347 | return -1; |
| 12348 | |
| 12349 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12350 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12351 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12352 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 12353 | nlmsg_free(msg); |
| 12354 | return -1; |
| 12355 | } |
| 12356 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12357 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12358 | } |
| 12359 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 12360 | |
| 12361 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 12362 | { |
| 12363 | struct i802_bss *bss = priv; |
| 12364 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12365 | struct nl_msg *msg; |
| 12366 | struct nlattr *params; |
| 12367 | int ret; |
| 12368 | u32 tdls_mode; |
| 12369 | |
| 12370 | wpa_printf(MSG_DEBUG, |
| 12371 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 12372 | tdls_external_control); |
| 12373 | |
| 12374 | if (tdls_external_control == 1) |
| 12375 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 12376 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 12377 | else |
| 12378 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 12379 | |
| 12380 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12381 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12382 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12383 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 12384 | goto fail; |
| 12385 | |
| 12386 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12387 | if (!params) |
| 12388 | goto fail; |
| 12389 | |
| 12390 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 12391 | tdls_mode)) |
| 12392 | goto fail; |
| 12393 | |
| 12394 | nla_nest_end(msg, params); |
| 12395 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12396 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 12397 | msg = NULL; |
| 12398 | if (ret) { |
| 12399 | wpa_printf(MSG_ERROR, |
| 12400 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 12401 | ret, strerror(-ret)); |
| 12402 | goto fail; |
| 12403 | } |
| 12404 | return 0; |
| 12405 | fail: |
| 12406 | nlmsg_free(msg); |
| 12407 | return -1; |
| 12408 | } |
| 12409 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12410 | |
| 12411 | #ifdef CONFIG_MBO |
| 12412 | |
| 12413 | static enum mbo_transition_reject_reason |
| 12414 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 12415 | { |
| 12416 | switch (status) { |
| 12417 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 12418 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 12419 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 12420 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 12421 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 12422 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 12423 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 12424 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 12425 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 12426 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 12427 | case QCA_STATUS_REJECT_UNKNOWN: |
| 12428 | default: |
| 12429 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 12430 | } |
| 12431 | } |
| 12432 | |
| 12433 | |
| 12434 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 12435 | struct nlattr *tb[], int num) |
| 12436 | { |
| 12437 | enum qca_wlan_btm_candidate_status status; |
| 12438 | char buf[50]; |
| 12439 | |
| 12440 | os_memcpy(candidate->bssid, |
| 12441 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 12442 | ETH_ALEN); |
| 12443 | |
| 12444 | status = nla_get_u32( |
| 12445 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 12446 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 12447 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 12448 | |
| 12449 | if (candidate->is_accept) |
| 12450 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 12451 | else |
| 12452 | os_snprintf(buf, sizeof(buf), |
| 12453 | "Rejected, Reject_reason: %d", |
| 12454 | candidate->reject_reason); |
| 12455 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 12456 | num, MAC2STR(candidate->bssid), buf); |
| 12457 | } |
| 12458 | |
| 12459 | |
| 12460 | static int |
| 12461 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 12462 | { |
| 12463 | struct wpa_bss_candidate_info *info = arg; |
| 12464 | struct candidate_list *candidate = info->candidates; |
| 12465 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 12466 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 12467 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 12468 | static struct nla_policy policy[ |
| 12469 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 12470 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 12471 | .minlen = ETH_ALEN |
| 12472 | }, |
| 12473 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 12474 | .type = NLA_U32, |
| 12475 | }, |
| 12476 | }; |
| 12477 | struct nlattr *attr; |
| 12478 | int rem; |
| 12479 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 12480 | u8 num; |
| 12481 | |
| 12482 | num = info->num; /* number of candidates sent to driver */ |
| 12483 | info->num = 0; |
| 12484 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 12485 | genlmsg_attrlen(gnlh, 0), NULL); |
| 12486 | |
| 12487 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 12488 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 12489 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 12490 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 12491 | return NL_SKIP; |
| 12492 | |
| 12493 | wpa_printf(MSG_DEBUG, |
| 12494 | "nl80211: WNM Candidate list received from driver"); |
| 12495 | nla_for_each_nested(attr, |
| 12496 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 12497 | rem) { |
| 12498 | if (info->num >= num || |
| 12499 | nla_parse_nested( |
| 12500 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 12501 | attr, policy) || |
| 12502 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 12503 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 12504 | break; |
| 12505 | |
| 12506 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 12507 | |
| 12508 | candidate++; |
| 12509 | info->num++; |
| 12510 | } |
| 12511 | |
| 12512 | return NL_SKIP; |
| 12513 | } |
| 12514 | |
| 12515 | |
| 12516 | static struct wpa_bss_candidate_info * |
| 12517 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 12518 | { |
| 12519 | struct i802_bss *bss = priv; |
| 12520 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12521 | struct nl_msg *msg; |
| 12522 | struct nlattr *attr, *attr1, *attr2; |
| 12523 | struct wpa_bss_candidate_info *info; |
| 12524 | u8 i; |
| 12525 | int ret; |
| 12526 | u8 *pos; |
| 12527 | |
| 12528 | if (!drv->fetch_bss_trans_status) |
| 12529 | return NULL; |
| 12530 | |
| 12531 | info = os_zalloc(sizeof(*info)); |
| 12532 | if (!info) |
| 12533 | return NULL; |
| 12534 | /* Allocate memory for number of candidates sent to driver */ |
| 12535 | info->candidates = os_calloc(params->n_candidates, |
| 12536 | sizeof(*info->candidates)); |
| 12537 | if (!info->candidates) { |
| 12538 | os_free(info); |
| 12539 | return NULL; |
| 12540 | } |
| 12541 | |
| 12542 | /* Copy the number of candidates being sent to driver. This is used in |
| 12543 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 12544 | * candidates that can be populated in info->candidates and will be |
| 12545 | * later overwritten with the actual number of candidates received from |
| 12546 | * the driver. |
| 12547 | */ |
| 12548 | info->num = params->n_candidates; |
| 12549 | |
| 12550 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12551 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12552 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12553 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 12554 | goto fail; |
| 12555 | |
| 12556 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12557 | if (!attr) |
| 12558 | goto fail; |
| 12559 | |
| 12560 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 12561 | params->mbo_transition_reason)) |
| 12562 | goto fail; |
| 12563 | |
| 12564 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 12565 | if (!attr1) |
| 12566 | goto fail; |
| 12567 | |
| 12568 | wpa_printf(MSG_DEBUG, |
| 12569 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 12570 | params->mbo_transition_reason, params->n_candidates); |
| 12571 | pos = params->bssid; |
| 12572 | for (i = 0; i < params->n_candidates; i++) { |
| 12573 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 12574 | MAC2STR(pos)); |
| 12575 | attr2 = nla_nest_start(msg, i); |
| 12576 | if (!attr2 || |
| 12577 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 12578 | ETH_ALEN, pos)) |
| 12579 | goto fail; |
| 12580 | pos += ETH_ALEN; |
| 12581 | nla_nest_end(msg, attr2); |
| 12582 | } |
| 12583 | |
| 12584 | nla_nest_end(msg, attr1); |
| 12585 | nla_nest_end(msg, attr); |
| 12586 | |
| 12587 | ret = send_and_recv_msgs(drv, msg, |
| 12588 | nl80211_get_bss_transition_status_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12589 | info, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12590 | msg = NULL; |
| 12591 | if (ret) { |
| 12592 | wpa_printf(MSG_ERROR, |
| 12593 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 12594 | ret, strerror(-ret)); |
| 12595 | goto fail; |
| 12596 | } |
| 12597 | return info; |
| 12598 | |
| 12599 | fail: |
| 12600 | nlmsg_free(msg); |
| 12601 | os_free(info->candidates); |
| 12602 | os_free(info); |
| 12603 | return NULL; |
| 12604 | } |
| 12605 | |
| 12606 | |
| 12607 | /** |
| 12608 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 12609 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 12610 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 12611 | * Returns: 0 on success, -1 on failure |
| 12612 | */ |
| 12613 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 12614 | { |
| 12615 | struct i802_bss *bss = priv; |
| 12616 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12617 | struct nl_msg *msg; |
| 12618 | struct nlattr *attr; |
| 12619 | int ret = -1; |
| 12620 | |
| 12621 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 12622 | return -1; |
| 12623 | |
| 12624 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12625 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12626 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12627 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 12628 | goto fail; |
| 12629 | |
| 12630 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12631 | if (!attr) |
| 12632 | goto fail; |
| 12633 | |
| 12634 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 12635 | ignore_disallow); |
| 12636 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 12637 | ignore_disallow)) |
| 12638 | goto fail; |
| 12639 | |
| 12640 | nla_nest_end(msg, attr); |
| 12641 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12642 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12643 | msg = NULL; |
| 12644 | if (ret) { |
| 12645 | wpa_printf(MSG_ERROR, |
| 12646 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 12647 | ret, strerror(-ret)); |
| 12648 | goto fail; |
| 12649 | } |
| 12650 | |
| 12651 | fail: |
| 12652 | nlmsg_free(msg); |
| 12653 | return ret; |
| 12654 | } |
| 12655 | |
| 12656 | #endif /* CONFIG_MBO */ |
| 12657 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 12658 | |
| 12659 | #ifdef CONFIG_PASN |
| 12660 | |
| 12661 | static int nl80211_send_pasn_resp(void *priv, struct pasn_auth *params) |
| 12662 | { |
| 12663 | unsigned int i; |
| 12664 | struct i802_bss *bss = priv; |
| 12665 | struct nl_msg *msg = NULL; |
| 12666 | struct nlattr *nlpeers, *attr, *attr1; |
| 12667 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12668 | |
| 12669 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12670 | "nl80211: PASN authentication response for %d entries", |
| 12671 | params->num_peers); |
| 12672 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 12673 | if (!msg || |
| 12674 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12675 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12676 | QCA_NL80211_VENDOR_SUBCMD_PASN)) |
| 12677 | goto fail; |
| 12678 | |
| 12679 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12680 | if (!attr) |
| 12681 | goto fail; |
| 12682 | |
| 12683 | nlpeers = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEERS); |
| 12684 | if (!nlpeers) |
| 12685 | goto fail; |
| 12686 | |
| 12687 | for (i = 0; i < params->num_peers; i++) { |
| 12688 | attr1 = nla_nest_start(msg, i); |
| 12689 | if (!attr1 || |
| 12690 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_SRC_ADDR, |
| 12691 | ETH_ALEN, params->peer[i].own_addr) || |
| 12692 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_MAC_ADDR, |
| 12693 | ETH_ALEN, params->peer[i].peer_addr)) |
| 12694 | goto fail; |
| 12695 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 12696 | if (params->peer[i].status == 0 && |
| 12697 | nla_put_flag(msg, |
| 12698 | QCA_WLAN_VENDOR_ATTR_PASN_PEER_STATUS_SUCCESS)) |
| 12699 | goto fail; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 12700 | |
| 12701 | wpa_printf(MSG_DEBUG, |
| 12702 | "nl80211: Own address[%u]: " MACSTR |
| 12703 | " Peer address[%u]: " MACSTR " Status: %s", |
| 12704 | i, MAC2STR(params->peer[i].own_addr), i, |
| 12705 | MAC2STR(params->peer[i].peer_addr), |
| 12706 | params->peer[i].status ? "Fail" : "Success"); |
| 12707 | nla_nest_end(msg, attr1); |
| 12708 | } |
| 12709 | |
| 12710 | nla_nest_end(msg, nlpeers); |
| 12711 | nla_nest_end(msg, attr); |
| 12712 | |
| 12713 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 12714 | |
| 12715 | fail: |
| 12716 | nlmsg_free(msg); |
| 12717 | return -1; |
| 12718 | } |
| 12719 | |
| 12720 | |
| 12721 | static u32 wpa_ltf_keyseed_len_to_sha_type(size_t len) |
| 12722 | { |
| 12723 | if (len == SHA384_MAC_LEN) |
| 12724 | return QCA_WLAN_VENDOR_SHA_384; |
| 12725 | if (len == SHA256_MAC_LEN) |
| 12726 | return QCA_WLAN_VENDOR_SHA_256; |
| 12727 | |
| 12728 | wpa_printf(MSG_ERROR, "nl80211: Unexpected LTF keyseed len %zu", len); |
| 12729 | return (u32) -1; |
| 12730 | } |
| 12731 | |
| 12732 | |
| 12733 | static int nl80211_set_secure_ranging_ctx(void *priv, |
| 12734 | struct secure_ranging_params *params) |
| 12735 | { |
| 12736 | int ret; |
| 12737 | u32 suite; |
| 12738 | struct nlattr *attr; |
| 12739 | struct nl_msg *msg = NULL; |
| 12740 | struct i802_bss *bss = priv; |
| 12741 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12742 | |
| 12743 | /* Configure secure ranging context only to the drivers that support it. |
| 12744 | */ |
| 12745 | if (!drv->secure_ranging_ctx_vendor_cmd_avail) |
| 12746 | return 0; |
| 12747 | |
| 12748 | if (!params->peer_addr || !params->own_addr) |
| 12749 | return -1; |
| 12750 | |
| 12751 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12752 | "nl80211: Secure ranging context for " MACSTR, |
| 12753 | MAC2STR(params->peer_addr)); |
| 12754 | |
| 12755 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 12756 | if (!msg || |
| 12757 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12758 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12759 | QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT)) |
| 12760 | goto fail; |
| 12761 | |
| 12762 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12763 | if (!attr) |
| 12764 | goto fail; |
| 12765 | |
| 12766 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_PEER_MAC_ADDR, |
| 12767 | ETH_ALEN, params->peer_addr) || |
| 12768 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SRC_ADDR, |
| 12769 | ETH_ALEN, params->own_addr) || |
| 12770 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_ACTION, |
| 12771 | params->action)) |
| 12772 | goto fail; |
| 12773 | |
| 12774 | if (params->cipher) { |
| 12775 | suite = wpa_cipher_to_cipher_suite(params->cipher); |
| 12776 | if (!suite || |
| 12777 | nla_put_u32(msg, |
| 12778 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_CIPHER, |
| 12779 | suite)) |
| 12780 | goto fail; |
| 12781 | } |
| 12782 | |
| 12783 | if (params->tk_len && params->tk) { |
| 12784 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_TK, |
| 12785 | params->tk_len, params->tk)) |
| 12786 | goto fail; |
| 12787 | wpa_hexdump_key(MSG_DEBUG, "nl80211: TK", |
| 12788 | params->tk, params->tk_len); |
| 12789 | } |
| 12790 | |
| 12791 | if (params->ltf_keyseed_len && params->ltf_keyseed) { |
| 12792 | u32 sha_type = wpa_ltf_keyseed_len_to_sha_type( |
| 12793 | params->ltf_keyseed_len); |
| 12794 | |
| 12795 | if (sha_type == (u32) -1 || |
| 12796 | nla_put_u32( |
| 12797 | msg, |
| 12798 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SHA_TYPE, |
| 12799 | sha_type) || |
| 12800 | nla_put(msg, |
| 12801 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_LTF_KEYSEED, |
| 12802 | params->ltf_keyseed_len, params->ltf_keyseed)) |
| 12803 | goto fail; |
| 12804 | wpa_hexdump_key(MSG_DEBUG, "nl80211: LTF keyseed", |
| 12805 | params->ltf_keyseed, params->ltf_keyseed_len); |
| 12806 | } |
| 12807 | nla_nest_end(msg, attr); |
| 12808 | |
| 12809 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 12810 | if (ret) |
| 12811 | wpa_printf(MSG_DEBUG, |
| 12812 | "nl80211: Set secure ranging context failed: ret=%d (%s)", |
| 12813 | ret, strerror(-ret)); |
| 12814 | return ret; |
| 12815 | fail: |
| 12816 | nlmsg_free(msg); |
| 12817 | return -1; |
| 12818 | } |
| 12819 | |
| 12820 | #endif /* CONFIG_PASN */ |
| 12821 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12822 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 12823 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12824 | static int nl80211_do_acs(void *priv, struct drv_acs_params *params) |
| 12825 | { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12826 | #if defined(CONFIG_DRIVER_NL80211_QCA) || defined(CONFIG_DRIVER_NL80211_BRCM) \ |
| 12827 | || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12828 | struct i802_bss *bss = priv; |
| 12829 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12830 | #endif /* CONFIG_DRIVER_NL80211_QCA || CONFIG_DRIVER_NL80211_BRCM \ |
| 12831 | || defined(CONFIG_DRIVER_NL80211_SYNA) */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12832 | |
| 12833 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 12834 | if (drv->qca_do_acs) |
| 12835 | return nl80211_qca_do_acs(drv, params); |
| 12836 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 12837 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12838 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12839 | if (drv->brcm_do_acs) |
| 12840 | return wpa_driver_do_broadcom_acs(drv, params); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12841 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12842 | |
| 12843 | return -1; |
| 12844 | } |
| 12845 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12846 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12847 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 12848 | { |
| 12849 | int fd, len; |
| 12850 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12851 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12852 | |
| 12853 | fd = open(name, O_RDWR); |
| 12854 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12855 | int level; |
| 12856 | /* |
| 12857 | * Flags may not exist on older kernels, or while we're tearing |
| 12858 | * down a disappearing device. |
| 12859 | */ |
| 12860 | if (errno == ENOENT) { |
| 12861 | ret = 0; |
| 12862 | level = MSG_DEBUG; |
| 12863 | } else { |
| 12864 | ret = -1; |
| 12865 | level = MSG_ERROR; |
| 12866 | } |
| 12867 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12868 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12869 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12870 | } |
| 12871 | |
| 12872 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 12873 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12874 | if (len < 0) { |
| 12875 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12876 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 12877 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12878 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12879 | close(fd); |
| 12880 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12881 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12882 | } |
| 12883 | |
| 12884 | |
| 12885 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 12886 | { |
| 12887 | struct i802_bss *bss = priv; |
| 12888 | char path[128]; |
| 12889 | int ret; |
| 12890 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12891 | /* P2P-Device has no netdev that can (or should) be configured here */ |
| 12892 | if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE) |
| 12893 | return 0; |
| 12894 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12895 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 12896 | filter_flags); |
| 12897 | |
| 12898 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 12899 | ret = os_snprintf(path, sizeof(path), |
| 12900 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 12901 | bss->ifname); |
| 12902 | if (os_snprintf_error(sizeof(path), ret)) |
| 12903 | return -1; |
| 12904 | |
| 12905 | ret = nl80211_write_to_file(path, |
| 12906 | !!(filter_flags & |
| 12907 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 12908 | if (ret) { |
| 12909 | wpa_printf(MSG_ERROR, |
| 12910 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 12911 | return ret; |
| 12912 | } |
| 12913 | |
| 12914 | os_snprintf(path, sizeof(path), |
| 12915 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 12916 | bss->ifname); |
| 12917 | ret = nl80211_write_to_file(path, |
| 12918 | !!(filter_flags & |
| 12919 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 12920 | |
| 12921 | if (ret) { |
| 12922 | wpa_printf(MSG_ERROR, |
| 12923 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 12924 | return ret; |
| 12925 | } |
| 12926 | |
| 12927 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 12928 | os_snprintf(path, sizeof(path), |
| 12929 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 12930 | bss->ifname); |
| 12931 | ret = nl80211_write_to_file(path, |
| 12932 | !!(filter_flags & |
| 12933 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 12934 | if (ret) { |
| 12935 | wpa_printf(MSG_ERROR, |
| 12936 | "nl80211: Failed set gratuitous ARP filter"); |
| 12937 | return ret; |
| 12938 | } |
| 12939 | |
| 12940 | /* Configure filtering of IPv6 NA frames */ |
| 12941 | os_snprintf(path, sizeof(path), |
| 12942 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 12943 | bss->ifname); |
| 12944 | ret = nl80211_write_to_file(path, |
| 12945 | !!(filter_flags & |
| 12946 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 12947 | if (ret) { |
| 12948 | wpa_printf(MSG_ERROR, |
| 12949 | "nl80211: Failed to set unsolicited NA filter"); |
| 12950 | return ret; |
| 12951 | } |
| 12952 | |
| 12953 | return 0; |
| 12954 | } |
| 12955 | |
| 12956 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 12957 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 12958 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 12959 | unsigned int *ext_capa_len) |
| 12960 | { |
| 12961 | struct i802_bss *bss = priv; |
| 12962 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12963 | enum nl80211_iftype nlmode; |
| 12964 | unsigned int i; |
| 12965 | |
| 12966 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 12967 | return -1; |
| 12968 | |
| 12969 | nlmode = wpa_driver_nl80211_if_type(type); |
| 12970 | |
| 12971 | /* By default, use the per-radio values */ |
| 12972 | *ext_capa = drv->extended_capa; |
| 12973 | *ext_capa_mask = drv->extended_capa_mask; |
| 12974 | *ext_capa_len = drv->extended_capa_len; |
| 12975 | |
| 12976 | /* Replace the default value if a per-interface type value exists */ |
| 12977 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 12978 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 12979 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 12980 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 12981 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 12982 | break; |
| 12983 | } |
| 12984 | } |
| 12985 | |
| 12986 | return 0; |
| 12987 | } |
| 12988 | |
| 12989 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12990 | static int nl80211_update_connection_params( |
| 12991 | void *priv, struct wpa_driver_associate_params *params, |
| 12992 | enum wpa_drv_update_connect_params_mask mask) |
| 12993 | { |
| 12994 | struct i802_bss *bss = priv; |
| 12995 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12996 | struct nl_msg *msg; |
| 12997 | int ret = -1; |
| 12998 | enum nl80211_auth_type type; |
| 12999 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13000 | /* Update Connection Params is intended for drivers that implement |
| 13001 | * internal SME and expect these updated connection params from |
| 13002 | * wpa_supplicant. Do not send this request for the drivers using |
| 13003 | * SME from wpa_supplicant. |
| 13004 | */ |
| 13005 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 13006 | return 0; |
| 13007 | |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13008 | /* 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] | 13009 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13010 | if (mask & WPA_DRV_UPDATE_TD_POLICY) { |
| 13011 | ret = nl80211_set_td_policy(priv, params->td_policy); |
| 13012 | if (ret) { |
| 13013 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13014 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 13015 | ret, strerror(-ret)); |
| 13016 | } |
| 13017 | return ret; |
| 13018 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13019 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13020 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13021 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 13022 | if (!msg) |
| 13023 | goto fail; |
| 13024 | |
| 13025 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 13026 | drv->ifindex); |
| 13027 | |
| 13028 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 13029 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 13030 | params->wpa_ie)) |
| 13031 | goto fail; |
| 13032 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 13033 | params->wpa_ie_len); |
| 13034 | } |
| 13035 | |
| 13036 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 13037 | type = get_nl_auth_type(params->auth_alg); |
| 13038 | if (type == NL80211_AUTHTYPE_MAX || |
| 13039 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 13040 | goto fail; |
| 13041 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 13042 | } |
| 13043 | |
| 13044 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 13045 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 13046 | goto fail; |
| 13047 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 13048 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13049 | msg = NULL; |
| 13050 | if (ret) |
| 13051 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13052 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 13053 | ret, strerror(-ret)); |
| 13054 | |
| 13055 | fail: |
| 13056 | nlmsg_free(msg); |
| 13057 | return ret; |
| 13058 | } |
| 13059 | |
| 13060 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13061 | static int nl80211_send_external_auth_status(void *priv, |
| 13062 | struct external_auth *params) |
| 13063 | { |
| 13064 | struct i802_bss *bss = priv; |
| 13065 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13066 | struct nl_msg *msg = NULL; |
| 13067 | int ret = -1; |
| 13068 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13069 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 13070 | * internal SME but want to offload authentication processing (e.g., |
| 13071 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13072 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 13073 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13074 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13075 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 13076 | return -1; |
| 13077 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13078 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 13079 | "nl80211: External auth status: %u", params->status); |
| 13080 | |
| 13081 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 13082 | if (!msg || |
| 13083 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 13084 | (params->ssid && params->ssid_len && |
| 13085 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 13086 | (params->pmkid && |
| 13087 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 13088 | (params->bssid && |
| 13089 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13090 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 13091 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13092 | msg = NULL; |
| 13093 | if (ret) { |
| 13094 | wpa_printf(MSG_DEBUG, |
| 13095 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 13096 | ret, strerror(-ret)); |
| 13097 | goto fail; |
| 13098 | } |
| 13099 | fail: |
| 13100 | nlmsg_free(msg); |
| 13101 | return ret; |
| 13102 | } |
| 13103 | |
| 13104 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13105 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 13106 | int val) |
| 13107 | { |
| 13108 | struct i802_bss *bss = priv; |
| 13109 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13110 | struct nl_msg *msg; |
| 13111 | int ret = -ENOBUFS; |
| 13112 | |
| 13113 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 13114 | val ? "Enable" : "Disable", bridge_ifname); |
| 13115 | |
| 13116 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 13117 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 13118 | goto fail; |
| 13119 | |
| 13120 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 13121 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 13122 | bridge_ifname, bss->ifname)) { |
| 13123 | wpa_printf(MSG_ERROR, |
| 13124 | "nl80211: Failed to remove interface %s from bridge %s", |
| 13125 | bss->ifname, bridge_ifname); |
| 13126 | return -1; |
| 13127 | } |
| 13128 | bss->added_if_into_bridge = 0; |
| 13129 | } |
| 13130 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 13131 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13132 | msg = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 13133 | if (ret && val && nl80211_get_4addr(bss) == 1) { |
| 13134 | wpa_printf(MSG_DEBUG, |
| 13135 | "nl80211: 4addr mode was already enabled"); |
| 13136 | ret = 0; |
| 13137 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13138 | if (!ret) { |
| 13139 | if (bridge_ifname[0] && val && |
| 13140 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 13141 | return -1; |
| 13142 | return 0; |
| 13143 | } |
| 13144 | |
| 13145 | fail: |
| 13146 | nlmsg_free(msg); |
| 13147 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 13148 | |
| 13149 | return ret; |
| 13150 | } |
| 13151 | |
| 13152 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 13153 | #ifdef CONFIG_DPP |
| 13154 | static int nl80211_dpp_listen(void *priv, bool enable) |
| 13155 | { |
| 13156 | struct i802_bss *bss = priv; |
| 13157 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13158 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
| 13159 | struct nl_sock *handle; |
| 13160 | |
| 13161 | if (!drv->multicast_registrations || !bss->nl_mgmt) |
| 13162 | return 0; /* cannot do more than hope broadcast RX works */ |
| 13163 | |
| 13164 | wpa_printf(MSG_DEBUG, |
| 13165 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", |
| 13166 | enable ? "enable" : "disable"); |
| 13167 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 13168 | return nl80211_register_frame(bss, handle, type, |
| 13169 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, |
| 13170 | enable); |
| 13171 | } |
| 13172 | #endif /* CONFIG_DPP */ |
| 13173 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13174 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 13175 | static int nl80211_set_td_policy(void *priv, u32 td_policy) |
| 13176 | { |
| 13177 | struct i802_bss *bss = priv; |
| 13178 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13179 | struct nl_msg *msg; |
| 13180 | int ret; |
| 13181 | struct nlattr *params; |
| 13182 | |
| 13183 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 13184 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 13185 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_SET_TD_POLICY) || |
| 13186 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 13187 | (nla_put_u32(msg, BRCM_ATTR_DRIVER_TD_POLICY, td_policy))) { |
| 13188 | nl80211_nlmsg_clear(msg); |
| 13189 | nlmsg_free(msg); |
| 13190 | return -ENOBUFS; |
| 13191 | } |
| 13192 | nla_nest_end(msg, params); |
| 13193 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable Policy %d\n", td_policy); |
| 13194 | |
| 13195 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 13196 | if (ret) { |
| 13197 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable setting failed: ret=%d (%s)", |
| 13198 | ret, strerror(-ret)); |
| 13199 | } |
| 13200 | |
| 13201 | return ret; |
| 13202 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 13203 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 13204 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13205 | #ifdef CONFIG_TESTING_OPTIONS |
| 13206 | |
| 13207 | static int testing_nl80211_register_frame(void *priv, u16 type, |
| 13208 | const u8 *match, size_t match_len, |
| 13209 | bool multicast) |
| 13210 | { |
| 13211 | struct i802_bss *bss = priv; |
| 13212 | struct nl_sock *handle; |
| 13213 | |
| 13214 | if (!bss->nl_mgmt) |
| 13215 | return -1; |
| 13216 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 13217 | return nl80211_register_frame(bss, handle, type, match, match_len, |
| 13218 | multicast); |
| 13219 | } |
| 13220 | |
| 13221 | |
| 13222 | static int testing_nl80211_radio_disable(void *priv, int disabled) |
| 13223 | { |
| 13224 | struct i802_bss *bss = priv; |
| 13225 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 13226 | |
| 13227 | /* For now, this is supported only partially in station mode with |
| 13228 | * SME-in-wpa_supplicant case where the NL80211_ATTR_LOCAL_STATE_CHANGE |
| 13229 | * attribute can be used to avoid sending out the Deauthentication frame |
| 13230 | * to the currently associated AP. */ |
| 13231 | |
| 13232 | if (!disabled) |
| 13233 | return 0; |
| 13234 | |
| 13235 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 13236 | return -1; |
| 13237 | |
| 13238 | if (!drv->associated) |
| 13239 | return 0; |
| 13240 | |
| 13241 | return wpa_driver_nl80211_mlme(drv, drv->bssid, |
| 13242 | NL80211_CMD_DEAUTHENTICATE, |
| 13243 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1, |
| 13244 | drv->first_bss); |
| 13245 | } |
| 13246 | |
| 13247 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 13248 | |
| 13249 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13250 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 13251 | .name = "nl80211", |
| 13252 | .desc = "Linux nl80211/cfg80211", |
| 13253 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 13254 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13255 | .set_key = driver_nl80211_set_key, |
| 13256 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13257 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 13258 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13259 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 13260 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13261 | .deauthenticate = driver_nl80211_deauthenticate, |
| 13262 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13263 | .associate = wpa_driver_nl80211_associate, |
| 13264 | .global_init = nl80211_global_init, |
| 13265 | .global_deinit = nl80211_global_deinit, |
| 13266 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13267 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13268 | .get_capa = wpa_driver_nl80211_get_capa, |
| 13269 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 13270 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 13271 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 13272 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13273 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 13274 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13275 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13276 | .if_remove = driver_nl80211_if_remove, |
| 13277 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13278 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13279 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13280 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 13281 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13282 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 13283 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13284 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13285 | .hapd_init = i802_init, |
| 13286 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 13287 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13288 | .get_seqnum = i802_get_seqnum, |
| 13289 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13290 | .get_inact_sec = i802_get_inact_sec, |
| 13291 | .sta_clear_stats = i802_sta_clear_stats, |
| 13292 | .set_rts = i802_set_rts, |
| 13293 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13294 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13295 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13296 | .sta_deauth = i802_sta_deauth, |
| 13297 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13298 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13299 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13300 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13301 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 13302 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 13303 | .cancel_remain_on_channel = |
| 13304 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13305 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13306 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 13307 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13308 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13309 | .signal_monitor = nl80211_signal_monitor, |
| 13310 | .signal_poll = nl80211_signal_poll, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13311 | .mlo_signal_poll = nl80211_mlo_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13312 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13313 | .set_param = nl80211_set_param, |
| 13314 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 13315 | .add_pmkid = nl80211_add_pmkid, |
| 13316 | .remove_pmkid = nl80211_remove_pmkid, |
| 13317 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13318 | .set_rekey_info = nl80211_set_rekey_info, |
| 13319 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13320 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 13321 | .start_dfs_cac = nl80211_start_radar_detection, |
| 13322 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13323 | #ifdef CONFIG_TDLS |
| 13324 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 13325 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13326 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 13327 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13328 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 13329 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13330 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 13331 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13332 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 13333 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 13334 | .switch_channel = nl80211_switch_channel, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 13335 | #ifdef CONFIG_IEEE80211AX |
| 13336 | .switch_color = nl80211_switch_color, |
| 13337 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13338 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 13339 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13340 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 13341 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 13342 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 13343 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 13344 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 13345 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 13346 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 13347 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 13348 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 13349 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 13350 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 13351 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 13352 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13353 | #ifdef CONFIG_MESH |
| 13354 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 13355 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 13356 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13357 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13358 | #endif /* CONFIG_MESH */ |
| 13359 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 13360 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 13361 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 13362 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 13363 | .add_tx_ts = nl80211_add_ts, |
| 13364 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 13365 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13366 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13367 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13368 | .disable_fils = nl80211_disable_fils, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 13369 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13370 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 13371 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13372 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 13373 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 13374 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 13375 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13376 | #ifdef CONFIG_MBO |
| 13377 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 13378 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 13379 | #endif /* CONFIG_MBO */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 13380 | .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13381 | .add_sta_node = nl80211_add_sta_node, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13382 | #ifdef CONFIG_PASN |
| 13383 | .send_pasn_resp = nl80211_send_pasn_resp, |
| 13384 | .set_secure_ranging_ctx = nl80211_set_secure_ranging_ctx, |
| 13385 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13386 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13387 | .do_acs = nl80211_do_acs, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13388 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 13389 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13390 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13391 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13392 | .set_4addr_mode = nl80211_set_4addr_mode, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 13393 | #ifdef CONFIG_DPP |
| 13394 | .dpp_listen = nl80211_dpp_listen, |
| 13395 | #endif /* CONFIG_DPP */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13396 | .get_sta_mlo_info = nl80211_get_sta_mlo_info, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13397 | #ifdef CONFIG_TESTING_OPTIONS |
| 13398 | .register_frame = testing_nl80211_register_frame, |
| 13399 | .radio_disable = testing_nl80211_radio_disable, |
| 13400 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13401 | }; |