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; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 226 | } |
| 227 | return CHAN_WIDTH_UNKNOWN; |
| 228 | } |
| 229 | |
| 230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 231 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 232 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 233 | return nlmode == NL80211_IFTYPE_AP || |
| 234 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 238 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 239 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 240 | return nlmode == NL80211_IFTYPE_STATION || |
| 241 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 245 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 246 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 247 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 248 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 249 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 250 | |
| 251 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 252 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 253 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 254 | { |
| 255 | struct i802_bss *bss; |
| 256 | |
| 257 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 258 | if (bss->ifindex == ifindex) |
| 259 | return bss; |
| 260 | } |
| 261 | |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 266 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 267 | { |
| 268 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 273 | { |
| 274 | if (drv->associated) |
| 275 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 276 | drv->associated = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 277 | drv->sta_mlo_info.valid_links = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 278 | os_memset(drv->bssid, 0, ETH_ALEN); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 279 | drv->first_bss->freq = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 280 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 281 | os_free(drv->pending_roam_data); |
| 282 | drv->pending_roam_data = NULL; |
| 283 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 287 | /* nl80211 code */ |
| 288 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 289 | { |
| 290 | int *err = arg; |
| 291 | *err = 0; |
| 292 | return NL_STOP; |
| 293 | } |
| 294 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 295 | |
| 296 | struct nl80211_ack_ext_arg { |
| 297 | int *err; |
| 298 | void *ext_data; |
| 299 | }; |
| 300 | |
| 301 | |
| 302 | static int ack_handler_cookie(struct nl_msg *msg, void *arg) |
| 303 | { |
| 304 | struct nl80211_ack_ext_arg *ext_arg = arg; |
| 305 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
| 306 | u64 *cookie = ext_arg->ext_data; |
| 307 | struct nlattr *attrs; |
| 308 | size_t ack_len, attr_len; |
| 309 | |
| 310 | *ext_arg->err = 0; |
| 311 | ack_len = sizeof(struct nlmsghdr) + sizeof(int) + |
| 312 | sizeof(struct nlmsghdr); |
| 313 | attrs = (struct nlattr *) |
| 314 | ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) + |
| 315 | sizeof(int)); |
| 316 | if (nlmsg_hdr(msg)->nlmsg_len <= ack_len) |
| 317 | return NL_STOP; |
| 318 | |
| 319 | attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len; |
| 320 | |
| 321 | if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 322 | return NL_STOP; |
| 323 | |
| 324 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL); |
| 325 | if (tb[NLMSGERR_ATTR_COOKIE]) |
| 326 | *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]); |
| 327 | |
| 328 | return NL_STOP; |
| 329 | } |
| 330 | |
| 331 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 332 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 333 | { |
| 334 | int *ret = arg; |
| 335 | *ret = 0; |
| 336 | return NL_SKIP; |
| 337 | } |
| 338 | |
| 339 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 340 | void *arg) |
| 341 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 342 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 343 | int len = nlh->nlmsg_len; |
| 344 | struct nlattr *attrs; |
| 345 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 347 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 348 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 349 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 350 | |
| 351 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 352 | return NL_SKIP; |
| 353 | |
| 354 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 355 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 356 | |
| 357 | if (len <= ack_len) |
| 358 | return NL_STOP; |
| 359 | |
| 360 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 361 | len -= ack_len; |
| 362 | |
| 363 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 364 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 365 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 366 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 367 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 368 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 369 | } |
| 370 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 371 | return NL_SKIP; |
| 372 | } |
| 373 | |
| 374 | |
| 375 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 376 | { |
| 377 | return NL_OK; |
| 378 | } |
| 379 | |
| 380 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 381 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 382 | { |
| 383 | /* |
| 384 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 385 | * heap memory for unnecessarily long time. |
| 386 | */ |
| 387 | if (msg) { |
| 388 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 389 | void *data = nlmsg_data(hdr); |
| 390 | /* |
| 391 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 392 | * only libnl were to maintain a stable API.. Neither will work |
| 393 | * with all released versions, so just calculate the length |
| 394 | * here. |
| 395 | */ |
| 396 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 397 | |
| 398 | os_memset(data, 0, len); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 403 | static int send_and_recv(struct nl80211_global *global, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 404 | struct nl_sock *nl_handle, struct nl_msg *msg, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 405 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 406 | void *valid_data, |
| 407 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 408 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 409 | { |
| 410 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 411 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 412 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 413 | if (!msg) |
| 414 | return -ENOMEM; |
| 415 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 416 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | if (!cb) |
| 418 | goto out; |
| 419 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 420 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 421 | opt = 1; |
| 422 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 423 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 424 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 425 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 426 | opt = 1; |
| 427 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 428 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 429 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | err = nl_send_auto_complete(nl_handle, msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 431 | if (err < 0) { |
| 432 | wpa_printf(MSG_INFO, |
| 433 | "nl80211: nl_send_auto_complete() failed: %s", |
| 434 | nl_geterror(err)); |
| 435 | /* Need to convert libnl error code to an errno value. For now, |
| 436 | * just hardcode this to EBADF; the real error reason is shown |
| 437 | * in that error print above. */ |
| 438 | err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 439 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 440 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 441 | |
| 442 | err = 1; |
| 443 | |
| 444 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 445 | 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] | 446 | if (ack_handler_custom) { |
| 447 | struct nl80211_ack_ext_arg *ext_arg = ack_data; |
| 448 | |
| 449 | ext_arg->err = &err; |
| 450 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, |
| 451 | ack_handler_custom, ack_data); |
| 452 | } else { |
| 453 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 454 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 455 | |
| 456 | if (valid_handler) |
| 457 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 458 | valid_handler, valid_data); |
| 459 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 460 | while (err > 0) { |
| 461 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 462 | |
| 463 | if (res == -NLE_DUMP_INTR) { |
| 464 | /* Most likely one of the nl80211 dump routines hit a |
| 465 | * case where internal results changed while the dump |
| 466 | * was being sent. The most common known case for this |
| 467 | * is scan results fetching while associated were every |
| 468 | * received Beacon frame from the AP may end up |
| 469 | * incrementing bss_generation. This |
| 470 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 471 | * other cases (of which there are no known common ones) |
| 472 | * will stop and return an error. */ |
| 473 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 474 | nl_geterror(res)); |
| 475 | err = -EAGAIN; |
| 476 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 477 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 478 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 479 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 482 | out: |
| 483 | nl_cb_put(cb); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 484 | /* Always clear the message as it can potentially contain keys */ |
| 485 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 486 | nlmsg_free(msg); |
| 487 | return err; |
| 488 | } |
| 489 | |
| 490 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 491 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 492 | struct nl_msg *msg, |
| 493 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 494 | void *valid_data, |
| 495 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 496 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 497 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 498 | return send_and_recv(drv->global, drv->global->nl, msg, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 499 | valid_handler, valid_data, |
| 500 | ack_handler_custom, ack_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 504 | /* Use this method to mark that it is necessary to own the connection/interface |
| 505 | * for this operation. |
| 506 | * handle may be set to NULL, to get the same behavior as send_and_recv_msgs(). |
| 507 | * set_owner can be used to mark this socket for receiving control port frames. |
| 508 | */ |
| 509 | static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv, |
| 510 | struct nl_msg *msg, |
| 511 | struct nl_sock *handle, int set_owner, |
| 512 | int (*valid_handler)(struct nl_msg *, |
| 513 | void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 514 | void *valid_data, |
| 515 | int (*ack_handler_custom)(struct nl_msg *, |
| 516 | void *), |
| 517 | void *ack_data) |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 518 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 519 | if (!msg) |
| 520 | return -ENOMEM; |
| 521 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 522 | /* Control port over nl80211 needs the flags and attributes below. |
| 523 | * |
| 524 | * The Linux kernel has initial checks for them (in nl80211.c) like: |
| 525 | * validate_pae_over_nl80211(...) |
| 526 | * or final checks like: |
| 527 | * dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid |
| 528 | * |
| 529 | * Final operations (e.g., disassociate) don't need to set these |
| 530 | * attributes, but they have to be performed on the socket, which has |
| 531 | * the connection owner property set in the kernel. |
| 532 | */ |
| 533 | if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && |
| 534 | handle && set_owner && |
| 535 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || |
| 536 | nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) || |
| 537 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 538 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))) |
| 539 | return -1; |
| 540 | |
| 541 | return send_and_recv(drv->global, handle ? handle : drv->global->nl, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 542 | msg, valid_handler, valid_data, |
| 543 | ack_handler_custom, ack_data); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 547 | static int |
| 548 | send_and_recv_msgs_connect_handle(struct wpa_driver_nl80211_data *drv, |
| 549 | struct nl_msg *msg, struct i802_bss *bss, |
| 550 | int set_owner) |
| 551 | { |
| 552 | struct nl_sock *nl_connect = get_connect_handle(bss); |
| 553 | |
| 554 | if (nl_connect) |
| 555 | return send_and_recv_msgs_owner(drv, msg, nl_connect, set_owner, |
| 556 | process_bss_event, bss, NULL, |
| 557 | NULL); |
| 558 | else |
| 559 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 560 | } |
| 561 | |
| 562 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 563 | struct nl_sock * get_connect_handle(struct i802_bss *bss) |
| 564 | { |
| 565 | if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) || |
| 566 | bss->use_nl_connect) |
| 567 | return bss->nl_connect; |
| 568 | |
| 569 | return NULL; |
| 570 | } |
| 571 | |
| 572 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 573 | struct family_data { |
| 574 | const char *group; |
| 575 | int id; |
| 576 | }; |
| 577 | |
| 578 | |
| 579 | static int family_handler(struct nl_msg *msg, void *arg) |
| 580 | { |
| 581 | struct family_data *res = arg; |
| 582 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 583 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 584 | struct nlattr *mcgrp; |
| 585 | int i; |
| 586 | |
| 587 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 588 | genlmsg_attrlen(gnlh, 0), NULL); |
| 589 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 590 | return NL_SKIP; |
| 591 | |
| 592 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 593 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 594 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 595 | nla_len(mcgrp), NULL); |
| 596 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 597 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 598 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 599 | res->group, |
| 600 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 601 | continue; |
| 602 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 603 | break; |
| 604 | }; |
| 605 | |
| 606 | return NL_SKIP; |
| 607 | } |
| 608 | |
| 609 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 610 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 611 | const char *family, const char *group) |
| 612 | { |
| 613 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 614 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 615 | struct family_data res = { group, -ENOENT }; |
| 616 | |
| 617 | msg = nlmsg_alloc(); |
| 618 | if (!msg) |
| 619 | return -ENOMEM; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 620 | if (!genlmsg_put(msg, 0, 0, global->nlctrl_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 621 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 622 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 623 | nlmsg_free(msg); |
| 624 | return -1; |
| 625 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 626 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 627 | ret = send_and_recv(global, global->nl, msg, family_handler, &res, |
| 628 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 629 | if (ret == 0) |
| 630 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 635 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 636 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 637 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 638 | if (TEST_FAIL()) |
| 639 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 640 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 641 | 0, flags, cmd, 0); |
| 642 | } |
| 643 | |
| 644 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 645 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 646 | { |
| 647 | if (bss->wdev_id_set) |
| 648 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 649 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 650 | } |
| 651 | |
| 652 | |
| 653 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 654 | { |
| 655 | struct nl_msg *msg; |
| 656 | |
| 657 | msg = nlmsg_alloc(); |
| 658 | if (!msg) |
| 659 | return NULL; |
| 660 | |
| 661 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 662 | nl80211_set_iface_id(msg, bss) < 0) { |
| 663 | nlmsg_free(msg); |
| 664 | return NULL; |
| 665 | } |
| 666 | |
| 667 | return msg; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | static struct nl_msg * |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 672 | nl80211_ifindex_msg_build(struct wpa_driver_nl80211_data *drv, |
| 673 | struct nl_msg *msg, int ifindex, int flags, |
| 674 | uint8_t cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 675 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 676 | if (!msg) |
| 677 | return NULL; |
| 678 | |
| 679 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 680 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 681 | nlmsg_free(msg); |
| 682 | return NULL; |
| 683 | } |
| 684 | |
| 685 | return msg; |
| 686 | } |
| 687 | |
| 688 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 689 | static struct nl_msg * |
| 690 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 691 | int flags, uint8_t cmd) |
| 692 | { |
| 693 | return nl80211_ifindex_msg_build(drv, nlmsg_alloc(), ifindex, flags, |
| 694 | cmd); |
| 695 | } |
| 696 | |
| 697 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 698 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 699 | uint8_t cmd) |
| 700 | { |
| 701 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 702 | } |
| 703 | |
| 704 | |
| 705 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 706 | { |
| 707 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 708 | } |
| 709 | |
| 710 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 711 | struct wiphy_idx_data { |
| 712 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 713 | enum nl80211_iftype nlmode; |
| 714 | u8 *macaddr; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 715 | u8 use_4addr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | |
| 719 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 720 | { |
| 721 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 722 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 723 | struct wiphy_idx_data *info = arg; |
| 724 | |
| 725 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 726 | genlmsg_attrlen(gnlh, 0), NULL); |
| 727 | |
| 728 | if (tb[NL80211_ATTR_WIPHY]) |
| 729 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 730 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 731 | if (tb[NL80211_ATTR_IFTYPE]) |
| 732 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 733 | |
| 734 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 735 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 736 | ETH_ALEN); |
| 737 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 738 | if (tb[NL80211_ATTR_4ADDR]) |
| 739 | info->use_4addr = nla_get_u8(tb[NL80211_ATTR_4ADDR]); |
| 740 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 741 | return NL_SKIP; |
| 742 | } |
| 743 | |
| 744 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 745 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 746 | { |
| 747 | struct nl_msg *msg; |
| 748 | struct wiphy_idx_data data = { |
| 749 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 750 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 751 | }; |
| 752 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 753 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 754 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 755 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 756 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 757 | NULL, NULL) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 758 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 759 | return -1; |
| 760 | } |
| 761 | |
| 762 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 763 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 764 | { |
| 765 | struct nl_msg *msg; |
| 766 | struct wiphy_idx_data data = { |
| 767 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 768 | .macaddr = NULL, |
| 769 | }; |
| 770 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 771 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 772 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 773 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 774 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 775 | NULL, NULL) == 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 776 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 777 | return NL80211_IFTYPE_UNSPECIFIED; |
| 778 | } |
| 779 | |
| 780 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 781 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 782 | { |
| 783 | struct nl_msg *msg; |
| 784 | struct wiphy_idx_data data = { |
| 785 | .macaddr = bss->addr, |
| 786 | }; |
| 787 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 788 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 789 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 790 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 791 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 792 | NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 793 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 794 | |
| 795 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 796 | static int nl80211_get_4addr(struct i802_bss *bss) |
| 797 | { |
| 798 | struct nl_msg *msg; |
| 799 | struct wiphy_idx_data data = { |
| 800 | .use_4addr = 0, |
| 801 | }; |
| 802 | |
| 803 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)) || |
| 804 | send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 805 | NULL, NULL)) |
| 806 | return -1; |
| 807 | return data.use_4addr; |
| 808 | } |
| 809 | |
| 810 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 811 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 812 | struct nl80211_wiphy_data *w) |
| 813 | { |
| 814 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 815 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 816 | |
| 817 | msg = nlmsg_alloc(); |
| 818 | if (!msg) |
| 819 | return -1; |
| 820 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 821 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 822 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 823 | nlmsg_free(msg); |
| 824 | return -1; |
| 825 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 826 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 827 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL, |
| 828 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 829 | if (ret) { |
| 830 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 831 | "failed: ret=%d (%s)", |
| 832 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 833 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 839 | { |
| 840 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 841 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 842 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 843 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 844 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 845 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 846 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 847 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 848 | __func__, res); |
| 849 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | |
| 853 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 854 | { |
| 855 | struct nl80211_wiphy_data *w = arg; |
| 856 | struct wpa_driver_nl80211_data *drv; |
| 857 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 858 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 859 | union wpa_event_data event; |
| 860 | |
| 861 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 862 | genlmsg_attrlen(gnlh, 0), NULL); |
| 863 | |
| 864 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 865 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 866 | gnlh->cmd); |
| 867 | return NL_SKIP; |
| 868 | } |
| 869 | |
| 870 | if (!tb[NL80211_ATTR_FRAME]) |
| 871 | return NL_SKIP; |
| 872 | |
| 873 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 874 | wiphy_list) { |
| 875 | os_memset(&event, 0, sizeof(event)); |
| 876 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 877 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 878 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 879 | } |
| 880 | |
| 881 | return NL_SKIP; |
| 882 | } |
| 883 | |
| 884 | |
| 885 | static struct nl80211_wiphy_data * |
| 886 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 887 | { |
| 888 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 889 | struct nl80211_wiphy_data *w; |
| 890 | int wiphy_idx, found = 0; |
| 891 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 892 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 893 | |
| 894 | if (bss->wiphy_data != NULL) |
| 895 | return bss->wiphy_data; |
| 896 | |
| 897 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 898 | |
| 899 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 900 | if (w->wiphy_idx == wiphy_idx) |
| 901 | goto add; |
| 902 | } |
| 903 | |
| 904 | /* alloc new one */ |
| 905 | w = os_zalloc(sizeof(*w)); |
| 906 | if (w == NULL) |
| 907 | return NULL; |
| 908 | w->wiphy_idx = wiphy_idx; |
| 909 | dl_list_init(&w->bsss); |
| 910 | dl_list_init(&w->drvs); |
| 911 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 912 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 913 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 914 | HOSTAPD_MODE_IEEE80211AD) { |
| 915 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 916 | if (!w->nl_cb) { |
| 917 | os_free(w); |
| 918 | return NULL; |
| 919 | } |
| 920 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 921 | no_seq_check, NULL); |
| 922 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 923 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 924 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 925 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 926 | "wiphy beacons"); |
| 927 | if (w->nl_beacons == NULL) { |
| 928 | os_free(w); |
| 929 | return NULL; |
| 930 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 931 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 932 | if (nl80211_register_beacons(bss->drv, w)) { |
| 933 | nl_destroy_handles(&w->nl_beacons); |
| 934 | os_free(w); |
| 935 | return NULL; |
| 936 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 937 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 938 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 939 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 940 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 941 | |
| 942 | dl_list_add(&nl80211_wiphys, &w->list); |
| 943 | |
| 944 | add: |
| 945 | /* drv entry for this bss already there? */ |
| 946 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 947 | if (tmp_bss->drv == bss->drv) { |
| 948 | found = 1; |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | /* if not add it */ |
| 953 | if (!found) |
| 954 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 955 | |
| 956 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 957 | bss->wiphy_data = w; |
| 958 | return w; |
| 959 | } |
| 960 | |
| 961 | |
| 962 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 963 | { |
| 964 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 965 | struct i802_bss *tmp_bss; |
| 966 | int found = 0; |
| 967 | |
| 968 | if (w == NULL) |
| 969 | return; |
| 970 | bss->wiphy_data = NULL; |
| 971 | dl_list_del(&bss->wiphy_list); |
| 972 | |
| 973 | /* still any for this drv present? */ |
| 974 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 975 | if (tmp_bss->drv == bss->drv) { |
| 976 | found = 1; |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | /* if not remove it */ |
| 981 | if (!found) |
| 982 | dl_list_del(&bss->drv->wiphy_list); |
| 983 | |
| 984 | if (!dl_list_empty(&w->bsss)) |
| 985 | return; |
| 986 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 987 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 988 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 989 | |
| 990 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 991 | dl_list_del(&w->list); |
| 992 | os_free(w); |
| 993 | } |
| 994 | |
| 995 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 996 | static unsigned int nl80211_get_ifindex(void *priv) |
| 997 | { |
| 998 | struct i802_bss *bss = priv; |
| 999 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1000 | |
| 1001 | return drv->ifindex; |
| 1002 | } |
| 1003 | |
| 1004 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1005 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 1006 | { |
| 1007 | struct i802_bss *bss = priv; |
| 1008 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1009 | if (!drv->associated) |
| 1010 | return -1; |
| 1011 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 1017 | { |
| 1018 | struct i802_bss *bss = priv; |
| 1019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1020 | if (!drv->associated) |
| 1021 | return -1; |
| 1022 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 1023 | return drv->ssid_len; |
| 1024 | } |
| 1025 | |
| 1026 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1027 | static int nl80211_get_sta_mlo_info(void *priv, |
| 1028 | struct driver_sta_mlo_info *mlo_info) |
| 1029 | { |
| 1030 | struct i802_bss *bss = priv; |
| 1031 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1032 | |
| 1033 | if (!drv->associated) |
| 1034 | return -1; |
| 1035 | |
| 1036 | os_memcpy(mlo_info, &drv->sta_mlo_info, sizeof(*mlo_info)); |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1041 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1042 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1043 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1044 | { |
| 1045 | union wpa_event_data event; |
| 1046 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1047 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1048 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 1049 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 1050 | drv->first_bss->ifname); |
| 1051 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1052 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1053 | if (!drv->if_removed) |
| 1054 | return; |
| 1055 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 1056 | drv->first_bss->ifname); |
| 1057 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1060 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1061 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1062 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1063 | sizeof(event.interface_status.ifname)); |
| 1064 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1065 | if (drv) |
| 1066 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1067 | else |
| 1068 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1069 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1074 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1075 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1076 | { |
| 1077 | union wpa_event_data event; |
| 1078 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1079 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1080 | if (drv->if_removed) { |
| 1081 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1082 | ifname); |
| 1083 | return; |
| 1084 | } |
| 1085 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1086 | ifname); |
| 1087 | drv->if_removed = 1; |
| 1088 | } else { |
| 1089 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1090 | ifname); |
| 1091 | } |
| 1092 | |
| 1093 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1094 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1095 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1096 | sizeof(event.interface_status.ifname)); |
| 1097 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1098 | if (drv) |
| 1099 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1100 | else |
| 1101 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1102 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | |
| 1106 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1107 | u8 *buf, size_t len) |
| 1108 | { |
| 1109 | int attrlen, rta_len; |
| 1110 | struct rtattr *attr; |
| 1111 | |
| 1112 | attrlen = len; |
| 1113 | attr = (struct rtattr *) buf; |
| 1114 | |
| 1115 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1116 | while (RTA_OK(attr, attrlen)) { |
| 1117 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1118 | if (os_strcmp(((char *) attr) + rta_len, |
| 1119 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1120 | return 1; |
| 1121 | else |
| 1122 | break; |
| 1123 | } |
| 1124 | attr = RTA_NEXT(attr, attrlen); |
| 1125 | } |
| 1126 | |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1132 | int ifindex, u8 *buf, size_t len) |
| 1133 | { |
| 1134 | if (drv->ifindex == ifindex) |
| 1135 | return 1; |
| 1136 | |
| 1137 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1138 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1139 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1140 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1141 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 1142 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | return 1; |
| 1144 | } |
| 1145 | |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1150 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1151 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 1152 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1153 | { |
| 1154 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1155 | int res; |
| 1156 | |
| 1157 | if (init_failed) |
| 1158 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1159 | dl_list_for_each(drv, &global->interfaces, |
| 1160 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1161 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1162 | if (res < 0) { |
| 1163 | wpa_printf(MSG_DEBUG, |
| 1164 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1165 | if (init_failed) |
| 1166 | *init_failed = 1; |
| 1167 | return drv; |
| 1168 | } |
| 1169 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1170 | return drv; |
| 1171 | } |
| 1172 | return NULL; |
| 1173 | } |
| 1174 | |
| 1175 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1176 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1177 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1178 | { |
| 1179 | struct i802_bss *bss; |
| 1180 | u8 addr[ETH_ALEN]; |
| 1181 | |
| 1182 | bss = get_bss_ifindex(drv, ifindex); |
| 1183 | if (bss && |
| 1184 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1185 | bss->ifname, addr) < 0) { |
| 1186 | wpa_printf(MSG_DEBUG, |
| 1187 | "nl80211: %s: failed to re-read MAC address", |
| 1188 | bss->ifname); |
| 1189 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1190 | wpa_printf(MSG_DEBUG, |
| 1191 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1192 | MACSTR " to " MACSTR, |
| 1193 | ifindex, bss->ifname, |
| 1194 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1195 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1196 | if (notify) |
| 1197 | wpa_supplicant_event(drv->ctx, |
| 1198 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1203 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1204 | struct ifinfomsg *ifi, |
| 1205 | u8 *buf, size_t len) |
| 1206 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1207 | struct nl80211_global *global = ctx; |
| 1208 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1209 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1210 | struct rtattr *attr; |
| 1211 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1212 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1213 | char ifname[IFNAMSIZ + 1]; |
| 1214 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1215 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1216 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1217 | extra[0] = '\0'; |
| 1218 | pos = extra; |
| 1219 | end = pos + sizeof(extra); |
| 1220 | ifname[0] = '\0'; |
| 1221 | |
| 1222 | attrlen = len; |
| 1223 | attr = (struct rtattr *) buf; |
| 1224 | while (RTA_OK(attr, attrlen)) { |
| 1225 | switch (attr->rta_type) { |
| 1226 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1227 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1228 | break; |
| 1229 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1230 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1231 | break; |
| 1232 | case IFLA_MASTER: |
| 1233 | brid = nla_get_u32((struct nlattr *) attr); |
| 1234 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1235 | break; |
| 1236 | case IFLA_WIRELESS: |
| 1237 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1238 | break; |
| 1239 | case IFLA_OPERSTATE: |
| 1240 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1241 | nla_get_u32((struct nlattr *) attr)); |
| 1242 | break; |
| 1243 | case IFLA_LINKMODE: |
| 1244 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1245 | nla_get_u32((struct nlattr *) attr)); |
| 1246 | break; |
| 1247 | } |
| 1248 | attr = RTA_NEXT(attr, attrlen); |
| 1249 | } |
| 1250 | extra[sizeof(extra) - 1] = '\0'; |
| 1251 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1252 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1253 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1254 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1255 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1256 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1257 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1258 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1259 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1260 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1261 | if (!drv) |
| 1262 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1263 | if (init_failed) |
| 1264 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1265 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1266 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1267 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1268 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1269 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1270 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1271 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1272 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1273 | /* Re-read MAC address as it may have changed */ |
| 1274 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1275 | return; |
| 1276 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1277 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1278 | namebuf, ifname); |
| 1279 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1280 | wpa_printf(MSG_DEBUG, |
| 1281 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1282 | drv->first_bss->ifname); |
| 1283 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1284 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1285 | "event generated by mode change"); |
| 1286 | drv->ignore_if_down_event = 0; |
| 1287 | } else { |
| 1288 | drv->if_disabled = 1; |
| 1289 | wpa_supplicant_event(drv->ctx, |
| 1290 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1291 | |
| 1292 | /* |
| 1293 | * Try to get drv again, since it may be removed as |
| 1294 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1295 | * dynamic interfaces |
| 1296 | */ |
| 1297 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1298 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1299 | if (!drv) |
| 1300 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1301 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1305 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1306 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1307 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1308 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1309 | "event since interface %s is down", |
| 1310 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1311 | return; |
| 1312 | } |
| 1313 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1314 | namebuf, ifname); |
| 1315 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1316 | wpa_printf(MSG_DEBUG, |
| 1317 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1318 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1319 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1320 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1321 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1322 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1323 | } else if (drv->if_removed) { |
| 1324 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1325 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1326 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1327 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1328 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1329 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1330 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1331 | drv->if_disabled = 0; |
| 1332 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1333 | NULL); |
| 1334 | } |
Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1335 | } else if (ifi->ifi_flags & IFF_UP) { |
| 1336 | /* Re-read MAC address as it may have changed */ |
| 1337 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * Some drivers send the association event before the operup event--in |
| 1342 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1343 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1344 | * IEEE 802.1X authentication |
| 1345 | */ |
| 1346 | if (drv->operstate == 1 && |
| 1347 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1348 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1349 | 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] | 1350 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1351 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1354 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1355 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1356 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1357 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1358 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1359 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1360 | struct i802_bss *bss; |
| 1361 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1362 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1363 | if (!if_indextoname(brid, namebuf)) { |
| 1364 | wpa_printf(MSG_DEBUG, |
| 1365 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1366 | brid); |
| 1367 | return; |
| 1368 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1369 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1370 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1371 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1372 | |
| 1373 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1374 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1375 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1376 | break; |
| 1377 | } |
| 1378 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1384 | struct ifinfomsg *ifi, |
| 1385 | u8 *buf, size_t len) |
| 1386 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1387 | struct nl80211_global *global = ctx; |
| 1388 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1389 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1390 | struct rtattr *attr; |
| 1391 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1392 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1393 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1394 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1395 | extra[0] = '\0'; |
| 1396 | pos = extra; |
| 1397 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1398 | ifname[0] = '\0'; |
| 1399 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1400 | attrlen = len; |
| 1401 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1402 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1403 | switch (attr->rta_type) { |
| 1404 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1405 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1406 | break; |
| 1407 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1408 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1409 | break; |
| 1410 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1411 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1412 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1413 | break; |
| 1414 | case IFLA_OPERSTATE: |
| 1415 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1416 | nla_get_u32((struct nlattr *) attr)); |
| 1417 | break; |
| 1418 | case IFLA_LINKMODE: |
| 1419 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1420 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1421 | break; |
| 1422 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1423 | attr = RTA_NEXT(attr, attrlen); |
| 1424 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1425 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1426 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1427 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1428 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1429 | ifi->ifi_flags, |
| 1430 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1431 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1432 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1433 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1434 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1435 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1436 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1437 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1438 | /* device has been removed from bridge */ |
| 1439 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1440 | |
| 1441 | if (!if_indextoname(brid, namebuf)) { |
| 1442 | wpa_printf(MSG_DEBUG, |
| 1443 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1444 | brid); |
| 1445 | } else { |
| 1446 | wpa_printf(MSG_DEBUG, |
| 1447 | "nl80211: Remove ifindex %u for bridge %s", |
| 1448 | brid, namebuf); |
| 1449 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1450 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1451 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1452 | |
| 1453 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1454 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1455 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1459 | struct nl80211_get_assoc_freq_arg { |
| 1460 | struct wpa_driver_nl80211_data *drv; |
| 1461 | unsigned int assoc_freq; |
| 1462 | unsigned int ibss_freq; |
| 1463 | u8 assoc_bssid[ETH_ALEN]; |
| 1464 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1465 | u8 assoc_ssid_len; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1466 | u8 bssid[MAX_NUM_MLD_LINKS][ETH_ALEN]; |
| 1467 | unsigned int freq[MAX_NUM_MLD_LINKS]; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1468 | }; |
| 1469 | |
| 1470 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1471 | { |
| 1472 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1473 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1474 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1475 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1476 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1477 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1478 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1479 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1480 | [NL80211_BSS_MLO_LINK_ID] = { .type = NLA_U8 }, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1481 | }; |
| 1482 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1483 | enum nl80211_bss_status status; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1484 | struct wpa_driver_nl80211_data *drv = ctx->drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1485 | |
| 1486 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1487 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1488 | if (!tb[NL80211_ATTR_BSS] || |
| 1489 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1490 | bss_policy) || |
| 1491 | !bss[NL80211_BSS_STATUS]) |
| 1492 | return NL_SKIP; |
| 1493 | |
| 1494 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1495 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1496 | bss[NL80211_BSS_FREQUENCY]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1497 | int link_id = -1; |
| 1498 | u32 freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1499 | |
| 1500 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1501 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1502 | |
| 1503 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1504 | ctx->freq[link_id] = freq; |
| 1505 | wpa_printf(MSG_DEBUG, |
| 1506 | "nl80211: MLO link %d associated on %u MHz", |
| 1507 | link_id, ctx->freq[link_id]); |
| 1508 | } |
| 1509 | |
| 1510 | if (!drv->sta_mlo_info.valid_links || |
| 1511 | drv->mlo_assoc_link_id == link_id) { |
| 1512 | ctx->assoc_freq = freq; |
| 1513 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1514 | ctx->assoc_freq); |
| 1515 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1516 | } |
| 1517 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1518 | bss[NL80211_BSS_FREQUENCY]) { |
| 1519 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1520 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1521 | ctx->ibss_freq); |
| 1522 | } |
| 1523 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1524 | bss[NL80211_BSS_BSSID]) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1525 | int link_id = -1; |
| 1526 | const u8 *bssid = nla_data(bss[NL80211_BSS_BSSID]); |
| 1527 | |
| 1528 | if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 1529 | link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 1530 | |
| 1531 | if (link_id >= 0 && link_id < MAX_NUM_MLD_LINKS) { |
| 1532 | os_memcpy(ctx->bssid[link_id], bssid, ETH_ALEN); |
| 1533 | wpa_printf(MSG_DEBUG, |
| 1534 | "nl80211: MLO link %d associated with " |
| 1535 | MACSTR, link_id, MAC2STR(bssid)); |
| 1536 | } |
| 1537 | |
| 1538 | if (!drv->sta_mlo_info.valid_links || |
| 1539 | drv->mlo_assoc_link_id == link_id) { |
| 1540 | os_memcpy(ctx->assoc_bssid, bssid, ETH_ALEN); |
| 1541 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1542 | MACSTR, MAC2STR(bssid)); |
| 1543 | } |
| 1544 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1548 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1549 | const u8 *ie, *ssid; |
| 1550 | size_t ie_len; |
| 1551 | |
| 1552 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1553 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1554 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1555 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1556 | ctx->assoc_ssid_len = ssid[1]; |
| 1557 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | return NL_SKIP; |
| 1562 | } |
| 1563 | |
| 1564 | |
| 1565 | 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] | 1566 | { |
| 1567 | struct nl_msg *msg; |
| 1568 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1569 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1570 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1571 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1572 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1573 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1574 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1575 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1576 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1577 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1578 | if (ret == -EAGAIN) { |
| 1579 | count++; |
| 1580 | if (count >= 10) { |
| 1581 | wpa_printf(MSG_INFO, |
| 1582 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1583 | } else { |
| 1584 | wpa_printf(MSG_DEBUG, |
| 1585 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1586 | goto try_again; |
| 1587 | } |
| 1588 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1589 | if (ret == 0) { |
| 1590 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1591 | return arg.assoc_ssid_len; |
| 1592 | } |
| 1593 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1594 | ret, strerror(-ret)); |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1600 | { |
| 1601 | struct nl_msg *msg; |
| 1602 | int ret; |
| 1603 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1604 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1605 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1606 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1607 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1608 | os_memset(&arg, 0, sizeof(arg)); |
| 1609 | arg.drv = drv; |
| 1610 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1611 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1612 | if (ret == -EAGAIN) { |
| 1613 | count++; |
| 1614 | if (count >= 10) { |
| 1615 | wpa_printf(MSG_INFO, |
| 1616 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1617 | } else { |
| 1618 | wpa_printf(MSG_DEBUG, |
| 1619 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1620 | goto try_again; |
| 1621 | } |
| 1622 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1623 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1624 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1625 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1626 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1627 | "associated BSS from scan results: %u MHz", freq); |
| 1628 | if (freq) |
| 1629 | drv->assoc_freq = freq; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1630 | |
| 1631 | if (drv->sta_mlo_info.valid_links) { |
| 1632 | int i; |
| 1633 | |
| 1634 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) |
| 1635 | drv->sta_mlo_info.links[i].freq = arg.freq[i]; |
| 1636 | } |
| 1637 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1638 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1639 | } |
| 1640 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1641 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1642 | return drv->assoc_freq; |
| 1643 | } |
| 1644 | |
| 1645 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1646 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1647 | { |
| 1648 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1649 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1650 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1651 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1652 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1653 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1654 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1655 | }; |
| 1656 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1657 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1658 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1659 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1660 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1661 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1662 | }; |
| 1663 | struct wpa_signal_info *sig_change = arg; |
| 1664 | |
| 1665 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1666 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1667 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1668 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1669 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1670 | return NL_SKIP; |
| 1671 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1672 | return NL_SKIP; |
| 1673 | |
| 1674 | sig_change->current_signal = |
| 1675 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1676 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1677 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1678 | sig_change->avg_signal = |
| 1679 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1680 | else |
| 1681 | sig_change->avg_signal = 0; |
| 1682 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1683 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1684 | sig_change->avg_beacon_signal = |
| 1685 | (s8) |
| 1686 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1687 | else |
| 1688 | sig_change->avg_beacon_signal = 0; |
| 1689 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1690 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1691 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1692 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1693 | rate_policy)) { |
| 1694 | sig_change->current_txrate = 0; |
| 1695 | } else { |
| 1696 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1697 | sig_change->current_txrate = |
| 1698 | nla_get_u16(rinfo[ |
| 1699 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | |
Mahesh KKV | 4571efa | 2022-12-06 14:11:39 -0800 | [diff] [blame] | 1704 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
| 1705 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1706 | sinfo[NL80211_STA_INFO_RX_BITRATE], |
| 1707 | rate_policy)) { |
| 1708 | sig_change->current_rxrate = 0; |
| 1709 | } else { |
| 1710 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1711 | sig_change->current_rxrate = |
| 1712 | nla_get_u16(rinfo[ |
| 1713 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | return NL_SKIP; |
| 1719 | } |
| 1720 | |
| 1721 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1722 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1723 | const u8 *bssid, struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1724 | { |
| 1725 | struct nl_msg *msg; |
| 1726 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1727 | sig->current_signal = -WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1728 | sig->current_txrate = 0; |
Mahesh KKV | 4571efa | 2022-12-06 14:11:39 -0800 | [diff] [blame] | 1729 | sig->current_rxrate = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1730 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1731 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1732 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1733 | nlmsg_free(msg); |
| 1734 | return -ENOBUFS; |
| 1735 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1736 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1737 | return send_and_recv_msgs(drv, msg, get_link_signal, sig, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1742 | { |
| 1743 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1744 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1745 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1746 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1747 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1748 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1749 | }; |
| 1750 | struct wpa_signal_info *sig_change = arg; |
| 1751 | |
| 1752 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1753 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1754 | |
| 1755 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1756 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1757 | return NL_SKIP; |
| 1758 | } |
| 1759 | |
| 1760 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1761 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1762 | survey_policy)) { |
| 1763 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1764 | "attributes!"); |
| 1765 | return NL_SKIP; |
| 1766 | } |
| 1767 | |
| 1768 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1769 | return NL_SKIP; |
| 1770 | |
| 1771 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1772 | sig_change->frequency) |
| 1773 | return NL_SKIP; |
| 1774 | |
| 1775 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1776 | return NL_SKIP; |
| 1777 | |
| 1778 | sig_change->current_noise = |
| 1779 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1780 | |
| 1781 | return NL_SKIP; |
| 1782 | } |
| 1783 | |
| 1784 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1785 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1786 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1787 | { |
| 1788 | struct nl_msg *msg; |
| 1789 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1790 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1791 | sig_change->frequency = drv->assoc_freq; |
| 1792 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1793 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1794 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change, |
| 1795 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1799 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1800 | { |
| 1801 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1802 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1803 | struct wpa_channel_info *chan_info = arg; |
| 1804 | |
| 1805 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1806 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1807 | |
| 1808 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1809 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1810 | |
| 1811 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1812 | chan_info->frequency = |
| 1813 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1814 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1815 | chan_info->chanwidth = convert2width( |
| 1816 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1817 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1818 | enum nl80211_channel_type ct = |
| 1819 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1820 | |
| 1821 | switch (ct) { |
| 1822 | case NL80211_CHAN_HT40MINUS: |
| 1823 | chan_info->sec_channel = -1; |
| 1824 | break; |
| 1825 | case NL80211_CHAN_HT40PLUS: |
| 1826 | chan_info->sec_channel = 1; |
| 1827 | break; |
| 1828 | default: |
| 1829 | chan_info->sec_channel = 0; |
| 1830 | break; |
| 1831 | } |
| 1832 | } |
| 1833 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1834 | chan_info->center_frq1 = |
| 1835 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1836 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1837 | chan_info->center_frq2 = |
| 1838 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1839 | |
| 1840 | if (chan_info->center_frq2) { |
| 1841 | u8 seg1_idx = 0; |
| 1842 | |
| 1843 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1844 | NUM_HOSTAPD_MODES) |
| 1845 | chan_info->seg1_idx = seg1_idx; |
| 1846 | } |
| 1847 | |
| 1848 | return NL_SKIP; |
| 1849 | } |
| 1850 | |
| 1851 | |
| 1852 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1853 | { |
| 1854 | struct i802_bss *bss = priv; |
| 1855 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1856 | struct nl_msg *msg; |
| 1857 | |
| 1858 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1859 | 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] | 1860 | } |
| 1861 | |
| 1862 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1864 | void *handle) |
| 1865 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1866 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1867 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1868 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1869 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1870 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1871 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1872 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1873 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1874 | __func__, res); |
| 1875 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | |
| 1879 | /** |
| 1880 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1881 | * @priv: driver_nl80211 private data |
| 1882 | * @alpha2_arg: country to which to switch to |
| 1883 | * Returns: 0 on success, -1 on failure |
| 1884 | * |
| 1885 | * This asks nl80211 to set the regulatory domain for given |
| 1886 | * country ISO / IEC alpha2. |
| 1887 | */ |
| 1888 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1889 | { |
| 1890 | struct i802_bss *bss = priv; |
| 1891 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1892 | char alpha2[3]; |
| 1893 | struct nl_msg *msg; |
| 1894 | |
| 1895 | msg = nlmsg_alloc(); |
| 1896 | if (!msg) |
| 1897 | return -ENOMEM; |
| 1898 | |
| 1899 | alpha2[0] = alpha2_arg[0]; |
| 1900 | alpha2[1] = alpha2_arg[1]; |
| 1901 | alpha2[2] = '\0'; |
| 1902 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1903 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1904 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1905 | nlmsg_free(msg); |
| 1906 | return -EINVAL; |
| 1907 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1908 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1909 | return -EINVAL; |
| 1910 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1914 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1915 | { |
| 1916 | char *alpha2 = arg; |
| 1917 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1918 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1919 | |
| 1920 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1921 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1922 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1923 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1924 | return NL_SKIP; |
| 1925 | } |
| 1926 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1927 | return NL_SKIP; |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1932 | { |
| 1933 | struct i802_bss *bss = priv; |
| 1934 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1935 | struct nl_msg *msg; |
| 1936 | int ret; |
| 1937 | |
| 1938 | msg = nlmsg_alloc(); |
| 1939 | if (!msg) |
| 1940 | return -ENOMEM; |
| 1941 | |
| 1942 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1943 | alpha2[0] = '\0'; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1944 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2, |
| 1945 | NULL, NULL); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1946 | if (!alpha2[0]) |
| 1947 | ret = -1; |
| 1948 | |
| 1949 | return ret; |
| 1950 | } |
| 1951 | |
| 1952 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1953 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1954 | { |
| 1955 | int ret; |
| 1956 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1957 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1958 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1959 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1960 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1961 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1964 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1965 | if (global->nl == NULL) |
| 1966 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1967 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1968 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1969 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1970 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1971 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1975 | global->nlctrl_id = genl_ctrl_resolve(global->nl, "nlctrl"); |
| 1976 | if (global->nlctrl_id < 0) { |
| 1977 | wpa_printf(MSG_ERROR, |
| 1978 | "nl80211: 'nlctrl' generic netlink not found"); |
| 1979 | goto err; |
| 1980 | } |
| 1981 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1982 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1983 | if (global->nl_event == NULL) |
| 1984 | goto err; |
| 1985 | |
| 1986 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1987 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1988 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1989 | if (ret < 0) { |
| 1990 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1991 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1992 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1993 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1996 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1998 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1999 | if (ret < 0) { |
| 2000 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 2001 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2002 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2003 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2006 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2007 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2008 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2009 | if (ret < 0) { |
| 2010 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 2011 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2012 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2013 | /* Continue without regulatory events */ |
| 2014 | } |
| 2015 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2016 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 2017 | if (ret >= 0) |
| 2018 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 2019 | if (ret < 0) { |
| 2020 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 2021 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2022 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2023 | /* Continue without vendor events */ |
| 2024 | } |
| 2025 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2026 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2027 | no_seq_check, NULL); |
| 2028 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2029 | process_global_event, global); |
| 2030 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2031 | nl80211_register_eloop_read(&global->nl_event, |
| 2032 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2033 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2034 | |
| 2035 | return 0; |
| 2036 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2037 | err: |
| 2038 | nl_destroy_handles(&global->nl_event); |
| 2039 | nl_destroy_handles(&global->nl); |
| 2040 | nl_cb_put(global->nl_cb); |
| 2041 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2042 | return -1; |
| 2043 | } |
| 2044 | |
| 2045 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2046 | static void nl80211_check_global(struct nl80211_global *global) |
| 2047 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2048 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2049 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 2050 | int ret; |
| 2051 | unsigned int i; |
| 2052 | |
| 2053 | /* |
| 2054 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 2055 | * and all registration having been cleared. |
| 2056 | */ |
| 2057 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 2058 | ELOOP_SOCKET_INVALID); |
| 2059 | |
| 2060 | for (i = 0; groups[i]; i++) { |
| 2061 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 2062 | if (ret >= 0) |
| 2063 | ret = nl_socket_add_membership(handle, ret); |
| 2064 | if (ret < 0) { |
| 2065 | wpa_printf(MSG_INFO, |
| 2066 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2067 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2073 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 2074 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2075 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2076 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2077 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2078 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2080 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 2081 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2082 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2083 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2084 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | |
| 2088 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 2089 | { |
| 2090 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2091 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2092 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 2094 | "after rfkill unblock"); |
| 2095 | return; |
| 2096 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2097 | |
| 2098 | if (is_p2p_net_interface(drv->nlmode)) |
| 2099 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 2100 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2101 | /* |
| 2102 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 2103 | * Device interface as enabled. |
| 2104 | */ |
| 2105 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2106 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2110 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 2111 | void *eloop_ctx, |
| 2112 | void *handle) |
| 2113 | { |
| 2114 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 2115 | u8 data[2048]; |
| 2116 | struct msghdr msg; |
| 2117 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2118 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2119 | struct cmsghdr *cmsg; |
| 2120 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 2121 | union wpa_event_data event; |
| 2122 | |
| 2123 | memset(&msg, 0, sizeof(msg)); |
| 2124 | msg.msg_iov = &entry; |
| 2125 | msg.msg_iovlen = 1; |
| 2126 | entry.iov_base = data; |
| 2127 | entry.iov_len = sizeof(data); |
| 2128 | msg.msg_control = &control; |
| 2129 | msg.msg_controllen = sizeof(control); |
| 2130 | |
| 2131 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 2132 | /* if error or not fitting 802.3 header, return */ |
| 2133 | if (res < 14) |
| 2134 | return; |
| 2135 | |
| 2136 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 2137 | { |
| 2138 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 2139 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 2140 | int *ack; |
| 2141 | |
| 2142 | found_wifi = 1; |
| 2143 | ack = (void *)CMSG_DATA(cmsg); |
| 2144 | acked = *ack; |
| 2145 | } |
| 2146 | |
| 2147 | if (cmsg->cmsg_level == SOL_PACKET && |
| 2148 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 2149 | struct sock_extended_err *err = |
| 2150 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 2151 | |
| 2152 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 2153 | found_ee = 1; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | if (!found_ee || !found_wifi) |
| 2158 | return; |
| 2159 | |
| 2160 | memset(&event, 0, sizeof(event)); |
| 2161 | event.eapol_tx_status.dst = data; |
| 2162 | event.eapol_tx_status.data = data + 14; |
| 2163 | event.eapol_tx_status.data_len = res - 14; |
| 2164 | event.eapol_tx_status.ack = acked; |
| 2165 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 2166 | } |
| 2167 | |
| 2168 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2169 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2170 | { |
| 2171 | if (bss->nl_connect) { |
| 2172 | wpa_printf(MSG_DEBUG, |
| 2173 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2174 | bss->nl_connect); |
| 2175 | return -1; |
| 2176 | } |
| 2177 | |
| 2178 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2179 | if (!bss->nl_connect) |
| 2180 | return -1; |
| 2181 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2182 | wpa_driver_nl80211_event_receive, |
| 2183 | bss->nl_cb, 1); |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2188 | static int nl80211_init_bss(struct i802_bss *bss) |
| 2189 | { |
| 2190 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 2191 | if (!bss->nl_cb) |
| 2192 | return -1; |
| 2193 | |
| 2194 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2195 | no_seq_check, NULL); |
| 2196 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2197 | process_bss_event, bss); |
| 2198 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2199 | nl80211_init_connect_handle(bss); |
| 2200 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2201 | return 0; |
| 2202 | } |
| 2203 | |
| 2204 | |
| 2205 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 2206 | { |
| 2207 | nl_cb_put(bss->nl_cb); |
| 2208 | bss->nl_cb = NULL; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2209 | |
| 2210 | if (bss->nl_connect) |
| 2211 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2215 | static void |
| 2216 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 2217 | { |
| 2218 | struct rfkill_config *rcfg; |
| 2219 | |
| 2220 | if (drv->rfkill) |
| 2221 | return; |
| 2222 | |
| 2223 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 2224 | if (!rcfg) |
| 2225 | return; |
| 2226 | |
| 2227 | rcfg->ctx = drv; |
| 2228 | |
| 2229 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 2230 | * not associated with a netdev, so use the name of some other interface |
| 2231 | * sharing the same wiphy as the P2P Device interface. |
| 2232 | * |
| 2233 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 2234 | * created and is created only once another wpa_s interface was added. |
| 2235 | */ |
| 2236 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 2237 | struct nl80211_global *global = drv->global; |
| 2238 | struct wpa_driver_nl80211_data *tmp1; |
| 2239 | |
| 2240 | dl_list_for_each(tmp1, &global->interfaces, |
| 2241 | struct wpa_driver_nl80211_data, list) { |
| 2242 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 2243 | !tmp1->rfkill) |
| 2244 | continue; |
| 2245 | |
| 2246 | wpa_printf(MSG_DEBUG, |
| 2247 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 2248 | tmp1->first_bss->ifname); |
| 2249 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 2250 | sizeof(rcfg->ifname)); |
| 2251 | break; |
| 2252 | } |
| 2253 | } else { |
| 2254 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 2255 | sizeof(rcfg->ifname)); |
| 2256 | } |
| 2257 | |
| 2258 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 2259 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 2260 | drv->rfkill = rfkill_init(rcfg); |
| 2261 | if (!drv->rfkill) { |
| 2262 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 2263 | os_free(rcfg); |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2268 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 2269 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2270 | const u8 *set_addr, |
| 2271 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2272 | { |
| 2273 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | struct i802_bss *bss; |
| 2275 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2276 | if (global_priv == NULL) |
| 2277 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | drv = os_zalloc(sizeof(*drv)); |
| 2279 | if (drv == NULL) |
| 2280 | return NULL; |
| 2281 | drv->global = global_priv; |
| 2282 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2283 | drv->hostapd = !!hostapd; |
| 2284 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2285 | |
| 2286 | /* |
| 2287 | * There is no driver capability flag for this, so assume it is |
| 2288 | * supported and disable this on first attempt to use if the driver |
| 2289 | * rejects the command due to missing support. |
| 2290 | */ |
| 2291 | drv->set_rekey_offload = 1; |
| 2292 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2293 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2294 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2295 | |
| 2296 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2297 | if (!drv->first_bss) { |
| 2298 | os_free(drv); |
| 2299 | return NULL; |
| 2300 | } |
| 2301 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2302 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2303 | bss->ctx = ctx; |
| 2304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2305 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2306 | drv->monitor_ifidx = -1; |
| 2307 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2308 | drv->eapol_tx_sock = -1; |
| 2309 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2310 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2311 | if (nl80211_init_bss(bss)) |
| 2312 | goto failed; |
| 2313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2314 | 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] | 2315 | goto failed; |
| 2316 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2317 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) { |
| 2318 | drv->control_port_ap = 1; |
| 2319 | goto skip_wifi_status; |
| 2320 | } |
| 2321 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2322 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2323 | if (drv->eapol_tx_sock < 0) |
| 2324 | goto failed; |
| 2325 | |
| 2326 | if (drv->data_tx_status) { |
| 2327 | int enabled = 1; |
| 2328 | |
| 2329 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2330 | &enabled, sizeof(enabled)) < 0) { |
| 2331 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2332 | "nl80211: wifi status sockopt failed: %s", |
| 2333 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2334 | drv->data_tx_status = 0; |
| 2335 | if (!drv->use_monitor) |
| 2336 | drv->capa.flags &= |
| 2337 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2338 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2339 | eloop_register_read_sock( |
| 2340 | drv->eapol_tx_sock, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2341 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2342 | drv, NULL); |
| 2343 | } |
| 2344 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2345 | skip_wifi_status: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2346 | |
| 2347 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2348 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2349 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2350 | drv->in_interface_list = 1; |
| 2351 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2352 | |
| 2353 | return bss; |
| 2354 | |
| 2355 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2356 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2357 | return NULL; |
| 2358 | } |
| 2359 | |
| 2360 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2361 | /** |
| 2362 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2363 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2364 | * e.g., wpa_supplicant_event() |
| 2365 | * @ifname: interface name, e.g., wlan0 |
| 2366 | * @global_priv: private driver global data from global_init() |
| 2367 | * Returns: Pointer to private data, %NULL on failure |
| 2368 | */ |
| 2369 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2370 | void *global_priv) |
| 2371 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2372 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2373 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2377 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2378 | struct nl_sock *nl_handle, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2379 | u16 type, const u8 *match, size_t match_len, |
| 2380 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2382 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2383 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2384 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2385 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2386 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2387 | buf[0] = '\0'; |
| 2388 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2389 | wpa_printf(MSG_DEBUG, |
| 2390 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", |
| 2391 | type, fc2str(type), nl_handle, buf, multicast); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2392 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2393 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2394 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2395 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2396 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2397 | nlmsg_free(msg); |
| 2398 | return -1; |
| 2399 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2400 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2401 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL, |
| 2402 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | if (ret) { |
| 2404 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2405 | "failed (type=%u): ret=%d (%s)", |
| 2406 | type, ret, strerror(-ret)); |
| 2407 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2408 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2410 | return ret; |
| 2411 | } |
| 2412 | |
| 2413 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2414 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2415 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2416 | if (bss->nl_mgmt) { |
| 2417 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2418 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2419 | return -1; |
| 2420 | } |
| 2421 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2422 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2423 | if (bss->nl_mgmt == NULL) |
| 2424 | return -1; |
| 2425 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2426 | return 0; |
| 2427 | } |
| 2428 | |
| 2429 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2430 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2431 | { |
| 2432 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2433 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2434 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2438 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2439 | const u8 *match, size_t match_len) |
| 2440 | { |
| 2441 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2442 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2443 | type, match, match_len, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2447 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2448 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2449 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2450 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2451 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2452 | |
| 2453 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2454 | return -1; |
| 2455 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2456 | "handle %p", bss->nl_mgmt); |
| 2457 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2458 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2459 | /* register for any AUTH message */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2460 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2461 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2462 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 2463 | /* register for SAE Authentication frames */ |
| 2464 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2465 | (u8 *) "\x03\x00", 2, false); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2468 | #ifdef CONFIG_PASN |
| 2469 | /* register for PASN Authentication frames */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2470 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2471 | (u8 *) "\x07\x00", 2, false)) |
| 2472 | ret = -1; |
| 2473 | #endif /* CONFIG_PASN */ |
| 2474 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2475 | #ifdef CONFIG_INTERWORKING |
| 2476 | /* QoS Map Configure */ |
| 2477 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2478 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2479 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2480 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2481 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2482 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2483 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2484 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2485 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2486 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2487 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2488 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2489 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2490 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2491 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2492 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2493 | /* Protected GAS Initial Request */ |
| 2494 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2495 | ret = -1; |
| 2496 | /* Protected GAS Initial Response */ |
| 2497 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2498 | ret = -1; |
| 2499 | /* Protected GAS Comeback Request */ |
| 2500 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2501 | ret = -1; |
| 2502 | /* Protected GAS Comeback Response */ |
| 2503 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2504 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2505 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2506 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2507 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2508 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2510 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2511 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2512 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2513 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2514 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2515 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2516 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2518 | #ifdef CONFIG_DPP |
| 2519 | /* DPP Public Action */ |
| 2520 | if (nl80211_register_action_frame(bss, |
| 2521 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2522 | 6) < 0) |
| 2523 | ret = -1; |
| 2524 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2525 | #ifdef CONFIG_OCV |
| 2526 | /* SA Query Request */ |
| 2527 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2528 | ret = -1; |
| 2529 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2531 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2532 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2533 | #ifdef CONFIG_TDLS |
| 2534 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2535 | /* TDLS Discovery Response */ |
| 2536 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2537 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2538 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2539 | } |
| 2540 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2541 | #ifdef CONFIG_FST |
| 2542 | /* FST Action frames */ |
| 2543 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2544 | ret = -1; |
| 2545 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2546 | |
| 2547 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2548 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2549 | ret = -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2550 | else if (!drv->has_driver_key_mgmt) { |
| 2551 | int i; |
| 2552 | |
| 2553 | /* Update supported AKMs only if the driver doesn't advertize |
| 2554 | * any AKM capabilities. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2555 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2556 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2557 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2558 | /* Update per interface supported AKMs */ |
| 2559 | for (i = 0; i < WPA_IF_MAX; i++) |
| 2560 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; |
| 2561 | } |
| 2562 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2563 | /* WNM - BSS Transition Management Request */ |
| 2564 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2565 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2566 | /* WNM-Sleep Mode Response */ |
| 2567 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2568 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2569 | #ifdef CONFIG_WNM |
| 2570 | /* WNM - Collocated Interference Request */ |
| 2571 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2572 | ret = -1; |
| 2573 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2574 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2575 | #ifdef CONFIG_HS20 |
| 2576 | /* WNM-Notification */ |
| 2577 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2578 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2579 | #endif /* CONFIG_HS20 */ |
| 2580 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2581 | /* WMM-AC ADDTS Response */ |
| 2582 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2583 | ret = -1; |
| 2584 | |
| 2585 | /* WMM-AC DELTS */ |
| 2586 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2587 | ret = -1; |
| 2588 | |
| 2589 | /* Radio Measurement - Neighbor Report Response */ |
| 2590 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2591 | ret = -1; |
| 2592 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2593 | /* Radio Measurement - Radio Measurement Request */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2594 | if (!drv->no_rrm && |
| 2595 | nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2596 | ret = -1; |
| 2597 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2598 | /* Radio Measurement - Link Measurement Request */ |
| 2599 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2600 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2601 | ret = -1; |
| 2602 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2603 | /* Robust AV SCS Response */ |
| 2604 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x01", 2) < 0) |
| 2605 | ret = -1; |
| 2606 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2607 | /* Robust AV MSCS Response */ |
| 2608 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0) |
| 2609 | ret = -1; |
| 2610 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2611 | /* Protected QoS Management Action frame */ |
| 2612 | if (nl80211_register_action_frame(bss, (u8 *) "\x7e\x50\x6f\x9a\x1a", |
| 2613 | 5) < 0) |
| 2614 | ret = -1; |
| 2615 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2616 | nl80211_mgmt_handle_register_eloop(bss); |
| 2617 | |
| 2618 | return ret; |
| 2619 | } |
| 2620 | |
| 2621 | |
| 2622 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2623 | { |
| 2624 | int ret = 0; |
| 2625 | |
| 2626 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2627 | return -1; |
| 2628 | |
| 2629 | wpa_printf(MSG_DEBUG, |
| 2630 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2631 | bss->nl_mgmt); |
| 2632 | |
| 2633 | /* Auth frames for mesh SAE */ |
| 2634 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2635 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2636 | (WLAN_FC_STYPE_AUTH << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2637 | NULL, 0, false) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2638 | ret = -1; |
| 2639 | |
| 2640 | /* Mesh peering open */ |
| 2641 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2642 | ret = -1; |
| 2643 | /* Mesh peering confirm */ |
| 2644 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2645 | ret = -1; |
| 2646 | /* Mesh peering close */ |
| 2647 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2648 | ret = -1; |
| 2649 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2650 | nl80211_mgmt_handle_register_eloop(bss); |
| 2651 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2652 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2656 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2657 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2658 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2659 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2661 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2662 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL, |
| 2663 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2664 | if (ret) { |
| 2665 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2666 | "failed: ret=%d (%s)", |
| 2667 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2668 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2669 | return ret; |
| 2670 | } |
| 2671 | |
| 2672 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2673 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2674 | { |
| 2675 | int ret = 0; |
| 2676 | |
| 2677 | /* Public Action frames */ |
| 2678 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2679 | ret = -1; |
| 2680 | /* RRM Measurement Report */ |
| 2681 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2682 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2683 | /* RRM Link Measurement Report */ |
| 2684 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2685 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2686 | /* RRM Neighbor Report Request */ |
| 2687 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2688 | ret = -1; |
| 2689 | /* FT Action frames */ |
| 2690 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2691 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2692 | /* SA Query */ |
| 2693 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2694 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2695 | /* Protected Dual of Public Action */ |
| 2696 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2697 | ret = -1; |
| 2698 | /* WNM */ |
| 2699 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2700 | ret = -1; |
| 2701 | /* WMM */ |
| 2702 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2703 | ret = -1; |
| 2704 | #ifdef CONFIG_FST |
| 2705 | /* FST Action frames */ |
| 2706 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2707 | ret = -1; |
| 2708 | #endif /* CONFIG_FST */ |
| 2709 | /* Vendor-specific */ |
| 2710 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2711 | ret = -1; |
| 2712 | |
| 2713 | return ret; |
| 2714 | } |
| 2715 | |
| 2716 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2717 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2718 | { |
| 2719 | static const int stypes[] = { |
| 2720 | WLAN_FC_STYPE_AUTH, |
| 2721 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2722 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2723 | WLAN_FC_STYPE_DISASSOC, |
| 2724 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2725 | WLAN_FC_STYPE_PROBE_REQ, |
| 2726 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2727 | * it, but it wouldn't really be the right thing anyway as |
| 2728 | * it isn't per interface ... maybe just dump the scan |
| 2729 | * results periodically for OLBC? |
| 2730 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2731 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2732 | }; |
| 2733 | unsigned int i; |
| 2734 | |
| 2735 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2736 | return -1; |
| 2737 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2738 | "handle %p", bss->nl_mgmt); |
| 2739 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2740 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2741 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2742 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2743 | (stypes[i] << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2744 | NULL, 0, false) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2745 | goto out_err; |
| 2746 | } |
| 2747 | } |
| 2748 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2749 | if (nl80211_action_subscribe_ap(bss)) |
| 2750 | goto out_err; |
| 2751 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2752 | if (nl80211_register_spurious_class3(bss)) |
| 2753 | goto out_err; |
| 2754 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2755 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2756 | return 0; |
| 2757 | |
| 2758 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2759 | nl_destroy_handles(&bss->nl_mgmt); |
| 2760 | return -1; |
| 2761 | } |
| 2762 | |
| 2763 | |
| 2764 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2765 | { |
| 2766 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2767 | return -1; |
| 2768 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2769 | "handle %p (device SME)", bss->nl_mgmt); |
| 2770 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2771 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2772 | goto out_err; |
| 2773 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2774 | if (bss->drv->device_ap_sme) { |
| 2775 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2776 | |
| 2777 | /* Register for all Authentication frames */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2778 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, |
| 2779 | false) < 0) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2780 | wpa_printf(MSG_DEBUG, |
| 2781 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2782 | } |
| 2783 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2784 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2785 | return 0; |
| 2786 | |
| 2787 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2788 | nl_destroy_handles(&bss->nl_mgmt); |
| 2789 | return -1; |
| 2790 | } |
| 2791 | |
| 2792 | |
| 2793 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2794 | { |
| 2795 | if (bss->nl_mgmt == NULL) |
| 2796 | return; |
| 2797 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2798 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2799 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2800 | |
| 2801 | nl80211_put_wiphy_data_ap(bss); |
| 2802 | } |
| 2803 | |
| 2804 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2805 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2806 | { |
| 2807 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2808 | } |
| 2809 | |
| 2810 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2811 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2812 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2813 | struct nl_msg *msg; |
| 2814 | int ret; |
| 2815 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2816 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2817 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2818 | |
| 2819 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2820 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2821 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | |
| 2825 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2826 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2827 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2828 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2829 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2830 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2831 | NL80211_CMD_STOP_P2P_DEVICE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2832 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2833 | |
| 2834 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2835 | start ? "Start" : "Stop", |
| 2836 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2837 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2838 | return ret; |
| 2839 | } |
| 2840 | |
| 2841 | |
| 2842 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2843 | { |
| 2844 | enum nl80211_iftype nlmode; |
| 2845 | |
| 2846 | nlmode = nl80211_get_ifmode(bss); |
| 2847 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2848 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2849 | bss->ifname, up); |
| 2850 | } |
| 2851 | |
| 2852 | /* P2P Device has start/stop which is equivalent */ |
| 2853 | return nl80211_set_p2pdev(bss, up); |
| 2854 | } |
| 2855 | |
| 2856 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2857 | #ifdef CONFIG_TESTING_OPTIONS |
| 2858 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2859 | { |
| 2860 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2861 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2862 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2863 | |
| 2864 | |
| 2865 | wpa_printf(MSG_DEBUG, |
| 2866 | "nl80211: QCA vendor test command response received"); |
| 2867 | |
| 2868 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2869 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2870 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2871 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2872 | return NL_SKIP; |
| 2873 | } |
| 2874 | |
| 2875 | wpa_hexdump(MSG_DEBUG, |
| 2876 | "nl80211: Received QCA vendor test command response", |
| 2877 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2878 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2879 | |
| 2880 | return NL_SKIP; |
| 2881 | } |
| 2882 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2883 | |
| 2884 | |
| 2885 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2886 | { |
| 2887 | #ifdef CONFIG_TESTING_OPTIONS |
| 2888 | struct nl_msg *msg; |
| 2889 | struct nlattr *params; |
| 2890 | int ret; |
| 2891 | |
| 2892 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2893 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2894 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2895 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2896 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2897 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2898 | nlmsg_free(msg); |
| 2899 | return; |
| 2900 | } |
| 2901 | nla_nest_end(msg, params); |
| 2902 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2903 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv, |
| 2904 | NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2905 | wpa_printf(MSG_DEBUG, |
| 2906 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2907 | ret, strerror(-ret)); |
| 2908 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2909 | } |
| 2910 | |
| 2911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2912 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2913 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2914 | const u8 *set_addr, int first, |
| 2915 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2916 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2917 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2918 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2919 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | |
| 2921 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2922 | bss->ifindex = drv->ifindex; |
| 2923 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2924 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2925 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2926 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2927 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2928 | drv->global->if_add_wdevid_set = 0; |
| 2929 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2930 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2931 | bss->static_ap = 1; |
| 2932 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2933 | if (first && |
| 2934 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2935 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2936 | drv->start_iface_up = 1; |
| 2937 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2938 | if (wpa_driver_nl80211_capa(drv)) |
| 2939 | return -1; |
| 2940 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2941 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2942 | return -1; |
| 2943 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2944 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2945 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2947 | if (set_addr && |
| 2948 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2949 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2950 | set_addr))) |
| 2951 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2952 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2953 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_STATION) |
| 2954 | drv->start_mode_sta = 1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2955 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2956 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2957 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2958 | else if (bss->if_dynamic || |
| 2959 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2960 | nlmode = nl80211_get_ifmode(bss); |
| 2961 | else |
| 2962 | nlmode = NL80211_IFTYPE_STATION; |
| 2963 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2964 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2965 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2966 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2967 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2968 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2969 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2970 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2972 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2973 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2974 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2975 | int ret = i802_set_iface_flags(bss, 1); |
| 2976 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2978 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2979 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2980 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2981 | |
| 2982 | if (is_p2p_net_interface(nlmode)) |
| 2983 | nl80211_disable_11b_rates(bss->drv, |
| 2984 | bss->drv->ifindex, 1); |
| 2985 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2986 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2987 | return ret; |
| 2988 | } else { |
| 2989 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2990 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2991 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2992 | drv->if_disabled = 1; |
| 2993 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2994 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2997 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2998 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2999 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3000 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3001 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 3002 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3003 | bss->addr)) |
| 3004 | return -1; |
| 3005 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 3006 | } |
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 | if (send_rfkill_event) { |
| 3009 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 3010 | drv, drv->ctx); |
| 3011 | } |
| 3012 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3013 | if (drv->vendor_cmd_test_avail) |
| 3014 | qca_vendor_test(drv); |
| 3015 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3016 | return 0; |
| 3017 | } |
| 3018 | |
| 3019 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3020 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3021 | { |
| 3022 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3023 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3024 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3025 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 3026 | drv->ifindex); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3027 | bss->beacon_set = 0; |
| 3028 | bss->freq = 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3029 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3030 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3031 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | |
| 3035 | /** |
| 3036 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3037 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3038 | * |
| 3039 | * Shut down driver interface and processing of driver events. Free |
| 3040 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 3041 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3042 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3043 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3044 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3045 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3047 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 3048 | bss->ifname, drv->disabled_11b_rates); |
| 3049 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3050 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3051 | if (drv->data_tx_status) |
| 3052 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 3053 | if (drv->eapol_tx_sock >= 0) |
| 3054 | close(drv->eapol_tx_sock); |
| 3055 | |
| 3056 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3057 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3058 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3059 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 3060 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3061 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3062 | "interface %s from bridge %s: %s", |
| 3063 | bss->ifname, bss->brname, strerror(errno)); |
| 3064 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3065 | |
| 3066 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3067 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 3068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3070 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 3071 | 0) < 0) |
| 3072 | wpa_printf(MSG_INFO, |
| 3073 | "nl80211: Could not set bridge %s down", |
| 3074 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3075 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3076 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3077 | "bridge %s: %s", |
| 3078 | bss->brname, strerror(errno)); |
| 3079 | } |
| 3080 | |
| 3081 | nl80211_remove_monitor_interface(drv); |
| 3082 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3083 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3084 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3085 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3086 | if (drv->eapol_sock >= 0) { |
| 3087 | eloop_unregister_read_sock(drv->eapol_sock); |
| 3088 | close(drv->eapol_sock); |
| 3089 | } |
| 3090 | |
| 3091 | if (drv->if_indices != drv->default_if_indices) |
| 3092 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3094 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3095 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3096 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3097 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 3098 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3099 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3100 | rfkill_deinit(drv->rfkill); |
| 3101 | |
| 3102 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3103 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3104 | if (!drv->start_iface_up) |
| 3105 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3106 | |
| 3107 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3108 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 3109 | 0) < 0) { |
| 3110 | wpa_printf(MSG_DEBUG, |
| 3111 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 3112 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3113 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3114 | drv->perm_addr) < 0) { |
| 3115 | wpa_printf(MSG_DEBUG, |
| 3116 | "nl80211: Could not restore permanent MAC address"); |
| 3117 | } |
| 3118 | } |
| 3119 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3120 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3121 | if (drv->start_mode_sta) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3122 | wpa_driver_nl80211_set_mode(bss, |
| 3123 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3124 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3125 | } else { |
| 3126 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 3127 | nl80211_del_p2pdev(bss); |
| 3128 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3129 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3130 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3131 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3132 | os_free(drv->filter_ssids); |
| 3133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3134 | os_free(drv->auth_ie); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3135 | os_free(drv->auth_data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3136 | |
| 3137 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3138 | dl_list_del(&drv->list); |
| 3139 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3140 | os_free(drv->extended_capa); |
| 3141 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3142 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 3143 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 3144 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 3145 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3146 | os_free(drv->first_bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3147 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 3148 | os_free(drv->pending_roam_data); |
| 3149 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3150 | os_free(drv); |
| 3151 | } |
| 3152 | |
| 3153 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3154 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 3155 | { |
| 3156 | switch (alg) { |
| 3157 | case WPA_ALG_WEP: |
| 3158 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3159 | return RSN_CIPHER_SUITE_WEP40; |
| 3160 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3161 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3162 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3163 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3164 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3165 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3166 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3167 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3168 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3169 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3170 | return RSN_CIPHER_SUITE_GCMP_256; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3171 | case WPA_ALG_BIP_CMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3172 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3173 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3174 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3175 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3176 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3177 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3178 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3179 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3180 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3181 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3182 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3183 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3184 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 3185 | alg); |
| 3186 | return 0; |
| 3187 | } |
| 3188 | |
| 3189 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 3190 | alg); |
| 3191 | return 0; |
| 3192 | } |
| 3193 | |
| 3194 | |
| 3195 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 3196 | { |
| 3197 | switch (cipher) { |
| 3198 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3199 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3200 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3201 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3202 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3203 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3204 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3205 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3206 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3207 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3208 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3209 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3210 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3211 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3212 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3213 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | return 0; |
| 3217 | } |
| 3218 | |
| 3219 | |
| 3220 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 3221 | int max_suites) |
| 3222 | { |
| 3223 | int num_suites = 0; |
| 3224 | |
| 3225 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3226 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3227 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3228 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3229 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3230 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3231 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3232 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3233 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3234 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3235 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3236 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3237 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3238 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3239 | |
| 3240 | return num_suites; |
| 3241 | } |
| 3242 | |
| 3243 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3244 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3245 | int max_suites) |
| 3246 | { |
| 3247 | int num_suites = 0; |
| 3248 | |
| 3249 | #define __AKM(a, b) \ |
| 3250 | if (num_suites < max_suites && \ |
| 3251 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3252 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3253 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 3254 | __AKM(PSK, PSK_OVER_802_1X); |
| 3255 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 3256 | __AKM(FT_PSK, FT_PSK); |
| 3257 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 3258 | __AKM(PSK_SHA256, PSK_SHA256); |
| 3259 | __AKM(SAE, SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3260 | __AKM(SAE_EXT_KEY, SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3261 | __AKM(FT_SAE, FT_SAE); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3262 | __AKM(FT_SAE_EXT_KEY, FT_SAE_EXT_KEY); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3263 | __AKM(CCKM, CCKM); |
| 3264 | __AKM(OSEN, OSEN); |
| 3265 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 3266 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 3267 | __AKM(FILS_SHA256, FILS_SHA256); |
| 3268 | __AKM(FILS_SHA384, FILS_SHA384); |
| 3269 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 3270 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 3271 | __AKM(OWE, OWE); |
| 3272 | __AKM(DPP, DPP); |
| 3273 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
| 3274 | #undef __AKM |
| 3275 | |
| 3276 | return num_suites; |
| 3277 | } |
| 3278 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3279 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3280 | static int wpa_driver_do_broadcom_acs(struct wpa_driver_nl80211_data *drv, |
| 3281 | struct drv_acs_params *params) |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3282 | { |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3283 | struct nl_msg *msg; |
| 3284 | struct nlattr *data; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3285 | int freq_list_len; |
| 3286 | int ret = -1; |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3287 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3288 | freq_list_len = int_array_len(params->freq_list); |
| 3289 | wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d", |
| 3290 | __func__, freq_list_len); |
| 3291 | |
| 3292 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 3293 | if (!msg || |
| 3294 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3295 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3296 | BRCM_VENDOR_SCMD_ACS) || |
| 3297 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3298 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode) || |
| 3299 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED, |
| 3300 | params->ht_enabled) || |
| 3301 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED, |
| 3302 | params->ht40_enabled) || |
| 3303 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED, |
| 3304 | params->vht_enabled) || |
| 3305 | nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width) || |
| 3306 | (freq_list_len > 0 && |
| 3307 | nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST, |
| 3308 | sizeof(int) * freq_list_len, params->freq_list))) |
| 3309 | goto fail; |
| 3310 | nla_nest_end(msg, data); |
| 3311 | |
| 3312 | wpa_printf(MSG_DEBUG, |
| 3313 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d", |
| 3314 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 3315 | params->vht_enabled, params->ch_width); |
| 3316 | |
| 3317 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 3318 | if (ret) { |
| 3319 | wpa_printf(MSG_ERROR, |
| 3320 | "nl80211: BRCM Failed to invoke driver ACS function: %s", |
| 3321 | strerror(errno)); |
| 3322 | } |
| 3323 | |
| 3324 | msg = NULL; |
| 3325 | fail: |
| 3326 | nlmsg_free(msg); |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3327 | return ret; |
| 3328 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3329 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3330 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 3331 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3332 | static int wpa_cross_akm_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3333 | int max_suites) |
| 3334 | { |
| 3335 | int num_suites = 0; |
| 3336 | |
| 3337 | #define __AKM_TO_SUITES_ARRAY(a, b) \ |
| 3338 | if (num_suites < max_suites && \ |
| 3339 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3340 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3341 | __AKM_TO_SUITES_ARRAY(PSK, PSK_OVER_802_1X); |
| 3342 | __AKM_TO_SUITES_ARRAY(SAE, SAE); |
| 3343 | #undef __AKM_TO_SUITES_ARRAY |
| 3344 | |
| 3345 | return num_suites; |
| 3346 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 3347 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3348 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3349 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3350 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3351 | const u8 *key, size_t key_len) |
| 3352 | { |
| 3353 | struct nl_msg *msg; |
| 3354 | int ret; |
| 3355 | |
| 3356 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 3357 | return 0; |
| 3358 | |
| 3359 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3360 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3361 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3362 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 3363 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 3364 | nl80211_nlmsg_clear(msg); |
| 3365 | nlmsg_free(msg); |
| 3366 | return -1; |
| 3367 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3368 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3369 | if (ret) { |
| 3370 | wpa_printf(MSG_DEBUG, |
| 3371 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3372 | ret, strerror(-ret)); |
| 3373 | } |
| 3374 | |
| 3375 | return ret; |
| 3376 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3377 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3378 | |
| 3379 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3380 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3381 | static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3382 | const u8 *key, size_t key_len) |
| 3383 | { |
| 3384 | struct nl_msg *msg; |
| 3385 | int ret; |
| 3386 | struct nlattr *params; |
| 3387 | |
| 3388 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3389 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3390 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3391 | BRCM_VENDOR_SCMD_SET_PMK) || |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3392 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3393 | nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) { |
| 3394 | nl80211_nlmsg_clear(msg); |
| 3395 | nlmsg_free(msg); |
| 3396 | return -ENOBUFS; |
| 3397 | } |
| 3398 | nla_nest_end(msg, params); |
| 3399 | |
| 3400 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 3401 | if (ret) { |
| 3402 | wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)", |
| 3403 | ret, strerror(-ret)); |
| 3404 | } |
| 3405 | |
| 3406 | return ret; |
| 3407 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3408 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3409 | |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3410 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3411 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3412 | const u8 *key, size_t key_len, |
| 3413 | const u8 *addr) |
| 3414 | { |
| 3415 | struct nl_msg *msg = NULL; |
| 3416 | int ret; |
| 3417 | |
| 3418 | /* |
| 3419 | * If the authenticator address is not set, assume it is |
| 3420 | * the current BSSID. |
| 3421 | */ |
| 3422 | if (!addr && drv->associated) |
| 3423 | addr = drv->bssid; |
| 3424 | else if (!addr) |
| 3425 | return -1; |
| 3426 | |
| 3427 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3428 | MAC2STR(addr)); |
| 3429 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3430 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3431 | if (!msg || |
| 3432 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3433 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3434 | nl80211_nlmsg_clear(msg); |
| 3435 | nlmsg_free(msg); |
| 3436 | return -ENOBUFS; |
| 3437 | } |
| 3438 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3439 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3440 | if (ret) { |
| 3441 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3442 | ret, strerror(-ret)); |
| 3443 | } |
| 3444 | |
| 3445 | return ret; |
| 3446 | } |
| 3447 | |
| 3448 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3449 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3450 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3451 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3452 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3453 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3454 | struct nl_msg *msg; |
| 3455 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3456 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3457 | int skip_set_key = 1; |
| 3458 | const char *ifname = params->ifname; |
| 3459 | enum wpa_alg alg = params->alg; |
| 3460 | const u8 *addr = params->addr; |
| 3461 | int key_idx = params->key_idx; |
| 3462 | int set_tx = params->set_tx; |
| 3463 | const u8 *seq = params->seq; |
| 3464 | size_t seq_len = params->seq_len; |
| 3465 | const u8 *key = params->key; |
| 3466 | size_t key_len = params->key_len; |
| 3467 | int vlan_id = params->vlan_id; |
| 3468 | enum key_flag key_flag = params->key_flag; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3469 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3470 | /* Ignore for P2P Device */ |
| 3471 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3472 | return 0; |
| 3473 | |
| 3474 | ifindex = if_nametoindex(ifname); |
| 3475 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3476 | "set_tx=%d seq_len=%lu key_len=%lu key_flag=0x%x", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3477 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3478 | (unsigned long) seq_len, (unsigned long) key_len, key_flag); |
| 3479 | |
| 3480 | if (check_key_flag(key_flag)) { |
| 3481 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3482 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3483 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3484 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3485 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3486 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3487 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3488 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3489 | __func__); |
| 3490 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3491 | return ret; |
| 3492 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3493 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3494 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3495 | if (key_flag & KEY_FLAG_PMK) { |
| 3496 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3497 | return nl80211_set_pmk(drv, key, key_len, addr); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3498 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3499 | if (drv->vendor_set_pmk) { |
Jay Patel | 731adae | 2021-02-17 14:55:58 -0800 | [diff] [blame] | 3500 | 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] | 3501 | return key_mgmt_set_key(drv, key, key_len); |
| 3502 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3503 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3504 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3505 | /* The driver does not have any offload mechanism for PMK, so |
| 3506 | * there is no need to configure this key. */ |
| 3507 | return 0; |
| 3508 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3509 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3510 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3511 | key_msg = nlmsg_alloc(); |
| 3512 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3513 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3514 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3515 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3516 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3517 | wpa_printf(MSG_DEBUG, |
| 3518 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3519 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3520 | if (!msg) |
| 3521 | goto fail2; |
| 3522 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3523 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3524 | __func__); |
| 3525 | ret = -EINVAL; |
| 3526 | goto fail2; |
| 3527 | } else if (alg == WPA_ALG_NONE) { |
| 3528 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3529 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3530 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3531 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3532 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3533 | u32 suite; |
| 3534 | |
| 3535 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3536 | if (!suite) { |
| 3537 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3538 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3539 | } |
| 3540 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3541 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3542 | if (!msg) |
| 3543 | goto fail2; |
| 3544 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3545 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3546 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3547 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3548 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3549 | if (seq && seq_len) { |
| 3550 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3551 | goto fail; |
| 3552 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3553 | seq, seq_len); |
| 3554 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3555 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3556 | |
| 3557 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3558 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3559 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3560 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3561 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3562 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3563 | KEY_FLAG_PAIRWISE_RX || |
| 3564 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3565 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3566 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3567 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3568 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3569 | goto fail; |
| 3570 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3571 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3572 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3573 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3574 | NL80211_KEYTYPE_GROUP)) |
| 3575 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3576 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3577 | wpa_printf(MSG_DEBUG, |
| 3578 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3579 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3580 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3581 | } else if (alg == WPA_ALG_WEP && |
| 3582 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3583 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3584 | skip_set_key = 0; |
| 3585 | } else { |
| 3586 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3587 | } |
| 3588 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3589 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3590 | wpa_printf(MSG_DEBUG, |
| 3591 | " invalid key_flag for a broadcast key"); |
| 3592 | ret = -EINVAL; |
| 3593 | goto fail; |
| 3594 | } else { |
| 3595 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3596 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3597 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3598 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3599 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3600 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3601 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3602 | nl80211_nlmsg_clear(key_msg); |
| 3603 | nlmsg_free(key_msg); |
| 3604 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3605 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3606 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3607 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3608 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3609 | goto fail; |
| 3610 | } |
| 3611 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3612 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3613 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3614 | ret = 0; |
| 3615 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3616 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3617 | ret, strerror(-ret)); |
| 3618 | |
| 3619 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3620 | * 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] | 3621 | * we're done here. |
| 3622 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3623 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3624 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3625 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3626 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3627 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3628 | key_msg = nlmsg_alloc(); |
| 3629 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3630 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3631 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3632 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3633 | if (!msg) |
| 3634 | goto fail2; |
| 3635 | if (!key_msg || |
| 3636 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3637 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3638 | (key_idx == 6 || key_idx == 7 ? |
| 3639 | NL80211_KEY_DEFAULT_BEACON : |
| 3640 | NL80211_KEY_DEFAULT_MGMT) : |
| 3641 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3642 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3643 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3644 | struct nlattr *types; |
| 3645 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3646 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3647 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3648 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3649 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3650 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3651 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3652 | struct nlattr *types; |
| 3653 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3654 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3655 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3656 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3657 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3658 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3661 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3662 | goto fail; |
| 3663 | nl80211_nlmsg_clear(key_msg); |
| 3664 | nlmsg_free(key_msg); |
| 3665 | key_msg = NULL; |
| 3666 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3667 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3668 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3669 | vlan_id); |
| 3670 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3671 | goto fail; |
| 3672 | } |
| 3673 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3674 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3675 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3676 | wpa_printf(MSG_DEBUG, |
| 3677 | "nl80211: set_key default failed; err=%d %s", |
| 3678 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3679 | return ret; |
| 3680 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3681 | fail: |
| 3682 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3683 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3684 | fail2: |
| 3685 | nl80211_nlmsg_clear(key_msg); |
| 3686 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3687 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | |
| 3691 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3692 | int key_idx, int defkey, |
| 3693 | const u8 *seq, size_t seq_len, |
| 3694 | const u8 *key, size_t key_len) |
| 3695 | { |
| 3696 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3697 | u32 suite; |
| 3698 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3699 | if (!key_attr) |
| 3700 | return -1; |
| 3701 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3702 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3703 | if (!suite) |
| 3704 | return -1; |
| 3705 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3706 | if (defkey && wpa_alg_bip(alg)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3707 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3708 | return -1; |
| 3709 | } else if (defkey) { |
| 3710 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3711 | return -1; |
| 3712 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3713 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3714 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3715 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3716 | (seq && seq_len && |
| 3717 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3718 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3719 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3720 | |
| 3721 | nla_nest_end(msg, key_attr); |
| 3722 | |
| 3723 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | |
| 3727 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3728 | struct nl_msg *msg) |
| 3729 | { |
| 3730 | int i, privacy = 0; |
| 3731 | struct nlattr *nl_keys, *nl_key; |
| 3732 | |
| 3733 | for (i = 0; i < 4; i++) { |
| 3734 | if (!params->wep_key[i]) |
| 3735 | continue; |
| 3736 | privacy = 1; |
| 3737 | break; |
| 3738 | } |
| 3739 | if (params->wps == WPS_MODE_PRIVACY) |
| 3740 | privacy = 1; |
| 3741 | if (params->pairwise_suite && |
| 3742 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3743 | privacy = 1; |
| 3744 | |
| 3745 | if (!privacy) |
| 3746 | return 0; |
| 3747 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3748 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3749 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3750 | |
| 3751 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3752 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3753 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3754 | |
| 3755 | for (i = 0; i < 4; i++) { |
| 3756 | if (!params->wep_key[i]) |
| 3757 | continue; |
| 3758 | |
| 3759 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3760 | if (!nl_key || |
| 3761 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3762 | params->wep_key[i]) || |
| 3763 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3764 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3765 | RSN_CIPHER_SUITE_WEP40 : |
| 3766 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3767 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3768 | (i == params->wep_tx_keyidx && |
| 3769 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3770 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3771 | |
| 3772 | nla_nest_end(msg, nl_key); |
| 3773 | } |
| 3774 | nla_nest_end(msg, nl_keys); |
| 3775 | |
| 3776 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3780 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3781 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3782 | int local_state_change, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3783 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3784 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3785 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3786 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3787 | struct nl_sock *nl_connect = get_connect_handle(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3789 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3790 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3791 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3792 | (local_state_change && |
| 3793 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3794 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3795 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3796 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3797 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3798 | if (nl_connect) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3799 | ret = send_and_recv(drv->global, nl_connect, msg, |
| 3800 | process_bss_event, bss, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3801 | else |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3802 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3803 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3804 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3805 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3806 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3807 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3808 | return ret; |
| 3809 | } |
| 3810 | |
| 3811 | |
| 3812 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3813 | u16 reason_code, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3814 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3815 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3816 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3817 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3818 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3819 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3820 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3821 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3822 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3823 | reason_code, 0, bss); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3824 | /* |
| 3825 | * For locally generated disconnect, supplicant already generates a |
| 3826 | * DEAUTH event, so ignore the event from NL80211. |
| 3827 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3828 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3829 | |
| 3830 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3834 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3835 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3836 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3838 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3839 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3840 | |
| 3841 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3842 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3843 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3844 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3845 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3846 | return wpa_driver_nl80211_disconnect(drv, reason_code, bss); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3847 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3848 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3849 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3850 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3851 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3852 | reason_code, 0, bss); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3853 | /* |
| 3854 | * For locally generated deauthenticate, supplicant already generates a |
| 3855 | * DEAUTH event, so ignore the event from NL80211. |
| 3856 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3857 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3858 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3859 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3863 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3864 | struct wpa_driver_auth_params *params) |
| 3865 | { |
| 3866 | int i; |
| 3867 | |
| 3868 | drv->auth_freq = params->freq; |
| 3869 | drv->auth_alg = params->auth_alg; |
| 3870 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3871 | drv->auth_local_state_change = params->local_state_change; |
| 3872 | drv->auth_p2p = params->p2p; |
| 3873 | |
| 3874 | if (params->bssid) |
| 3875 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3876 | else |
| 3877 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3878 | |
| 3879 | if (params->ssid) { |
| 3880 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3881 | drv->auth_ssid_len = params->ssid_len; |
| 3882 | } else |
| 3883 | drv->auth_ssid_len = 0; |
| 3884 | |
| 3885 | |
| 3886 | os_free(drv->auth_ie); |
| 3887 | drv->auth_ie = NULL; |
| 3888 | drv->auth_ie_len = 0; |
| 3889 | if (params->ie) { |
| 3890 | drv->auth_ie = os_malloc(params->ie_len); |
| 3891 | if (drv->auth_ie) { |
| 3892 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3893 | drv->auth_ie_len = params->ie_len; |
| 3894 | } |
| 3895 | } |
| 3896 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3897 | os_free(drv->auth_data); |
| 3898 | drv->auth_data = NULL; |
| 3899 | drv->auth_data_len = 0; |
| 3900 | if (params->auth_data) { |
| 3901 | drv->auth_data = os_memdup(params->auth_data, |
| 3902 | params->auth_data_len); |
| 3903 | if (drv->auth_data) |
| 3904 | drv->auth_data_len = params->auth_data_len; |
| 3905 | } |
| 3906 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3907 | for (i = 0; i < 4; i++) { |
| 3908 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3909 | params->wep_key_len[i] <= 16) { |
| 3910 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3911 | params->wep_key_len[i]); |
| 3912 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3913 | } else |
| 3914 | drv->auth_wep_key_len[i] = 0; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3919 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3920 | { |
| 3921 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3922 | |
| 3923 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3924 | return; |
| 3925 | |
| 3926 | /* |
| 3927 | * Looks like we failed to unmask 11b rates previously. This could |
| 3928 | * happen, e.g., if the interface was down at the point in time when a |
| 3929 | * P2P group was terminated. |
| 3930 | */ |
| 3931 | wpa_printf(MSG_DEBUG, |
| 3932 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3933 | bss->ifname); |
| 3934 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3935 | } |
| 3936 | |
| 3937 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3938 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3939 | { |
| 3940 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3941 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3942 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3943 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3944 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3945 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3946 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3947 | return NL80211_AUTHTYPE_FT; |
| 3948 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3949 | return NL80211_AUTHTYPE_SAE; |
| 3950 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3951 | return NL80211_AUTHTYPE_FILS_SK; |
| 3952 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3953 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3954 | |
| 3955 | return NL80211_AUTHTYPE_MAX; |
| 3956 | } |
| 3957 | |
| 3958 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3959 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3960 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3961 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3962 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3963 | int ret = -1, i; |
| 3964 | struct nl_msg *msg; |
| 3965 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3966 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3967 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3968 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3969 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3970 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3971 | nl80211_unmask_11b_rates(bss); |
| 3972 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3973 | is_retry = drv->retry_auth; |
| 3974 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3975 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3976 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3977 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3978 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3979 | if (params->bssid) |
| 3980 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3981 | else |
| 3982 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3983 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3984 | nlmode = params->p2p ? |
| 3985 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3986 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3987 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3988 | return -1; |
| 3989 | |
| 3990 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3991 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3992 | drv->ifindex); |
| 3993 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3994 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3995 | if (!msg) |
| 3996 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3997 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3998 | os_memset(&p, 0, sizeof(p)); |
| 3999 | p.ifname = bss->ifname; |
| 4000 | p.alg = WPA_ALG_WEP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4001 | for (i = 0; i < 4; i++) { |
| 4002 | if (!params->wep_key[i]) |
| 4003 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4004 | p.key_idx = i; |
| 4005 | p.set_tx = i == params->wep_tx_keyidx; |
| 4006 | p.key = params->wep_key[i]; |
| 4007 | p.key_len = params->wep_key_len[i]; |
| 4008 | p.key_flag = i == params->wep_tx_keyidx ? |
| 4009 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 4010 | KEY_FLAG_GROUP_RX_TX; |
| 4011 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4012 | if (params->wep_tx_keyidx != i) |
| 4013 | continue; |
| 4014 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4015 | params->wep_key[i], params->wep_key_len[i])) |
| 4016 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4019 | if (params->bssid) { |
| 4020 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4021 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4022 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4023 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4024 | } |
| 4025 | if (params->freq) { |
| 4026 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 4028 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4029 | } |
| 4030 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4031 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 4032 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4033 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4034 | params->ssid)) |
| 4035 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4036 | } |
| 4037 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4038 | if (params->ie && |
| 4039 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 4040 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4041 | if (params->auth_data) { |
| 4042 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 4043 | params->auth_data_len); |
| 4044 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 4045 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4046 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4047 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4048 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4049 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4050 | if (type == NL80211_AUTHTYPE_MAX || |
| 4051 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4052 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4053 | if (params->local_state_change) { |
| 4054 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4055 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 4056 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4162 | |
| 4163 | for (i = 0; i < 4; i++) { |
| 4164 | if (drv->auth_wep_key_len[i]) { |
| 4165 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 4166 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | drv->retry_auth = 1; |
| 4171 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 4172 | } |
| 4173 | |
| 4174 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4175 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 4176 | size_t data_len, int noack, |
| 4177 | unsigned int freq, int no_cck, |
| 4178 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4179 | unsigned int wait_time, |
| 4180 | const u16 *csa_offs, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4181 | size_t csa_offs_len, int no_encrypt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4182 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4183 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4184 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4185 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4186 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4187 | int use_cookie = 1; |
| 4188 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4189 | |
| 4190 | mgmt = (struct ieee80211_mgmt *) data; |
| 4191 | fc = le_to_host16(mgmt->frame_control); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4192 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR |
| 4193 | " 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] | 4194 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4195 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4196 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4197 | if ((is_sta_interface(drv->nlmode) || |
| 4198 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4199 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4200 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 4201 | /* |
| 4202 | * The use of last_mgmt_freq is a bit of a hack, |
| 4203 | * but it works due to the single-threaded nature |
| 4204 | * of wpa_supplicant. |
| 4205 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4206 | if (freq == 0) { |
| 4207 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 4208 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4209 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4210 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4211 | wait_time = 0; |
| 4212 | use_cookie = 0; |
| 4213 | no_cck = 1; |
| 4214 | offchanok = 1; |
| 4215 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4216 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4217 | |
| 4218 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4219 | if (freq == 0) { |
| 4220 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 4221 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4222 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4223 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4224 | if ((int) freq == bss->freq) |
| 4225 | wait_time = 0; |
| 4226 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 4227 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 4228 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4229 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4230 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4231 | /* |
| 4232 | * Only one of the authentication frame types is encrypted. |
| 4233 | * In order for static WEP encryption to work properly (i.e., |
| 4234 | * to not encrypt the frame), we need to tell mac80211 about |
| 4235 | * the frames that must not be encrypted. |
| 4236 | */ |
| 4237 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4238 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4239 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 4240 | encrypt = 0; |
| 4241 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4242 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4243 | if (is_sta_interface(drv->nlmode) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4244 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4245 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4246 | if (freq == 0 && |
| 4247 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 4248 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 4249 | freq = nl80211_get_assoc_freq(drv); |
| 4250 | wpa_printf(MSG_DEBUG, |
| 4251 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 4252 | freq); |
| 4253 | } |
| 4254 | |
| 4255 | /* Allow off channel for PASN authentication */ |
| 4256 | if (data_len >= IEEE80211_HDRLEN + 2 && |
| 4257 | WPA_GET_LE16(data + IEEE80211_HDRLEN) == WLAN_AUTH_PASN && |
| 4258 | !offchanok) { |
| 4259 | wpa_printf(MSG_DEBUG, |
| 4260 | "nl80211: send_mlme: allow off channel for PASN"); |
| 4261 | offchanok = 1; |
| 4262 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4265 | #ifdef CONFIG_PASN |
| 4266 | if (is_sta_interface(drv->nlmode) && |
| 4267 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4268 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DEAUTH) { |
| 4269 | wpa_printf(MSG_DEBUG, |
| 4270 | "nl80211: send_mlme: allow Deauthentication frame for PASN"); |
| 4271 | |
| 4272 | use_cookie = 0; |
| 4273 | offchanok = 1; |
| 4274 | goto send_frame_cmd; |
| 4275 | } |
| 4276 | #endif /* CONFIG_PASN */ |
| 4277 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4278 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4279 | freq = nl80211_get_assoc_freq(drv); |
| 4280 | wpa_printf(MSG_DEBUG, |
| 4281 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 4282 | freq); |
| 4283 | } |
| 4284 | if (freq == 0) { |
| 4285 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
| 4286 | bss->freq); |
| 4287 | freq = bss->freq; |
| 4288 | } |
| 4289 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4290 | if (drv->use_monitor && is_ap_interface(drv->nlmode)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4291 | wpa_printf(MSG_DEBUG, |
| 4292 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
| 4293 | freq, bss->freq); |
| 4294 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4295 | noack); |
| 4296 | } |
| 4297 | |
| 4298 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 4299 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 4300 | use_cookie = 0; |
| 4301 | send_frame_cmd: |
| 4302 | #ifdef CONFIG_TESTING_OPTIONS |
| 4303 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 4304 | wpa_printf(MSG_DEBUG, |
| 4305 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 4306 | if (nl80211_create_monitor_interface(drv) < 0) |
| 4307 | return -1; |
| 4308 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4309 | noack); |
| 4310 | nl80211_remove_monitor_interface(drv); |
| 4311 | return res; |
| 4312 | } |
| 4313 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4314 | |
| 4315 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 4316 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 4317 | use_cookie, no_cck, noack, offchanok, |
| 4318 | csa_offs, csa_offs_len); |
| 4319 | |
| 4320 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4324 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 4325 | { |
| 4326 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 4327 | u8 rates_len = 0; |
| 4328 | int i; |
| 4329 | |
| 4330 | if (!basic_rates) |
| 4331 | return 0; |
| 4332 | |
| 4333 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 4334 | rates[rates_len++] = basic_rates[i] / 5; |
| 4335 | |
| 4336 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 4337 | } |
| 4338 | |
| 4339 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4340 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 4341 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4342 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4343 | { |
| 4344 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4345 | struct nl_msg *msg; |
| 4346 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4347 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 4348 | (cts >= 0 && |
| 4349 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 4350 | (preamble >= 0 && |
| 4351 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 4352 | (slot >= 0 && |
| 4353 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 4354 | (ht_opmode >= 0 && |
| 4355 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 4356 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4357 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 4358 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 4359 | nlmsg_free(msg); |
| 4360 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4363 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4367 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 4368 | struct hostapd_acl_params *params) |
| 4369 | { |
| 4370 | struct i802_bss *bss = priv; |
| 4371 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4372 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4373 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4374 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4375 | int ret; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4376 | size_t acl_nla_sz, acl_nlmsg_sz, nla_sz, nlmsg_sz; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4377 | |
| 4378 | if (!(drv->capa.max_acl_mac_addrs)) |
| 4379 | return -ENOTSUP; |
| 4380 | |
| 4381 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 4382 | return -ENOTSUP; |
| 4383 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4384 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 4385 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 4386 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4387 | acl_nla_sz = nla_total_size(ETH_ALEN) * params->num_mac_acl; |
| 4388 | acl_nlmsg_sz = nlmsg_total_size(acl_nla_sz); |
| 4389 | acl = nlmsg_alloc_size(acl_nlmsg_sz); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4390 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4391 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4392 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4393 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 4394 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4395 | return -ENOMEM; |
| 4396 | } |
| 4397 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4398 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4399 | /* |
| 4400 | * genetlink message header (Length of user header is 0) + |
| 4401 | * u32 attr: NL80211_ATTR_IFINDEX + |
| 4402 | * u32 attr: NL80211_ATTR_ACL_POLICY + |
| 4403 | * nested acl attr |
| 4404 | */ |
| 4405 | nla_sz = GENL_HDRLEN + |
| 4406 | nla_total_size(4) * 2 + |
| 4407 | nla_total_size(acl_nla_sz); |
| 4408 | nlmsg_sz = nlmsg_total_size(nla_sz); |
| 4409 | if (!(msg = nl80211_ifindex_msg_build(drv, nlmsg_alloc_size(nlmsg_sz), |
| 4410 | drv->ifindex, 0, |
| 4411 | NL80211_CMD_SET_MAC_ACL)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4412 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 4413 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 4414 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 4415 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 4416 | nlmsg_free(msg); |
| 4417 | nlmsg_free(acl); |
| 4418 | return -ENOMEM; |
| 4419 | } |
| 4420 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4421 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4422 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4423 | if (ret) { |
| 4424 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 4425 | ret, strerror(-ret)); |
| 4426 | } |
| 4427 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4428 | return ret; |
| 4429 | } |
| 4430 | |
| 4431 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4432 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 4433 | { |
| 4434 | if (beacon_int > 0) { |
| 4435 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 4436 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4437 | beacon_int); |
| 4438 | } |
| 4439 | |
| 4440 | return 0; |
| 4441 | } |
| 4442 | |
| 4443 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4444 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 4445 | { |
| 4446 | if (dtim_period > 0) { |
| 4447 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 4448 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 4449 | } |
| 4450 | |
| 4451 | return 0; |
| 4452 | } |
| 4453 | |
| 4454 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4455 | #ifdef CONFIG_MESH |
| 4456 | static int nl80211_set_mesh_config(void *priv, |
| 4457 | struct wpa_driver_mesh_bss_params *params) |
| 4458 | { |
| 4459 | struct i802_bss *bss = priv; |
| 4460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4461 | struct nl_msg *msg; |
| 4462 | int ret; |
| 4463 | |
| 4464 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4465 | if (!msg) |
| 4466 | return -1; |
| 4467 | |
| 4468 | ret = nl80211_put_mesh_config(msg, params); |
| 4469 | if (ret < 0) { |
| 4470 | nlmsg_free(msg); |
| 4471 | return ret; |
| 4472 | } |
| 4473 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4474 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4475 | if (ret) { |
| 4476 | wpa_printf(MSG_ERROR, |
| 4477 | "nl80211: Mesh config set failed: %d (%s)", |
| 4478 | ret, strerror(-ret)); |
| 4479 | return ret; |
| 4480 | } |
| 4481 | return 0; |
| 4482 | } |
| 4483 | #endif /* CONFIG_MESH */ |
| 4484 | |
| 4485 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4486 | 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] | 4487 | struct wpa_driver_ap_params *params) |
| 4488 | { |
| 4489 | struct nlattr *bands, *band; |
| 4490 | struct nl80211_txrate_vht vht_rate; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4491 | struct nl80211_txrate_he he_rate; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4492 | |
| 4493 | if (!params->freq || |
| 4494 | (params->beacon_rate == 0 && |
| 4495 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4496 | return 0; |
| 4497 | |
| 4498 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4499 | if (!bands) |
| 4500 | return -1; |
| 4501 | |
| 4502 | switch (params->freq->mode) { |
| 4503 | case HOSTAPD_MODE_IEEE80211B: |
| 4504 | case HOSTAPD_MODE_IEEE80211G: |
| 4505 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4506 | break; |
| 4507 | case HOSTAPD_MODE_IEEE80211A: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4508 | if (is_6ghz_freq(params->freq->freq)) |
| 4509 | band = nla_nest_start(msg, NL80211_BAND_6GHZ); |
| 4510 | else |
| 4511 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4512 | break; |
| 4513 | case HOSTAPD_MODE_IEEE80211AD: |
| 4514 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4515 | break; |
| 4516 | default: |
| 4517 | return 0; |
| 4518 | } |
| 4519 | |
| 4520 | if (!band) |
| 4521 | return -1; |
| 4522 | |
| 4523 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4524 | os_memset(&he_rate, 0, sizeof(he_rate)); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4525 | |
| 4526 | switch (params->rate_type) { |
| 4527 | case BEACON_RATE_LEGACY: |
| 4528 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4529 | wpa_printf(MSG_INFO, |
| 4530 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4531 | return -1; |
| 4532 | } |
| 4533 | |
| 4534 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 4535 | (u8) params->beacon_rate / 5) || |
| 4536 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4537 | (params->freq->vht_enabled && |
| 4538 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4539 | &vht_rate))) |
| 4540 | return -1; |
| 4541 | |
| 4542 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4543 | params->beacon_rate); |
| 4544 | break; |
| 4545 | case BEACON_RATE_HT: |
| 4546 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4547 | wpa_printf(MSG_INFO, |
| 4548 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4549 | return -1; |
| 4550 | } |
| 4551 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4552 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4553 | (params->freq->vht_enabled && |
| 4554 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4555 | &vht_rate))) |
| 4556 | return -1; |
| 4557 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4558 | params->beacon_rate); |
| 4559 | break; |
| 4560 | case BEACON_RATE_VHT: |
| 4561 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4562 | wpa_printf(MSG_INFO, |
| 4563 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4564 | return -1; |
| 4565 | } |
| 4566 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4567 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4568 | return -1; |
| 4569 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4570 | return -1; |
| 4571 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4572 | &vht_rate)) |
| 4573 | return -1; |
| 4574 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4575 | params->beacon_rate); |
| 4576 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4577 | case BEACON_RATE_HE: |
| 4578 | if (!(flags2 & WPA_DRIVER_FLAGS2_BEACON_RATE_HE)) { |
| 4579 | wpa_printf(MSG_INFO, |
| 4580 | "nl80211: Driver does not support setting Beacon frame rate (HE)"); |
| 4581 | return -1; |
| 4582 | } |
| 4583 | he_rate.mcs[0] = BIT(params->beacon_rate); |
| 4584 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4585 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4586 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4587 | &vht_rate) || |
| 4588 | nla_put(msg, NL80211_TXRATE_HE, sizeof(he_rate), &he_rate)) |
| 4589 | return -1; |
| 4590 | wpa_printf(MSG_DEBUG, " * beacon_rate = HE-MCS %u", |
| 4591 | params->beacon_rate); |
| 4592 | break; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | nla_nest_end(msg, band); |
| 4596 | nla_nest_end(msg, bands); |
| 4597 | |
| 4598 | return 0; |
| 4599 | } |
| 4600 | |
| 4601 | |
| 4602 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4603 | int multicast_to_unicast) |
| 4604 | { |
| 4605 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4606 | struct nl_msg *msg; |
| 4607 | int ret; |
| 4608 | |
| 4609 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4610 | if (!msg || |
| 4611 | (multicast_to_unicast && |
| 4612 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4613 | wpa_printf(MSG_ERROR, |
| 4614 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4615 | bss->ifname); |
| 4616 | nlmsg_free(msg); |
| 4617 | return -ENOBUFS; |
| 4618 | } |
| 4619 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4620 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4621 | |
| 4622 | switch (ret) { |
| 4623 | case 0: |
| 4624 | wpa_printf(MSG_DEBUG, |
| 4625 | "nl80211: multicast to unicast %s on interface %s", |
| 4626 | multicast_to_unicast ? "enabled" : "disabled", |
| 4627 | bss->ifname); |
| 4628 | break; |
| 4629 | case -EOPNOTSUPP: |
| 4630 | if (!multicast_to_unicast) |
| 4631 | break; |
| 4632 | wpa_printf(MSG_INFO, |
| 4633 | "nl80211: multicast to unicast not supported on interface %s", |
| 4634 | bss->ifname); |
| 4635 | break; |
| 4636 | default: |
| 4637 | wpa_printf(MSG_ERROR, |
| 4638 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4639 | multicast_to_unicast ? "enabling" : "disabling", |
| 4640 | ret, strerror(-ret), bss->ifname); |
| 4641 | break; |
| 4642 | } |
| 4643 | |
| 4644 | return ret; |
| 4645 | } |
| 4646 | |
| 4647 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4648 | #ifdef CONFIG_SAE |
| 4649 | static int nl80211_put_sae_pwe(struct nl_msg *msg, int pwe) |
| 4650 | { |
| 4651 | u8 sae_pwe; |
| 4652 | |
| 4653 | wpa_printf(MSG_DEBUG, "nl802111: sae_pwe=%d", pwe); |
| 4654 | if (pwe == 0) |
| 4655 | sae_pwe = NL80211_SAE_PWE_HUNT_AND_PECK; |
| 4656 | else if (pwe == 1) |
| 4657 | sae_pwe = NL80211_SAE_PWE_HASH_TO_ELEMENT; |
| 4658 | else if (pwe == 2) |
| 4659 | sae_pwe = NL80211_SAE_PWE_BOTH; |
| 4660 | else if (pwe == 3) |
| 4661 | return 0; /* special test mode */ |
| 4662 | else |
| 4663 | return -1; |
| 4664 | if (nla_put_u8(msg, NL80211_ATTR_SAE_PWE, sae_pwe)) |
| 4665 | return -1; |
| 4666 | |
| 4667 | return 0; |
| 4668 | } |
| 4669 | #endif /* CONFIG_SAE */ |
| 4670 | |
| 4671 | |
| 4672 | #ifdef CONFIG_FILS |
| 4673 | static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
| 4674 | struct wpa_driver_ap_params *params) |
| 4675 | { |
| 4676 | struct nlattr *attr; |
| 4677 | |
| 4678 | if (!bss->drv->fils_discovery) { |
| 4679 | wpa_printf(MSG_ERROR, |
| 4680 | "nl80211: Driver does not support FILS Discovery frame transmission for %s", |
| 4681 | bss->ifname); |
| 4682 | return -1; |
| 4683 | } |
| 4684 | |
| 4685 | attr = nla_nest_start(msg, NL80211_ATTR_FILS_DISCOVERY); |
| 4686 | if (!attr || |
| 4687 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 4688 | params->fd_min_int) || |
| 4689 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 4690 | params->fd_max_int) || |
| 4691 | (params->fd_frame_tmpl && |
| 4692 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 4693 | params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 4694 | return -1; |
| 4695 | |
| 4696 | nla_nest_end(msg, attr); |
| 4697 | return 0; |
| 4698 | } |
| 4699 | #endif /* CONFIG_FILS */ |
| 4700 | |
| 4701 | |
| 4702 | #ifdef CONFIG_IEEE80211AX |
| 4703 | static int nl80211_unsol_bcast_probe_resp(struct i802_bss *bss, |
| 4704 | struct nl_msg *msg, |
| 4705 | struct wpa_driver_ap_params *params) |
| 4706 | { |
| 4707 | struct nlattr *attr; |
| 4708 | |
| 4709 | if (!bss->drv->unsol_bcast_probe_resp) { |
| 4710 | wpa_printf(MSG_ERROR, |
| 4711 | "nl80211: Driver does not support unsolicited broadcast Probe Response frame transmission for %s", |
| 4712 | bss->ifname); |
| 4713 | return -1; |
| 4714 | } |
| 4715 | |
| 4716 | wpa_printf(MSG_DEBUG, |
| 4717 | "nl80211: Unsolicited broadcast Probe Response frame interval: %u", |
| 4718 | params->unsol_bcast_probe_resp_interval); |
| 4719 | attr = nla_nest_start(msg, NL80211_ATTR_UNSOL_BCAST_PROBE_RESP); |
| 4720 | if (!attr || |
| 4721 | nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT, |
| 4722 | params->unsol_bcast_probe_resp_interval) || |
| 4723 | (params->unsol_bcast_probe_resp_tmpl && |
| 4724 | nla_put(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL, |
| 4725 | params->unsol_bcast_probe_resp_tmpl_len, |
| 4726 | params->unsol_bcast_probe_resp_tmpl))) |
| 4727 | return -1; |
| 4728 | |
| 4729 | nla_nest_end(msg, attr); |
| 4730 | return 0; |
| 4731 | } |
| 4732 | #endif /* CONFIG_IEEE80211AX */ |
| 4733 | |
| 4734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4735 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4736 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4737 | { |
| 4738 | struct i802_bss *bss = priv; |
| 4739 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4740 | struct nl_msg *msg; |
| 4741 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4742 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4743 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4744 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4745 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4746 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4747 | #ifdef CONFIG_MESH |
| 4748 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4749 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4750 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4751 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4753 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4754 | beacon_set); |
| 4755 | if (beacon_set) |
| 4756 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4757 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4758 | !nl80211_get_wiphy_data_ap(bss)) |
| 4759 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4760 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4761 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4762 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4763 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4764 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4765 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4766 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4767 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4768 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4769 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4770 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4771 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4772 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4773 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4774 | params->head) || |
| 4775 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4776 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4777 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4778 | nl80211_put_beacon_rate(msg, drv->capa.flags, drv->capa.flags2, |
| 4779 | params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4780 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4781 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4782 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4783 | if (params->proberesp && params->proberesp_len) { |
| 4784 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4785 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4786 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4787 | params->proberesp)) |
| 4788 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4789 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4790 | switch (params->hide_ssid) { |
| 4791 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4792 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4793 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4794 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4795 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4796 | break; |
| 4797 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4798 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4799 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4800 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4801 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4802 | break; |
| 4803 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4804 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4805 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4806 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4807 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4808 | break; |
| 4809 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4810 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4811 | if (params->privacy && |
| 4812 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4813 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4814 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4815 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4816 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4817 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4818 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4819 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4820 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4821 | goto fail; |
| 4822 | } else { |
| 4823 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4824 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4825 | goto fail; |
| 4826 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4827 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4828 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4829 | ver = 0; |
| 4830 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4831 | ver |= NL80211_WPA_VERSION_1; |
| 4832 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4833 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4834 | if (ver && |
| 4835 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4836 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4837 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4838 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4839 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4840 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 4841 | suites, ARRAY_SIZE(suites)); |
| 4842 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4843 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4844 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", |
| 4845 | num_suites); |
| 4846 | else if (num_suites && |
| 4847 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4848 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4849 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4850 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4851 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4852 | (!params->pairwise_ciphers || |
| 4853 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4854 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4855 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4856 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4857 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4858 | if (drv->device_ap_sme) { |
| 4859 | u32 flags = 0; |
| 4860 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4861 | if (params->key_mgmt_suites & (WPA_KEY_MGMT_SAE | |
| 4862 | WPA_KEY_MGMT_SAE_EXT_KEY)) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4863 | /* Add the previously used flag attribute to support |
| 4864 | * older kernel versions and the newer flag bit for |
| 4865 | * newer kernels. */ |
| 4866 | if (nla_put_flag(msg, |
| 4867 | NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4868 | goto fail; |
| 4869 | flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 4870 | } |
| 4871 | |
| 4872 | flags |= NL80211_AP_SETTINGS_SA_QUERY_OFFLOAD_SUPPORT; |
| 4873 | |
| 4874 | if (nla_put_u32(msg, NL80211_ATTR_AP_SETTINGS_FLAGS, flags)) |
| 4875 | goto fail; |
| 4876 | } |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4877 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4878 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4879 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4880 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4881 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4882 | if (num_suites && |
| 4883 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4884 | num_suites * sizeof(u32), suites)) |
| 4885 | goto fail; |
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: group_cipher=0x%x", |
| 4888 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4889 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4890 | if (suite && |
| 4891 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4892 | goto fail; |
| 4893 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4894 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4895 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4896 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4897 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4898 | wpabuf_len(params->beacon_ies), |
| 4899 | wpabuf_head(params->beacon_ies))) |
| 4900 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4901 | } |
| 4902 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4903 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4904 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4905 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4906 | wpabuf_len(params->proberesp_ies), |
| 4907 | wpabuf_head(params->proberesp_ies))) |
| 4908 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4909 | } |
| 4910 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4911 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4912 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4913 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4914 | wpabuf_len(params->assocresp_ies), |
| 4915 | wpabuf_head(params->assocresp_ies))) |
| 4916 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4917 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4918 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4919 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4920 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4921 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4922 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4923 | params->ap_max_inactivity)) |
| 4924 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4927 | #ifdef CONFIG_P2P |
| 4928 | if (params->p2p_go_ctwindow > 0) { |
| 4929 | if (drv->p2p_go_ctwindow_supported) { |
| 4930 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4931 | params->p2p_go_ctwindow); |
| 4932 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4933 | params->p2p_go_ctwindow)) |
| 4934 | goto fail; |
| 4935 | } else { |
| 4936 | wpa_printf(MSG_INFO, |
| 4937 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4938 | } |
| 4939 | } |
| 4940 | #endif /* CONFIG_P2P */ |
| 4941 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4942 | if (params->pbss) { |
| 4943 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4944 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4945 | goto fail; |
| 4946 | } |
| 4947 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4948 | if (params->ftm_responder) { |
| 4949 | struct nlattr *ftm; |
| 4950 | |
| 4951 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 4952 | ret = -ENOTSUP; |
| 4953 | goto fail; |
| 4954 | } |
| 4955 | |
| 4956 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 4957 | if (!ftm || |
| 4958 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 4959 | (params->lci && |
| 4960 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 4961 | wpabuf_len(params->lci), |
| 4962 | wpabuf_head(params->lci))) || |
| 4963 | (params->civic && |
| 4964 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 4965 | wpabuf_len(params->civic), |
| 4966 | wpabuf_head(params->civic)))) |
| 4967 | goto fail; |
| 4968 | nla_nest_end(msg, ftm); |
| 4969 | } |
| 4970 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4971 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4972 | if (params->he_spr_ctrl) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4973 | struct nlattr *spr; |
| 4974 | |
| 4975 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4976 | wpa_printf(MSG_DEBUG, "nl80211: he_spr_ctrl=0x%x", |
| 4977 | params->he_spr_ctrl); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4978 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4979 | if (!spr || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4980 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_SR_CTRL, |
| 4981 | params->he_spr_ctrl) || |
| 4982 | ((params->he_spr_ctrl & |
| 4983 | SPATIAL_REUSE_NON_SRG_OFFSET_PRESENT) && |
| 4984 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET, |
| 4985 | params->he_spr_non_srg_obss_pd_max_offset))) |
| 4986 | goto fail; |
| 4987 | |
| 4988 | if ((params->he_spr_ctrl & |
| 4989 | SPATIAL_REUSE_SRG_INFORMATION_PRESENT) && |
| 4990 | (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
| 4991 | params->he_spr_srg_obss_pd_min_offset) || |
| 4992 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 4993 | params->he_spr_srg_obss_pd_max_offset) || |
| 4994 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP, |
| 4995 | sizeof(params->he_spr_bss_color_bitmap), |
| 4996 | params->he_spr_bss_color_bitmap) || |
| 4997 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP, |
| 4998 | sizeof(params->he_spr_partial_bssid_bitmap), |
| 4999 | params->he_spr_partial_bssid_bitmap))) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5000 | goto fail; |
| 5001 | |
| 5002 | nla_nest_end(msg, spr); |
| 5003 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5004 | |
| 5005 | if (params->freq && params->freq->he_enabled) { |
| 5006 | struct nlattr *bss_color; |
| 5007 | |
| 5008 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 5009 | if (!bss_color || |
| 5010 | (params->he_bss_color_disabled && |
| 5011 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 5012 | (params->he_bss_color_partial && |
| 5013 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 5014 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 5015 | params->he_bss_color)) |
| 5016 | goto fail; |
| 5017 | nla_nest_end(msg, bss_color); |
| 5018 | } |
| 5019 | |
| 5020 | if (params->twt_responder) { |
| 5021 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 5022 | params->twt_responder); |
| 5023 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 5024 | goto fail; |
| 5025 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5026 | |
| 5027 | if (params->unsol_bcast_probe_resp_interval && |
| 5028 | nl80211_unsol_bcast_probe_resp(bss, msg, params) < 0) |
| 5029 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5030 | #endif /* CONFIG_IEEE80211AX */ |
| 5031 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5032 | #ifdef CONFIG_SAE |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 5033 | if (wpa_key_mgmt_sae(params->key_mgmt_suites) && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5034 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 5035 | goto fail; |
| 5036 | #endif /* CONFIG_SAE */ |
| 5037 | |
| 5038 | #ifdef CONFIG_FILS |
| 5039 | if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
| 5040 | goto fail; |
| 5041 | #endif /* CONFIG_FILS */ |
| 5042 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5043 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5044 | if (ret) { |
| 5045 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 5046 | ret, strerror(-ret)); |
| 5047 | } else { |
| 5048 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5049 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 5050 | params->short_slot_time, params->ht_opmode, |
| 5051 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5052 | nl80211_set_multicast_to_unicast(bss, |
| 5053 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5054 | if (beacon_set && params->freq && |
| 5055 | params->freq->bandwidth != bss->bandwidth) { |
| 5056 | wpa_printf(MSG_DEBUG, |
| 5057 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 5058 | bss->ifname, bss->bandwidth, |
| 5059 | params->freq->bandwidth); |
| 5060 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 5061 | if (ret) { |
| 5062 | wpa_printf(MSG_DEBUG, |
| 5063 | "nl80211: Frequency set failed: %d (%s)", |
| 5064 | ret, strerror(-ret)); |
| 5065 | } else { |
| 5066 | wpa_printf(MSG_DEBUG, |
| 5067 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 5068 | bss->bandwidth = params->freq->bandwidth; |
| 5069 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5070 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5071 | /* |
| 5072 | * cfg80211 updates the driver on frequence change in AP |
| 5073 | * mode only at the point when beaconing is started, so |
| 5074 | * set the initial value here. |
| 5075 | */ |
| 5076 | bss->bandwidth = params->freq->bandwidth; |
| 5077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5078 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5079 | |
| 5080 | #ifdef CONFIG_MESH |
| 5081 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 5082 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 5083 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 5084 | mesh_params.ht_opmode = params->ht_opmode; |
| 5085 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 5086 | if (ret < 0) |
| 5087 | return ret; |
| 5088 | } |
| 5089 | #endif /* CONFIG_MESH */ |
| 5090 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5091 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5092 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5093 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5094 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5098 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5099 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5101 | enum hostapd_hw_mode hw_mode; |
| 5102 | int is_24ghz; |
| 5103 | u8 channel; |
| 5104 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5105 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5106 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 5107 | return -ENOBUFS; |
| 5108 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5109 | wpa_printf(MSG_DEBUG, " * eht_enabled=%d", freq->eht_enabled); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5110 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5111 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 5112 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5113 | wpa_printf(MSG_DEBUG, " * radar_background=%d", |
| 5114 | freq->radar_background); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5115 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5116 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 5117 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 5118 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 5119 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5120 | if (freq->vht_enabled || |
| 5121 | ((freq->he_enabled || freq->eht_enabled) && !is_24ghz)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5122 | enum nl80211_chan_width cw; |
| 5123 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5124 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5125 | switch (freq->bandwidth) { |
| 5126 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5127 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5128 | break; |
| 5129 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5130 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5131 | break; |
| 5132 | case 80: |
| 5133 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5134 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5135 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5136 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5137 | break; |
| 5138 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5139 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5140 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5141 | case 320: |
| 5142 | cw = NL80211_CHAN_WIDTH_320; |
| 5143 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5144 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5145 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5146 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5147 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5148 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 5149 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 5150 | freq->center_freq1); |
| 5151 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 5152 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5153 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 5154 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 5155 | freq->center_freq1) || |
| 5156 | (freq->center_freq2 && |
| 5157 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 5158 | freq->center_freq2))) |
| 5159 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5160 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5161 | enum nl80211_channel_type ct; |
| 5162 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5163 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 5164 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5165 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5166 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5167 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5168 | break; |
| 5169 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5170 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5171 | break; |
| 5172 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5173 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | break; |
| 5175 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5176 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5177 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 5179 | return -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5180 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 5181 | wpa_printf(MSG_DEBUG, |
| 5182 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5183 | freq->edmg.channels, freq->edmg.bw_config); |
| 5184 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5185 | freq->edmg.channels) || |
| 5186 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5187 | freq->edmg.bw_config)) |
| 5188 | return -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5189 | } else { |
| 5190 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 5191 | NL80211_CHAN_NO_HT); |
| 5192 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 5193 | NL80211_CHAN_NO_HT)) |
| 5194 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5195 | } |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5196 | if (freq->radar_background && |
| 5197 | nla_put_flag(msg, NL80211_ATTR_RADAR_BACKGROUND)) |
| 5198 | return -ENOBUFS; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5199 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5200 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5204 | static int nl80211_set_channel(struct i802_bss *bss, |
| 5205 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5206 | { |
| 5207 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5208 | struct nl_msg *msg; |
| 5209 | int ret; |
| 5210 | |
| 5211 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5212 | "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)", |
| 5213 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 5214 | freq->he_enabled, freq->eht_enabled, freq->bandwidth, |
| 5215 | freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5216 | |
| 5217 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 5218 | NL80211_CMD_SET_WIPHY); |
| 5219 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 5220 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5221 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5222 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5223 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5224 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5225 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5226 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5227 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5228 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5229 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5230 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5231 | return -1; |
| 5232 | } |
| 5233 | |
| 5234 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5235 | static u32 sta_flags_nl80211(int flags) |
| 5236 | { |
| 5237 | u32 f = 0; |
| 5238 | |
| 5239 | if (flags & WPA_STA_AUTHORIZED) |
| 5240 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5241 | if (flags & WPA_STA_WMM) |
| 5242 | f |= BIT(NL80211_STA_FLAG_WME); |
| 5243 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 5244 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 5245 | if (flags & WPA_STA_MFP) |
| 5246 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 5247 | if (flags & WPA_STA_TDLS_PEER) |
| 5248 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5249 | if (flags & WPA_STA_AUTHENTICATED) |
| 5250 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5251 | if (flags & WPA_STA_ASSOCIATED) |
| 5252 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5253 | |
| 5254 | return f; |
| 5255 | } |
| 5256 | |
| 5257 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5258 | #ifdef CONFIG_MESH |
| 5259 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 5260 | { |
| 5261 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5262 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5263 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5264 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5265 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5266 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5267 | return NL80211_PLINK_OPN_RCVD; |
| 5268 | case PLINK_CNF_RCVD: |
| 5269 | return NL80211_PLINK_CNF_RCVD; |
| 5270 | case PLINK_ESTAB: |
| 5271 | return NL80211_PLINK_ESTAB; |
| 5272 | case PLINK_HOLDING: |
| 5273 | return NL80211_PLINK_HOLDING; |
| 5274 | case PLINK_BLOCKED: |
| 5275 | return NL80211_PLINK_BLOCKED; |
| 5276 | default: |
| 5277 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 5278 | state); |
| 5279 | } |
| 5280 | return -1; |
| 5281 | } |
| 5282 | #endif /* CONFIG_MESH */ |
| 5283 | |
| 5284 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5285 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 5286 | struct hostapd_sta_add_params *params) |
| 5287 | { |
| 5288 | struct i802_bss *bss = priv; |
| 5289 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5290 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5291 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5292 | int ret = -ENOBUFS; |
| 5293 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5294 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 5295 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 5296 | return -EOPNOTSUPP; |
| 5297 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5298 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 5299 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5300 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 5301 | NL80211_CMD_NEW_STATION); |
| 5302 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 5303 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5304 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5305 | /* |
| 5306 | * Set the below properties only in one of the following cases: |
| 5307 | * 1. New station is added, already associated. |
| 5308 | * 2. Set WPA_STA_TDLS_PEER station. |
| 5309 | * 3. Set an already added unassociated station, if driver supports |
| 5310 | * full AP client state. (Set these properties after station became |
| 5311 | * associated will be rejected by the driver). |
| 5312 | */ |
| 5313 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5314 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5315 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5316 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 5317 | params->supp_rates, params->supp_rates_len); |
| 5318 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 5319 | params->capability); |
| 5320 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 5321 | params->supp_rates_len, params->supp_rates) || |
| 5322 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 5323 | params->capability)) |
| 5324 | goto fail; |
| 5325 | |
| 5326 | if (params->ht_capabilities) { |
| 5327 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 5328 | (u8 *) params->ht_capabilities, |
| 5329 | sizeof(*params->ht_capabilities)); |
| 5330 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 5331 | sizeof(*params->ht_capabilities), |
| 5332 | params->ht_capabilities)) |
| 5333 | goto fail; |
| 5334 | } |
| 5335 | |
| 5336 | if (params->vht_capabilities) { |
| 5337 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 5338 | (u8 *) params->vht_capabilities, |
| 5339 | sizeof(*params->vht_capabilities)); |
| 5340 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 5341 | sizeof(*params->vht_capabilities), |
| 5342 | params->vht_capabilities)) |
| 5343 | goto fail; |
| 5344 | } |
| 5345 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5346 | if (params->he_capab) { |
| 5347 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 5348 | params->he_capab, params->he_capab_len); |
| 5349 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 5350 | params->he_capab_len, params->he_capab)) |
| 5351 | goto fail; |
| 5352 | } |
| 5353 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5354 | if (params->he_6ghz_capab) { |
| 5355 | wpa_hexdump(MSG_DEBUG, " * he_6ghz_capab", |
| 5356 | params->he_6ghz_capab, |
| 5357 | sizeof(*params->he_6ghz_capab)); |
| 5358 | if (nla_put(msg, NL80211_ATTR_HE_6GHZ_CAPABILITY, |
| 5359 | sizeof(*params->he_6ghz_capab), |
| 5360 | params->he_6ghz_capab)) |
| 5361 | goto fail; |
| 5362 | } |
| 5363 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 5364 | if (params->eht_capab) { |
| 5365 | wpa_hexdump(MSG_DEBUG, " * eht_capab", |
| 5366 | params->eht_capab, params->eht_capab_len); |
| 5367 | if (nla_put(msg, NL80211_ATTR_EHT_CAPABILITY, |
| 5368 | params->eht_capab_len, params->eht_capab)) |
| 5369 | goto fail; |
| 5370 | } |
| 5371 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5372 | if (params->ext_capab) { |
| 5373 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 5374 | params->ext_capab, params->ext_capab_len); |
| 5375 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 5376 | params->ext_capab_len, params->ext_capab)) |
| 5377 | goto fail; |
| 5378 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5379 | |
| 5380 | if (is_ap_interface(drv->nlmode) && |
| 5381 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 5382 | params->support_p2p_ps ? |
| 5383 | NL80211_P2P_PS_SUPPORTED : |
| 5384 | NL80211_P2P_PS_UNSUPPORTED)) |
| 5385 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5386 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5387 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5388 | if (params->aid) { |
| 5389 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5390 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 5391 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5392 | } else { |
| 5393 | /* |
| 5394 | * cfg80211 validates that AID is non-zero, so we have |
| 5395 | * to make this a non-zero value for the TDLS case where |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5396 | * a stub STA entry is used for now and for a station |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5397 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5398 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5399 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 5400 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 5401 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5402 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 5403 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5404 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5405 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5406 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5407 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5408 | params->listen_interval)) |
| 5409 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5410 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 5411 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5412 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 5413 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5414 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5415 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 5416 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 5417 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5418 | params->listen_interval); |
| 5419 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 5420 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5421 | params->listen_interval)) |
| 5422 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5423 | } |
| 5424 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 5425 | if (params->vht_opmode_enabled) { |
| 5426 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5427 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 5428 | params->vht_opmode)) |
| 5429 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5430 | } |
| 5431 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5432 | if (params->supp_channels) { |
| 5433 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 5434 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5435 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 5436 | params->supp_channels_len, params->supp_channels)) |
| 5437 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | if (params->supp_oper_classes) { |
| 5441 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 5442 | params->supp_oper_classes, |
| 5443 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5444 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 5445 | params->supp_oper_classes_len, |
| 5446 | params->supp_oper_classes)) |
| 5447 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5448 | } |
| 5449 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5450 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5451 | upd.set = sta_flags_nl80211(params->flags); |
| 5452 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5453 | |
| 5454 | /* |
| 5455 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 5456 | * flags, as nl80211 driver moves a new station, by default, into |
| 5457 | * associated state. |
| 5458 | * |
| 5459 | * On the other hand, if the driver supports that feature and the |
| 5460 | * station is added in unauthenticated state, set the |
| 5461 | * authenticated/associated bits in the mask to prevent moving this |
| 5462 | * station to associated state before it is actually associated. |
| 5463 | * |
| 5464 | * This is irrelevant for mesh mode where the station is added to the |
| 5465 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 5466 | * nl80211 API. |
| 5467 | */ |
| 5468 | if (!is_mesh_interface(drv->nlmode)) { |
| 5469 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 5470 | wpa_printf(MSG_DEBUG, |
| 5471 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 5472 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5473 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 5474 | } else if (!params->set && |
| 5475 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 5476 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 5477 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 5478 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 5479 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 5480 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5481 | #ifdef CONFIG_MESH |
| 5482 | } else { |
| 5483 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 5484 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 5485 | params->peer_aid); |
| 5486 | if (ret) |
| 5487 | goto fail; |
| 5488 | } |
| 5489 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5490 | } |
| 5491 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5492 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 5493 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5494 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5495 | goto fail; |
| 5496 | |
| 5497 | #ifdef CONFIG_MESH |
| 5498 | if (params->plink_state && |
| 5499 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 5500 | sta_plink_state_nl80211(params->plink_state))) |
| 5501 | goto fail; |
| 5502 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5503 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5504 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5505 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 5506 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5507 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 5508 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5509 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5510 | if (!wme || |
| 5511 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 5512 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 5513 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 5514 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 5515 | WMM_QOSINFO_STA_SP_MASK)) |
| 5516 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5517 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5518 | } |
| 5519 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5520 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5521 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5522 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5523 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 5524 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 5525 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5526 | if (ret == -EEXIST) |
| 5527 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5528 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5529 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5530 | return ret; |
| 5531 | } |
| 5532 | |
| 5533 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5534 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 5535 | { |
| 5536 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5537 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5538 | struct rtnl_neigh *rn; |
| 5539 | struct nl_addr *nl_addr; |
| 5540 | int err; |
| 5541 | |
| 5542 | rn = rtnl_neigh_alloc(); |
| 5543 | if (!rn) |
| 5544 | return; |
| 5545 | |
| 5546 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 5547 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 5548 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 5549 | if (!nl_addr) { |
| 5550 | rtnl_neigh_put(rn); |
| 5551 | return; |
| 5552 | } |
| 5553 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 5554 | |
| 5555 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 5556 | if (err < 0) { |
| 5557 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 5558 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 5559 | bss->ifindex, nl_geterror(err)); |
| 5560 | } else { |
| 5561 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 5562 | MACSTR, MAC2STR(addr)); |
| 5563 | } |
| 5564 | |
| 5565 | nl_addr_put(nl_addr); |
| 5566 | rtnl_neigh_put(rn); |
| 5567 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5568 | } |
| 5569 | |
| 5570 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5571 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 5572 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5573 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5574 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5575 | struct nl_msg *msg; |
| 5576 | int ret; |
| 5577 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5578 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 5579 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5580 | (deauth == 0 && |
| 5581 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5582 | WLAN_FC_STYPE_DISASSOC)) || |
| 5583 | (deauth == 1 && |
| 5584 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5585 | WLAN_FC_STYPE_DEAUTH)) || |
| 5586 | (reason_code && |
| 5587 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 5588 | nlmsg_free(msg); |
| 5589 | return -ENOBUFS; |
| 5590 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5591 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5592 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5593 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 5594 | " --> %d (%s)", |
| 5595 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5596 | |
| 5597 | if (drv->rtnl_sk) |
| 5598 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 5599 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5600 | if (ret == -ENOENT) |
| 5601 | return 0; |
| 5602 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5606 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5607 | { |
| 5608 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5609 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5610 | |
| 5611 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 5612 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5614 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 5615 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5616 | { |
| 5617 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 5618 | /* Remove all bridges learned for this iface */ |
| 5619 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 5620 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5621 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5622 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5623 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5624 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5625 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 5626 | } |
| 5627 | |
| 5628 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5629 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5630 | { |
| 5631 | switch (mode) { |
| 5632 | case NL80211_IFTYPE_ADHOC: |
| 5633 | return "ADHOC"; |
| 5634 | case NL80211_IFTYPE_STATION: |
| 5635 | return "STATION"; |
| 5636 | case NL80211_IFTYPE_AP: |
| 5637 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5638 | case NL80211_IFTYPE_AP_VLAN: |
| 5639 | return "AP_VLAN"; |
| 5640 | case NL80211_IFTYPE_WDS: |
| 5641 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5642 | case NL80211_IFTYPE_MONITOR: |
| 5643 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5644 | case NL80211_IFTYPE_MESH_POINT: |
| 5645 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5646 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5647 | return "P2P_CLIENT"; |
| 5648 | case NL80211_IFTYPE_P2P_GO: |
| 5649 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5650 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5651 | return "P2P_DEVICE"; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5652 | case NL80211_IFTYPE_OCB: |
| 5653 | return "OCB"; |
| 5654 | case NL80211_IFTYPE_NAN: |
| 5655 | return "NAN"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5656 | default: |
| 5657 | return "unknown"; |
| 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5662 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 5663 | const char *ifname, |
| 5664 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5665 | const u8 *addr, int wds, |
| 5666 | int (*handler)(struct nl_msg *, void *), |
| 5667 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5668 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5669 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5670 | int ifidx; |
| 5671 | int ret = -ENOBUFS; |
| 5672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5673 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 5674 | iftype, nl80211_iftype_str(iftype)); |
| 5675 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5676 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 5677 | if (!msg || |
| 5678 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 5679 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 5680 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | |
| 5682 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5683 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5685 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5686 | if (!flags || |
| 5687 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 5688 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5689 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5690 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5691 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5692 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 5693 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5694 | } |
| 5695 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5696 | /* |
| 5697 | * Tell cfg80211 that the interface belongs to the socket that created |
| 5698 | * it, and the interface should be deleted when the socket is closed. |
| 5699 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5700 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5701 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5702 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5703 | if ((addr && iftype == NL80211_IFTYPE_P2P_DEVICE) && |
| 5704 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5705 | goto fail; |
| 5706 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5707 | ret = send_and_recv_msgs(drv, msg, handler, arg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5708 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5709 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5710 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5711 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5712 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 5713 | ifname, ret, strerror(-ret)); |
| 5714 | return ret; |
| 5715 | } |
| 5716 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5717 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 5718 | return 0; |
| 5719 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5720 | ifidx = if_nametoindex(ifname); |
| 5721 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 5722 | ifname, ifidx); |
| 5723 | |
| 5724 | if (ifidx <= 0) |
| 5725 | return -1; |
| 5726 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5727 | /* |
| 5728 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5729 | * the parent interface. This is used mainly with hostapd. |
| 5730 | */ |
| 5731 | if (drv->hostapd || |
| 5732 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 5733 | iftype == NL80211_IFTYPE_WDS || |
| 5734 | iftype == NL80211_IFTYPE_MONITOR) { |
| 5735 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5736 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5737 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5738 | |
| 5739 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5740 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5741 | nl80211_remove_iface(drv, ifidx); |
| 5742 | return -1; |
| 5743 | } |
| 5744 | |
| 5745 | return ifidx; |
| 5746 | } |
| 5747 | |
| 5748 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5749 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 5750 | const char *ifname, enum nl80211_iftype iftype, |
| 5751 | const u8 *addr, int wds, |
| 5752 | int (*handler)(struct nl_msg *, void *), |
| 5753 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5754 | { |
| 5755 | int ret; |
| 5756 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5757 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 5758 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5759 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5760 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5761 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5762 | if (use_existing) { |
| 5763 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 5764 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5765 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 5766 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5767 | addr) < 0 && |
| 5768 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 5769 | ifname, 0) < 0 || |
| 5770 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5771 | addr) < 0 || |
| 5772 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 5773 | ifname, 1) < 0)) |
| 5774 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5775 | return -ENFILE; |
| 5776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5777 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 5778 | |
| 5779 | /* Try to remove the interface that was already there. */ |
| 5780 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 5781 | |
| 5782 | /* Try to create the interface again */ |
| 5783 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5784 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5787 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 5788 | wpa_printf(MSG_DEBUG, |
| 5789 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 5790 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5791 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5792 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5793 | |
| 5794 | return ret; |
| 5795 | } |
| 5796 | |
| 5797 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5798 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 5799 | { |
| 5800 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5801 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5802 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5803 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5804 | |
| 5805 | /* |
| 5806 | * Disable Probe Request reporting unless we need it in this way for |
| 5807 | * devices that include the AP SME, in the other case (unless using |
| 5808 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 5809 | */ |
| 5810 | if (!drv->device_ap_sme) |
| 5811 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5812 | |
| 5813 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5814 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5815 | return -1; |
| 5816 | |
| 5817 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5818 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5819 | wpa_printf(MSG_DEBUG, |
| 5820 | "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] | 5821 | |
| 5822 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5823 | nl80211_create_monitor_interface(drv) && |
| 5824 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5825 | return -1; |
| 5826 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5827 | if (drv->device_ap_sme && |
| 5828 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5829 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5830 | "Probe Request frame reporting in AP mode"); |
| 5831 | /* Try to survive without this */ |
| 5832 | } |
| 5833 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5834 | return 0; |
| 5835 | } |
| 5836 | |
| 5837 | |
| 5838 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5839 | { |
| 5840 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5841 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5842 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5843 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5844 | if (drv->device_ap_sme) { |
| 5845 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5846 | if (!drv->use_monitor) |
| 5847 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5848 | } else if (drv->use_monitor) |
| 5849 | nl80211_remove_monitor_interface(drv); |
| 5850 | else |
| 5851 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5852 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5853 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5854 | bss->beacon_set = 0; |
| 5855 | } |
| 5856 | |
| 5857 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5858 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 5859 | u16 proto, const u8 *buf, size_t len, |
| 5860 | int no_encrypt) |
| 5861 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5862 | struct nl80211_ack_ext_arg ext_arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5863 | struct i802_bss *bss = priv; |
| 5864 | struct nl_msg *msg; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5865 | u64 cookie = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5866 | int ret; |
| 5867 | |
| 5868 | wpa_printf(MSG_DEBUG, |
| 5869 | "nl80211: Send over control port dest=" MACSTR |
| 5870 | " proto=0x%04x len=%u no_encrypt=%d", |
| 5871 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 5872 | |
| 5873 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 5874 | if (!msg || |
| 5875 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 5876 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 5877 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 5878 | (no_encrypt && |
| 5879 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { |
| 5880 | nlmsg_free(msg); |
| 5881 | return -ENOBUFS; |
| 5882 | } |
| 5883 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5884 | os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg)); |
| 5885 | ext_arg.ext_data = &cookie; |
| 5886 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, |
| 5887 | ack_handler_cookie, &ext_arg); |
| 5888 | if (ret) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5889 | wpa_printf(MSG_DEBUG, |
| 5890 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 5891 | ret, strerror(-ret)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5892 | } else { |
| 5893 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5894 | |
| 5895 | wpa_printf(MSG_DEBUG, |
| 5896 | "nl80211: tx_control_port cookie=0x%llx", |
| 5897 | (long long unsigned int) cookie); |
| 5898 | drv->eapol_tx_cookie = cookie; |
| 5899 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5900 | |
| 5901 | return ret; |
| 5902 | } |
| 5903 | |
| 5904 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5905 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5906 | const u8 *addr, const u8 *data, |
| 5907 | size_t data_len) |
| 5908 | { |
| 5909 | struct sockaddr_ll ll; |
| 5910 | int ret; |
| 5911 | |
| 5912 | if (bss->drv->eapol_tx_sock < 0) { |
| 5913 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5914 | return -1; |
| 5915 | } |
| 5916 | |
| 5917 | os_memset(&ll, 0, sizeof(ll)); |
| 5918 | ll.sll_family = AF_PACKET; |
| 5919 | ll.sll_ifindex = bss->ifindex; |
| 5920 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5921 | ll.sll_halen = ETH_ALEN; |
| 5922 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5923 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5924 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5925 | if (ret < 0) |
| 5926 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5927 | strerror(errno)); |
| 5928 | |
| 5929 | return ret; |
| 5930 | } |
| 5931 | |
| 5932 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5933 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5934 | |
| 5935 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5936 | void *priv, const u8 *addr, const u8 *data, |
| 5937 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 5938 | { |
| 5939 | struct i802_bss *bss = priv; |
| 5940 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5941 | struct ieee80211_hdr *hdr; |
| 5942 | size_t len; |
| 5943 | u8 *pos; |
| 5944 | int res; |
| 5945 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5946 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5947 | /* For now, disable EAPOL TX over control port in AP mode by default |
| 5948 | * since it does not provide TX status notifications. */ |
| 5949 | if (drv->control_port_ap && |
| 5950 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5951 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
| 5952 | data, data_len, !encrypt); |
| 5953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5954 | if (drv->device_ap_sme || !drv->use_monitor) |
| 5955 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 5956 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5957 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 5958 | data_len; |
| 5959 | hdr = os_zalloc(len); |
| 5960 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5961 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 5962 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5963 | return -1; |
| 5964 | } |
| 5965 | |
| 5966 | hdr->frame_control = |
| 5967 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 5968 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 5969 | if (encrypt) |
| 5970 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 5971 | if (qos) { |
| 5972 | hdr->frame_control |= |
| 5973 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 5974 | } |
| 5975 | |
| 5976 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 5977 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 5978 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 5979 | pos = (u8 *) (hdr + 1); |
| 5980 | |
| 5981 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5982 | /* Set highest priority in QoS header */ |
| 5983 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | pos[1] = 0; |
| 5985 | pos += 2; |
| 5986 | } |
| 5987 | |
| 5988 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 5989 | pos += sizeof(rfc1042_header); |
| 5990 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 5991 | pos += 2; |
| 5992 | memcpy(pos, data, data_len); |
| 5993 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5994 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5995 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5996 | wpa_printf(MSG_ERROR, |
| 5997 | "hapd_send_eapol - packet len: %lu - failed", |
| 5998 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5999 | } |
| 6000 | os_free(hdr); |
| 6001 | |
| 6002 | return res; |
| 6003 | } |
| 6004 | |
| 6005 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6006 | 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] | 6007 | unsigned int total_flags, |
| 6008 | unsigned int flags_or, |
| 6009 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | { |
| 6011 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6012 | struct nl_msg *msg; |
| 6013 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 | struct nl80211_sta_flag_update upd; |
| 6015 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6016 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 6017 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 6018 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 6019 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 6020 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6021 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6022 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 6023 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6024 | |
| 6025 | /* |
| 6026 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 6027 | * can be removed eventually. |
| 6028 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6029 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6030 | if (!flags || |
| 6031 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 6032 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 6033 | ((total_flags & WPA_STA_WMM) && |
| 6034 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 6035 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 6036 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 6037 | ((total_flags & WPA_STA_MFP) && |
| 6038 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 6039 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 6040 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 6041 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6042 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6043 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6044 | |
| 6045 | os_memset(&upd, 0, sizeof(upd)); |
| 6046 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 6047 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6048 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 6049 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6050 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6051 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6052 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6053 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6054 | return -ENOBUFS; |
| 6055 | } |
| 6056 | |
| 6057 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6058 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 6059 | unsigned int weight) |
| 6060 | { |
| 6061 | struct i802_bss *bss = priv; |
| 6062 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6063 | int ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6064 | |
| 6065 | wpa_printf(MSG_DEBUG, |
| 6066 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 6067 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 6068 | |
| 6069 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6070 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6071 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 6072 | goto fail; |
| 6073 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6074 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
| 6075 | if (ret) { |
| 6076 | wpa_printf(MSG_DEBUG, |
| 6077 | "nl80211: SET_STATION[AIRTIME_WEIGHT] failed: ret=%d (%s)", |
| 6078 | ret, strerror(-ret)); |
| 6079 | } |
| 6080 | return ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6081 | fail: |
| 6082 | nlmsg_free(msg); |
| 6083 | return -ENOBUFS; |
| 6084 | } |
| 6085 | |
| 6086 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6087 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 6088 | struct wpa_driver_associate_params *params) |
| 6089 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6090 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6091 | |
| 6092 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6093 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 6094 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6095 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 6096 | } else |
| 6097 | nlmode = NL80211_IFTYPE_AP; |
| 6098 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6099 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6100 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6101 | nl80211_remove_monitor_interface(drv); |
| 6102 | return -1; |
| 6103 | } |
| 6104 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6105 | if (params->freq.freq && |
| 6106 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6107 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6108 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6109 | nl80211_remove_monitor_interface(drv); |
| 6110 | return -1; |
| 6111 | } |
| 6112 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6113 | return 0; |
| 6114 | } |
| 6115 | |
| 6116 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6117 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 6118 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | { |
| 6120 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6121 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6122 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6123 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6124 | 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] | 6125 | if (ret) { |
| 6126 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 6127 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6128 | } else { |
| 6129 | wpa_printf(MSG_DEBUG, |
| 6130 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6131 | } |
| 6132 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6133 | if (reset_mode && |
| 6134 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6135 | NL80211_IFTYPE_STATION)) { |
| 6136 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6137 | "station mode"); |
| 6138 | } |
| 6139 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6140 | return ret; |
| 6141 | } |
| 6142 | |
| 6143 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6144 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 6145 | struct wpa_driver_associate_params *params) |
| 6146 | { |
| 6147 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 6148 | return -1; |
| 6149 | |
| 6150 | if (params->htcaps && params->htcaps_mask) { |
| 6151 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 6152 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 6153 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 6154 | params->htcaps_mask, sz); |
| 6155 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 6156 | params->htcaps) || |
| 6157 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 6158 | params->htcaps_mask)) |
| 6159 | return -1; |
| 6160 | } |
| 6161 | |
| 6162 | #ifdef CONFIG_VHT_OVERRIDES |
| 6163 | if (params->disable_vht) { |
| 6164 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 6165 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 6166 | return -1; |
| 6167 | } |
| 6168 | |
| 6169 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 6170 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 6171 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 6172 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 6173 | params->vhtcaps_mask, sz); |
| 6174 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 6175 | params->vhtcaps) || |
| 6176 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 6177 | params->vhtcaps_mask)) |
| 6178 | return -1; |
| 6179 | } |
| 6180 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 6181 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6182 | #ifdef CONFIG_HE_OVERRIDES |
| 6183 | if (params->disable_he) { |
| 6184 | wpa_printf(MSG_DEBUG, " * HE disabled"); |
| 6185 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_HE)) |
| 6186 | return -1; |
| 6187 | } |
| 6188 | #endif /* CONFIG_HE_OVERRIDES */ |
| 6189 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6190 | return 0; |
| 6191 | } |
| 6192 | |
| 6193 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6194 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 6195 | struct wpa_driver_associate_params *params) |
| 6196 | { |
| 6197 | struct nl_msg *msg; |
| 6198 | int ret = -1; |
| 6199 | int count = 0; |
| 6200 | |
| 6201 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 6202 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6203 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6204 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6205 | "IBSS mode"); |
| 6206 | return -1; |
| 6207 | } |
| 6208 | |
| 6209 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6210 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 6211 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 6212 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6213 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6214 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6215 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6216 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 6217 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6218 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6219 | drv->ssid_len = params->ssid_len; |
| 6220 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6221 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 6222 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6223 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | |
| 6225 | ret = nl80211_set_conn_keys(params, msg); |
| 6226 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6227 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6228 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6229 | if (params->bssid && params->fixed_bssid) { |
| 6230 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 6231 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6232 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6233 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6234 | } |
| 6235 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6236 | if (params->fixed_freq) { |
| 6237 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 6238 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 6239 | goto fail; |
| 6240 | } |
| 6241 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6242 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6243 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6244 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 6245 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6246 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6247 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6248 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6249 | } |
| 6250 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6251 | if (params->wpa_ie) { |
| 6252 | wpa_hexdump(MSG_DEBUG, |
| 6253 | " * Extra IEs for Beacon/Probe Response frames", |
| 6254 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6255 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 6256 | params->wpa_ie)) |
| 6257 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6258 | } |
| 6259 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 6260 | ret = nl80211_ht_vht_overrides(msg, params); |
| 6261 | if (ret < 0) |
| 6262 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6263 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6264 | 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] | 6265 | msg = NULL; |
| 6266 | if (ret) { |
| 6267 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 6268 | ret, strerror(-ret)); |
| 6269 | count++; |
| 6270 | if (ret == -EALREADY && count == 1) { |
| 6271 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 6272 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6273 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | nlmsg_free(msg); |
| 6275 | goto retry; |
| 6276 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6277 | } else { |
| 6278 | wpa_printf(MSG_DEBUG, |
| 6279 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6280 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6281 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6282 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6283 | nlmsg_free(msg); |
| 6284 | return ret; |
| 6285 | } |
| 6286 | |
| 6287 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6288 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 6289 | struct wpa_driver_associate_params *params, |
| 6290 | struct nl_msg *msg) |
| 6291 | { |
| 6292 | if (params->fils_erp_username_len) { |
| 6293 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 6294 | params->fils_erp_username, |
| 6295 | params->fils_erp_username_len); |
| 6296 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 6297 | params->fils_erp_username_len, |
| 6298 | params->fils_erp_username)) |
| 6299 | return -1; |
| 6300 | } |
| 6301 | |
| 6302 | if (params->fils_erp_realm_len) { |
| 6303 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 6304 | params->fils_erp_realm, |
| 6305 | params->fils_erp_realm_len); |
| 6306 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 6307 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 6308 | return -1; |
| 6309 | } |
| 6310 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6311 | if (params->fils_erp_rrk_len) { |
Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 6312 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 6313 | params->fils_erp_next_seq_num); |
| 6314 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 6315 | params->fils_erp_next_seq_num)) |
| 6316 | return -1; |
| 6317 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6318 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 6319 | (unsigned long) params->fils_erp_rrk_len); |
| 6320 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 6321 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 6322 | return -1; |
| 6323 | } |
| 6324 | |
| 6325 | return 0; |
| 6326 | } |
| 6327 | |
| 6328 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6329 | static unsigned int num_bits_set(u32 val) |
| 6330 | { |
| 6331 | unsigned int c; |
| 6332 | |
| 6333 | for (c = 0; val; c++) |
| 6334 | val &= val - 1; |
| 6335 | |
| 6336 | return c; |
| 6337 | } |
| 6338 | |
| 6339 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6340 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 6341 | struct wpa_driver_associate_params *params, |
| 6342 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6343 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6344 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 6345 | return -1; |
| 6346 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6347 | if (params->bssid) { |
| 6348 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 6349 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6350 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6351 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6352 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6353 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6354 | if (params->bssid_hint) { |
| 6355 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 6356 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6357 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 6358 | params->bssid_hint)) |
| 6359 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6360 | } |
| 6361 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6362 | if (params->freq.freq) { |
| 6363 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6364 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6365 | params->freq.freq)) |
| 6366 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6367 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6368 | } else |
| 6369 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6370 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6371 | if (params->freq_hint) { |
| 6372 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 6374 | params->freq_hint)) |
| 6375 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6376 | } |
| 6377 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6378 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 6379 | wpa_printf(MSG_DEBUG, |
| 6380 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 6381 | params->freq.edmg.channels, |
| 6382 | params->freq.edmg.bw_config); |
| 6383 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 6384 | params->freq.edmg.channels) || |
| 6385 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 6386 | params->freq.edmg.bw_config)) |
| 6387 | return -1; |
| 6388 | } |
| 6389 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6390 | if (params->bg_scan_period >= 0) { |
| 6391 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 6392 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6393 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 6394 | params->bg_scan_period)) |
| 6395 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6396 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6398 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6399 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6400 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6401 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6402 | params->ssid)) |
| 6403 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6404 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6405 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6407 | drv->ssid_len = params->ssid_len; |
| 6408 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6409 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6410 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6411 | if (params->wpa_ie && |
| 6412 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 6413 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6414 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6415 | if (params->wpa_proto) { |
| 6416 | enum nl80211_wpa_versions ver = 0; |
| 6417 | |
| 6418 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 6419 | ver |= NL80211_WPA_VERSION_1; |
| 6420 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 6421 | ver |= NL80211_WPA_VERSION_2; |
| 6422 | |
| 6423 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6424 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 6425 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 6429 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 6430 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6431 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 6432 | cipher)) |
| 6433 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6434 | } |
| 6435 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6436 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 6437 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 6438 | /* |
| 6439 | * This is likely to work even though many drivers do not |
| 6440 | * advertise support for operations without GTK. |
| 6441 | */ |
| 6442 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 6443 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6444 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 6445 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6446 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 6447 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6451 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6452 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 6453 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6454 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6455 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 6456 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6457 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6458 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6459 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE_EXT_KEY || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6460 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6461 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE_EXT_KEY || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6462 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6463 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6464 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6465 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 6466 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 6467 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6468 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 6469 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 6470 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6471 | u32 *mgmt; |
| 6472 | unsigned int akm_count = 1, i; |
| 6473 | |
| 6474 | /* |
| 6475 | * Make sure the driver has capability to handle default AKM in |
| 6476 | * key_mgmt_suite plus allowed AKMs in allowed_key_mgmts. |
| 6477 | */ |
| 6478 | if (drv->capa.max_num_akms <= |
| 6479 | num_bits_set(params->allowed_key_mgmts)) { |
| 6480 | wpa_printf(MSG_INFO, |
| 6481 | "nl80211: Not enough support for the allowed AKMs (max_num_akms=%u <= num_bits_set=%u)", |
| 6482 | drv->capa.max_num_akms, |
| 6483 | num_bits_set(params->allowed_key_mgmts)); |
| 6484 | return -1; |
| 6485 | } |
| 6486 | |
| 6487 | mgmt = os_malloc(sizeof(u32) * drv->capa.max_num_akms); |
| 6488 | if (!mgmt) |
| 6489 | return -1; |
| 6490 | |
| 6491 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6492 | |
| 6493 | switch (params->key_mgmt_suite) { |
| 6494 | case WPA_KEY_MGMT_CCKM: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6495 | mgmt[0] = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6496 | break; |
| 6497 | case WPA_KEY_MGMT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6498 | mgmt[0] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6499 | break; |
| 6500 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6501 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6502 | break; |
| 6503 | case WPA_KEY_MGMT_FT_PSK: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6504 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6505 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6506 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6507 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6508 | break; |
| 6509 | case WPA_KEY_MGMT_PSK_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6510 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6511 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6512 | case WPA_KEY_MGMT_OSEN: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6513 | mgmt[0] = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6514 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6515 | case WPA_KEY_MGMT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6516 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE; |
| 6517 | break; |
| 6518 | case WPA_KEY_MGMT_SAE_EXT_KEY: |
| 6519 | mgmt[0] = RSN_AUTH_KEY_MGMT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6520 | break; |
| 6521 | case WPA_KEY_MGMT_FT_SAE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6522 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 6523 | break; |
| 6524 | case WPA_KEY_MGMT_FT_SAE_EXT_KEY: |
| 6525 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6526 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6527 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6528 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6529 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6530 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6531 | mgmt[0] = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6532 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6533 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6534 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6535 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6536 | case WPA_KEY_MGMT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6537 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6538 | break; |
| 6539 | case WPA_KEY_MGMT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6540 | mgmt[0] = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6541 | break; |
| 6542 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6543 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6544 | break; |
| 6545 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6546 | mgmt[0] = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6547 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6548 | case WPA_KEY_MGMT_OWE: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6549 | mgmt[0] = RSN_AUTH_KEY_MGMT_OWE; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6550 | break; |
| 6551 | case WPA_KEY_MGMT_DPP: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6552 | mgmt[0] = RSN_AUTH_KEY_MGMT_DPP; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6553 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6554 | case WPA_KEY_MGMT_PSK: |
| 6555 | default: |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6556 | mgmt[0] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6557 | break; |
| 6558 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6559 | |
| 6560 | if (drv->capa.max_num_akms > 1) { |
| 6561 | akm_count += wpa_key_mgmt_to_suites( |
| 6562 | params->allowed_key_mgmts, &mgmt[1], |
| 6563 | drv->capa.max_num_akms - 1); |
| 6564 | } |
| 6565 | |
| 6566 | for (i = 0; i < akm_count; i++) |
| 6567 | wpa_printf(MSG_DEBUG, " * akm[%d]=0x%x", i, mgmt[i]); |
| 6568 | |
| 6569 | if (nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 6570 | akm_count * sizeof(u32), mgmt)) { |
| 6571 | os_free(mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6572 | return -1; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | os_free(mgmt); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6576 | } |
| 6577 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6578 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6579 | if (IS_CROSS_AKM_ROAM_KEY_MGMT(params->key_mgmt_suite)) { |
| 6580 | int num_suites; |
| 6581 | u32 suites[NL80211_MAX_NR_AKM_SUITES]; |
| 6582 | |
| 6583 | wpa_printf(MSG_INFO, "nl80211: key_mgmt_suites=0x%x", |
| 6584 | params->key_mgmt_suite); |
| 6585 | num_suites = wpa_cross_akm_key_mgmt_to_suites(params->key_mgmt_suite, |
| 6586 | suites, ARRAY_SIZE(suites)); |
| 6587 | if (num_suites && |
| 6588 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), suites)) { |
| 6589 | wpa_printf(MSG_ERROR, "Updating multi akm_suite failed"); |
| 6590 | return -1; |
| 6591 | } |
| 6592 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6593 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6594 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6595 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 6596 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 6597 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 6598 | return -1; |
| 6599 | } |
| 6600 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6601 | /* Add PSK in case of 4-way handshake offload */ |
| 6602 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6603 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6604 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 6605 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 6606 | return -1; |
| 6607 | } |
| 6608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6609 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6610 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6611 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 6612 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 6613 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 6614 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 6615 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 6616 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 6617 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 6618 | return -1; |
| 6619 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6620 | if (params->rrm_used) { |
| 6621 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6622 | if ((!((drv_rrm_flags & |
| 6623 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 6624 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 6625 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6626 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 6627 | return -1; |
| 6628 | } |
| 6629 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6630 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6631 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6632 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6633 | if (params->p2p) |
| 6634 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 6635 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6636 | if (params->pbss) { |
| 6637 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 6638 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 6639 | return -1; |
| 6640 | } |
| 6641 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6642 | drv->connect_reassoc = 0; |
| 6643 | if (params->prev_bssid) { |
| 6644 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 6645 | MAC2STR(params->prev_bssid)); |
| 6646 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 6647 | params->prev_bssid)) |
| 6648 | return -1; |
| 6649 | drv->connect_reassoc = 1; |
| 6650 | } |
| 6651 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6652 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 6653 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 6654 | return -1; |
| 6655 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6656 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6657 | if (((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6658 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) && |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6659 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6660 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6661 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6662 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6663 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 6664 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 6665 | return -1; |
| 6666 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6667 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | |
| 6671 | static int wpa_driver_nl80211_try_connect( |
| 6672 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6673 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6674 | struct i802_bss *bss) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6675 | { |
| 6676 | struct nl_msg *msg; |
| 6677 | enum nl80211_auth_type type; |
| 6678 | int ret; |
| 6679 | int algs; |
| 6680 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6681 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6682 | if (params->req_key_mgmt_offload && params->psk && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6683 | (wpa_key_mgmt_wpa_psk_no_sae(params->key_mgmt_suite) || |
| 6684 | wpa_key_mgmt_wpa_psk_no_sae(params->allowed_key_mgmts))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6685 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 6686 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 6687 | if (ret) |
| 6688 | return ret; |
| 6689 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6690 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6691 | |
| 6692 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 6693 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6694 | if (!msg) |
| 6695 | return -1; |
| 6696 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6697 | ret = nl80211_connect_common(drv, params, msg); |
| 6698 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6699 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6700 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6701 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6702 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6703 | goto fail; |
| 6704 | |
| 6705 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 6706 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 6707 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 6708 | goto fail; |
| 6709 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6710 | #ifdef CONFIG_SAE |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6711 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6712 | if (((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6713 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) && |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6714 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6715 | if ((wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6716 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6717 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6718 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 6719 | goto fail; |
| 6720 | #endif /* CONFIG_SAE */ |
| 6721 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6722 | algs = 0; |
| 6723 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6724 | algs++; |
| 6725 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6726 | algs++; |
| 6727 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6728 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6729 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 6730 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6731 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6732 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6733 | if (algs > 1) { |
| 6734 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 6735 | "selection"); |
| 6736 | goto skip_auth_type; |
| 6737 | } |
| 6738 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6739 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6740 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6741 | if (type == NL80211_AUTHTYPE_MAX || |
| 6742 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6743 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6744 | |
| 6745 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6746 | ret = nl80211_set_conn_keys(params, msg); |
| 6747 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6748 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6749 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6750 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6751 | msg = NULL; |
| 6752 | if (ret) { |
| 6753 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 6754 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6755 | } else { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6756 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 6757 | drv->roam_indication_done = false; |
| 6758 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6759 | wpa_printf(MSG_DEBUG, |
| 6760 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6761 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6762 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6763 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6764 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6765 | nlmsg_free(msg); |
| 6766 | return ret; |
| 6767 | |
| 6768 | } |
| 6769 | |
| 6770 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6771 | static int wpa_driver_nl80211_connect( |
| 6772 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6773 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6774 | struct i802_bss *bss) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6775 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6776 | int ret; |
| 6777 | |
| 6778 | /* Store the connection attempted bssid for future use */ |
| 6779 | if (params->bssid) |
| 6780 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 6781 | else |
| 6782 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 6783 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6784 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6785 | if (ret == -EALREADY) { |
| 6786 | /* |
| 6787 | * cfg80211 does not currently accept new connections if |
| 6788 | * we are already connected. As a workaround, force |
| 6789 | * disconnection and try again. |
| 6790 | */ |
| 6791 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 6792 | "disconnecting before reassociation " |
| 6793 | "attempt"); |
| 6794 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6795 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, bss)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6796 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6797 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6798 | } |
| 6799 | return ret; |
| 6800 | } |
| 6801 | |
| 6802 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6803 | static int wpa_driver_nl80211_associate( |
| 6804 | void *priv, struct wpa_driver_associate_params *params) |
| 6805 | { |
| 6806 | struct i802_bss *bss = priv; |
| 6807 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6808 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6809 | struct nl_msg *msg; |
| 6810 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6811 | nl80211_unmask_11b_rates(bss); |
| 6812 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6813 | if (params->mode == IEEE80211_MODE_AP) |
| 6814 | return wpa_driver_nl80211_ap(drv, params); |
| 6815 | |
| 6816 | if (params->mode == IEEE80211_MODE_IBSS) |
| 6817 | return wpa_driver_nl80211_ibss(drv, params); |
| 6818 | |
| 6819 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6820 | enum nl80211_iftype nlmode = params->p2p ? |
| 6821 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 6822 | |
| 6823 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6824 | return -1; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6825 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6826 | if ((params->key_mgmt_suite & WPA_KEY_MGMT_SAE) || |
| 6827 | (params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE)) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 6828 | #else |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6829 | if (wpa_key_mgmt_sae(params->key_mgmt_suite) || |
| 6830 | wpa_key_mgmt_sae(params->allowed_key_mgmts)) |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 6831 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6832 | bss->use_nl_connect = 1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6833 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6834 | bss->use_nl_connect = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6835 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6836 | return wpa_driver_nl80211_connect(drv, params, bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6837 | } |
| 6838 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6839 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6840 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6841 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 6842 | drv->ifindex); |
| 6843 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6844 | if (!msg) |
| 6845 | return -1; |
| 6846 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6847 | ret = nl80211_connect_common(drv, params, msg); |
| 6848 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6849 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6850 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6851 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6852 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6853 | goto fail; |
| 6854 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6855 | if (params->fils_kek) { |
| 6856 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 6857 | (unsigned int) params->fils_kek_len); |
| 6858 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 6859 | params->fils_kek)) |
| 6860 | goto fail; |
| 6861 | } |
| 6862 | if (params->fils_nonces) { |
| 6863 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 6864 | params->fils_nonces, |
| 6865 | params->fils_nonces_len); |
| 6866 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 6867 | params->fils_nonces_len, params->fils_nonces)) |
| 6868 | goto fail; |
| 6869 | } |
| 6870 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6871 | 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] | 6872 | msg = NULL; |
| 6873 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6874 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6875 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 6876 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6877 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6878 | } else { |
| 6879 | wpa_printf(MSG_DEBUG, |
| 6880 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6881 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6882 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6883 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6884 | nlmsg_free(msg); |
| 6885 | return ret; |
| 6886 | } |
| 6887 | |
| 6888 | |
| 6889 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6890 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6891 | { |
| 6892 | struct nl_msg *msg; |
| 6893 | int ret = -ENOBUFS; |
| 6894 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6895 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 6896 | ifindex, mode, nl80211_iftype_str(mode)); |
| 6897 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6898 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 6899 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 6900 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6901 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6902 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6903 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6904 | if (!ret) |
| 6905 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6906 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6907 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6908 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 6909 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 6910 | return ret; |
| 6911 | } |
| 6912 | |
| 6913 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6914 | static int wpa_driver_nl80211_set_mode_impl( |
| 6915 | struct i802_bss *bss, |
| 6916 | enum nl80211_iftype nlmode, |
| 6917 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6918 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6920 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6921 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6922 | int was_ap = is_ap_interface(drv->nlmode); |
| 6923 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6924 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6925 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6926 | if (TEST_FAIL()) |
| 6927 | return -1; |
| 6928 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6929 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6930 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 6931 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6932 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6933 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6934 | drv->nlmode = nlmode; |
| 6935 | ret = 0; |
| 6936 | goto done; |
| 6937 | } |
| 6938 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6939 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6940 | return -1; |
| 6941 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6942 | if (nlmode == drv->nlmode) { |
| 6943 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 6944 | "requested mode - ignore error"); |
| 6945 | ret = 0; |
| 6946 | goto done; /* Already in the requested mode */ |
| 6947 | } |
| 6948 | |
| 6949 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 6950 | * take the device down, try to set the mode again, and bring the |
| 6951 | * device back up. |
| 6952 | */ |
| 6953 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 6954 | "interface down"); |
| 6955 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6956 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6957 | if (res == -EACCES || res == -ENODEV) |
| 6958 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6959 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6960 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 6961 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6962 | os_sleep(0, 100000); |
| 6963 | continue; |
| 6964 | } |
| 6965 | |
| 6966 | /* |
| 6967 | * Setting the mode will fail for some drivers if the phy is |
| 6968 | * on a frequency that the mode is disallowed in. |
| 6969 | */ |
| 6970 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6971 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6972 | if (res) { |
| 6973 | wpa_printf(MSG_DEBUG, |
| 6974 | "nl80211: Failed to set frequency on interface"); |
| 6975 | } |
| 6976 | } |
| 6977 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6978 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && |
| 6979 | bss->brname[0] && |
| 6980 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 6981 | wpa_printf(MSG_DEBUG, |
| 6982 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", |
| 6983 | bss->ifname, bss->brname); |
| 6984 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 6985 | bss->brname, bss->ifname) < 0) |
| 6986 | wpa_printf(MSG_INFO, |
| 6987 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 6988 | bss->ifname, bss->brname, |
| 6989 | strerror(errno)); |
| 6990 | } |
| 6991 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6992 | /* Try to set the mode again while the interface is down */ |
| 6993 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6994 | if (mode_switch_res == -EBUSY) { |
| 6995 | wpa_printf(MSG_DEBUG, |
| 6996 | "nl80211: Delaying mode set while interface going down"); |
| 6997 | os_sleep(0, 100000); |
| 6998 | continue; |
| 6999 | } |
| 7000 | ret = mode_switch_res; |
| 7001 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | if (!ret) { |
| 7005 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 7006 | "interface is down"); |
| 7007 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7008 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7009 | } |
| 7010 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7011 | /* Bring the interface back up */ |
| 7012 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 7013 | if (res != 0) { |
| 7014 | wpa_printf(MSG_DEBUG, |
| 7015 | "nl80211: Failed to set interface up after switching mode"); |
| 7016 | ret = -1; |
| 7017 | } |
| 7018 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7019 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7020 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 7022 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7023 | return ret; |
| 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 | if (is_p2p_net_interface(nlmode)) { |
| 7027 | wpa_printf(MSG_DEBUG, |
| 7028 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 7029 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7030 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7031 | } else if (drv->disabled_11b_rates) { |
| 7032 | wpa_printf(MSG_DEBUG, |
| 7033 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 7034 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7035 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7036 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7037 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7038 | if (is_ap_interface(nlmode)) { |
| 7039 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 7040 | /* Setup additional AP mode functionality if needed */ |
| 7041 | if (nl80211_setup_ap(bss)) |
| 7042 | return -1; |
| 7043 | } else if (was_ap) { |
| 7044 | /* Remove additional AP mode functionality */ |
| 7045 | nl80211_teardown_ap(bss); |
| 7046 | } else { |
| 7047 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 7048 | } |
| 7049 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7050 | if (is_mesh_interface(nlmode) && |
| 7051 | nl80211_mgmt_subscribe_mesh(bss)) |
| 7052 | return -1; |
| 7053 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7054 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7055 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7056 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 7057 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 7058 | "frame processing - ignore for now"); |
| 7059 | |
| 7060 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7064 | void nl80211_restore_ap_mode(struct i802_bss *bss) |
| 7065 | { |
| 7066 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7067 | int was_ap = is_ap_interface(drv->nlmode); |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7068 | int br_ifindex; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7069 | |
| 7070 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); |
| 7071 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && |
| 7072 | bss->brname[0] && |
| 7073 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 7074 | wpa_printf(MSG_DEBUG, |
| 7075 | "nl80211: Add AP interface %s back into the bridge %s", |
| 7076 | bss->ifname, bss->brname); |
| 7077 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, |
| 7078 | bss->ifname) < 0) { |
| 7079 | wpa_printf(MSG_WARNING, |
| 7080 | "nl80211: Failed to add interface %s into bridge %s: %s", |
| 7081 | bss->ifname, bss->brname, strerror(errno)); |
| 7082 | } |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 7083 | br_ifindex = if_nametoindex(bss->brname); |
| 7084 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7085 | } |
| 7086 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
| 7087 | } |
| 7088 | |
| 7089 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7090 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 7091 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7092 | { |
| 7093 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 7094 | } |
| 7095 | |
| 7096 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7097 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 7098 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7099 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7100 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7101 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7105 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 7106 | struct wpa_driver_capa *capa) |
| 7107 | { |
| 7108 | struct i802_bss *bss = priv; |
| 7109 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 7110 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7111 | if (!drv->has_capability) |
| 7112 | return -1; |
| 7113 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7114 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 7115 | capa->extended_capa = drv->extended_capa; |
| 7116 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 7117 | capa->extended_capa_len = drv->extended_capa_len; |
| 7118 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7119 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7120 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7121 | } |
| 7122 | |
| 7123 | |
| 7124 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 7125 | { |
| 7126 | struct i802_bss *bss = priv; |
| 7127 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7128 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7129 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 7130 | bss->ifname, drv->operstate, state, |
| 7131 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7132 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7133 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7134 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 7135 | } |
| 7136 | |
| 7137 | |
| 7138 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 7139 | { |
| 7140 | struct i802_bss *bss = priv; |
| 7141 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7142 | struct nl_msg *msg; |
| 7143 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7144 | int ret; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7145 | const u8 *connected_addr = drv->sta_mlo_info.valid_links ? |
| 7146 | drv->sta_mlo_info.ap_mld_addr : drv->bssid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7147 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7148 | if (!drv->associated && is_zero_ether_addr(connected_addr) && |
| 7149 | !authorized) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7150 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 7151 | return 0; |
| 7152 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7153 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7154 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7155 | MACSTR, authorized ? "" : "un", MAC2STR(connected_addr)); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7156 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7157 | os_memset(&upd, 0, sizeof(upd)); |
| 7158 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7159 | if (authorized) |
| 7160 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7161 | |
| 7162 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 7163 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7164 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 7165 | nlmsg_free(msg); |
| 7166 | return -ENOBUFS; |
| 7167 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7168 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7169 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7170 | if (!ret) |
| 7171 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7172 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 7173 | ret, strerror(-ret)); |
| 7174 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7175 | } |
| 7176 | |
| 7177 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7178 | /* Set kernel driver on given frequency (MHz) */ |
| 7179 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7180 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7181 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 7182 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7186 | static inline int min_int(int a, int b) |
| 7187 | { |
| 7188 | if (a < b) |
| 7189 | return a; |
| 7190 | return b; |
| 7191 | } |
| 7192 | |
| 7193 | |
| 7194 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 7195 | { |
| 7196 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7197 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7198 | |
| 7199 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7200 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7201 | |
| 7202 | /* |
| 7203 | * TODO: validate the key index and mac address! |
| 7204 | * Otherwise, there's a race condition as soon as |
| 7205 | * the kernel starts sending key notifications. |
| 7206 | */ |
| 7207 | |
| 7208 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 7209 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 7210 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7211 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7212 | return NL_SKIP; |
| 7213 | } |
| 7214 | |
| 7215 | |
| 7216 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 7217 | int idx, u8 *seq) |
| 7218 | { |
| 7219 | struct i802_bss *bss = priv; |
| 7220 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7221 | struct nl_msg *msg; |
| 7222 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7223 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 7224 | NL80211_CMD_GET_KEY); |
| 7225 | if (!msg || |
| 7226 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7227 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 7228 | nlmsg_free(msg); |
| 7229 | return -ENOBUFS; |
| 7230 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7231 | |
| 7232 | memset(seq, 0, 6); |
| 7233 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7234 | 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] | 7235 | } |
| 7236 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7237 | |
| 7238 | static int i802_set_rts(void *priv, int rts) |
| 7239 | { |
| 7240 | struct i802_bss *bss = priv; |
| 7241 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7242 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7243 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7244 | u32 val; |
| 7245 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7246 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7247 | val = (u32) -1; |
| 7248 | else |
| 7249 | val = rts; |
| 7250 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7251 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7252 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 7253 | nlmsg_free(msg); |
| 7254 | return -ENOBUFS; |
| 7255 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7256 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7257 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7258 | if (!ret) |
| 7259 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7260 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 7261 | "%d (%s)", rts, ret, strerror(-ret)); |
| 7262 | return ret; |
| 7263 | } |
| 7264 | |
| 7265 | |
| 7266 | static int i802_set_frag(void *priv, int frag) |
| 7267 | { |
| 7268 | struct i802_bss *bss = priv; |
| 7269 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7270 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7271 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7272 | u32 val; |
| 7273 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7274 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7275 | val = (u32) -1; |
| 7276 | else |
| 7277 | val = frag; |
| 7278 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7279 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7280 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 7281 | nlmsg_free(msg); |
| 7282 | return -ENOBUFS; |
| 7283 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7284 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7285 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7286 | if (!ret) |
| 7287 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7288 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 7289 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 7290 | return ret; |
| 7291 | } |
| 7292 | |
| 7293 | |
| 7294 | static int i802_flush(void *priv) |
| 7295 | { |
| 7296 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7297 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7298 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7299 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7300 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 7301 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7302 | |
| 7303 | /* |
| 7304 | * XXX: FIX! this needs to flush all VLANs too |
| 7305 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7306 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7307 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7308 | if (res) { |
| 7309 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 7310 | "(%s)", res, strerror(-res)); |
| 7311 | } |
| 7312 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7313 | } |
| 7314 | |
| 7315 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7316 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 7317 | struct nlattr *attr) |
| 7318 | { |
| 7319 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 7320 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 7321 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 7322 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 7323 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 7324 | }; |
| 7325 | int rem; |
| 7326 | |
| 7327 | nla_for_each_nested(tidattr, attr, rem) { |
| 7328 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 7329 | tidattr, NULL) != 0 || |
| 7330 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 7331 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 7332 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 7333 | txq_stats_policy) != 0) |
| 7334 | continue; |
| 7335 | /* sum the backlogs over all TIDs for station */ |
| 7336 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 7337 | data->backlog_bytes += nla_get_u32( |
| 7338 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 7339 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 7340 | data->backlog_bytes += nla_get_u32( |
| 7341 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 7342 | } |
| 7343 | } |
| 7344 | |
| 7345 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7346 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 7347 | { |
| 7348 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7349 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7350 | struct hostap_sta_driver_data *data = arg; |
| 7351 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 7352 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 7353 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 7354 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 7355 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 7356 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 7357 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7358 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7359 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 7360 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7361 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7362 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7363 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
| 7364 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7365 | [NL80211_STA_INFO_CONNECTED_TIME] = { .type = NLA_U32 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7366 | }; |
| 7367 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 7368 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 7369 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 7370 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 7371 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 7372 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 7373 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 7374 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7375 | }; |
| 7376 | |
| 7377 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7378 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7379 | |
| 7380 | /* |
| 7381 | * TODO: validate the interface and mac address! |
| 7382 | * Otherwise, there's a race condition as soon as |
| 7383 | * the kernel starts sending station notifications. |
| 7384 | */ |
| 7385 | |
| 7386 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 7387 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 7388 | return NL_SKIP; |
| 7389 | } |
| 7390 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 7391 | tb[NL80211_ATTR_STA_INFO], |
| 7392 | stats_policy)) { |
| 7393 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 7394 | return NL_SKIP; |
| 7395 | } |
| 7396 | |
| 7397 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 7398 | data->inactive_msec = |
| 7399 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7400 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7401 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 7402 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 7403 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 7404 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7405 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 7406 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 7407 | /* |
| 7408 | * The driver supports 64-bit counters, so use them to override |
| 7409 | * the 32-bit values. |
| 7410 | */ |
| 7411 | data->rx_bytes = |
| 7412 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 7413 | data->tx_bytes = |
| 7414 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 7415 | data->bytes_64bit = 1; |
| 7416 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7417 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 7418 | data->rx_packets = |
| 7419 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 7420 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 7421 | data->tx_packets = |
| 7422 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7423 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 7424 | data->rx_airtime = |
| 7425 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 7426 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 7427 | data->tx_airtime = |
| 7428 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7429 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 7430 | data->tx_retry_failed = |
| 7431 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7432 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 7433 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7434 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 7435 | data->last_ack_rssi = |
| 7436 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 7437 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 7438 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7439 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7440 | if (stats[NL80211_STA_INFO_CONNECTED_TIME]) { |
| 7441 | data->connected_sec = |
| 7442 | nla_get_u32(stats[NL80211_STA_INFO_CONNECTED_TIME]); |
| 7443 | data->flags |= STA_DRV_DATA_CONN_TIME; |
| 7444 | } |
| 7445 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7446 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 7447 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7448 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 7449 | rate_policy) == 0) { |
| 7450 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7451 | data->current_tx_rate = |
| 7452 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7453 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7454 | data->current_tx_rate = |
| 7455 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7456 | |
| 7457 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 7458 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 7459 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 7460 | } |
| 7461 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7462 | data->tx_vhtmcs = |
| 7463 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7464 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 7465 | } |
| 7466 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7467 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 7468 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7469 | data->tx_vht_nss = |
| 7470 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7471 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 7472 | } |
| 7473 | } |
| 7474 | |
| 7475 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 7476 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7477 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 7478 | rate_policy) == 0) { |
| 7479 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7480 | data->current_rx_rate = |
| 7481 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7482 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7483 | data->current_rx_rate = |
| 7484 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7485 | |
| 7486 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 7487 | data->rx_mcs = |
| 7488 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 7489 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 7490 | } |
| 7491 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7492 | data->rx_vhtmcs = |
| 7493 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7494 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 7495 | } |
| 7496 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7497 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 7498 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7499 | data->rx_vht_nss = |
| 7500 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7501 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 7502 | } |
| 7503 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7504 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7505 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 7506 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 7507 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7508 | return NL_SKIP; |
| 7509 | } |
| 7510 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7511 | static int i802_read_sta_data(struct i802_bss *bss, |
| 7512 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7513 | const u8 *addr) |
| 7514 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7515 | struct nl_msg *msg; |
| 7516 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7517 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 7518 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7519 | nlmsg_free(msg); |
| 7520 | return -ENOBUFS; |
| 7521 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7522 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7523 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data, |
| 7524 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | |
| 7528 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 7529 | int cw_min, int cw_max, int burst_time) |
| 7530 | { |
| 7531 | struct i802_bss *bss = priv; |
| 7532 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7533 | struct nl_msg *msg; |
| 7534 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7535 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7537 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7538 | if (!msg) |
| 7539 | return -1; |
| 7540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7541 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 7542 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7543 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7544 | |
| 7545 | /* We are only sending parameters for a single TXQ at a time */ |
| 7546 | params = nla_nest_start(msg, 1); |
| 7547 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7548 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7549 | |
| 7550 | switch (queue) { |
| 7551 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7552 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 7553 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7554 | break; |
| 7555 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7556 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 7557 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7558 | break; |
| 7559 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7560 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 7561 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7562 | break; |
| 7563 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7564 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 7565 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7566 | break; |
| 7567 | } |
| 7568 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 7569 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7570 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 7571 | (burst_time * 100 + 16) / 32) || |
| 7572 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 7573 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 7574 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 7575 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7576 | |
| 7577 | nla_nest_end(msg, params); |
| 7578 | |
| 7579 | nla_nest_end(msg, txq); |
| 7580 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7581 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7582 | wpa_printf(MSG_DEBUG, |
| 7583 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 7584 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 7585 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7586 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7587 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7588 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7589 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7590 | return -1; |
| 7591 | } |
| 7592 | |
| 7593 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7594 | 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] | 7595 | const char *ifname, int vlan_id) |
| 7596 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7597 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7598 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7599 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7600 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7601 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 7602 | ", ifname=%s[%d], vlan_id=%d)", |
| 7603 | bss->ifname, if_nametoindex(bss->ifname), |
| 7604 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7605 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 7606 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7607 | (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7608 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7609 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 7610 | nlmsg_free(msg); |
| 7611 | return -ENOBUFS; |
| 7612 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7613 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7614 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7615 | if (ret < 0) { |
| 7616 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 7617 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 7618 | MAC2STR(addr), ifname, vlan_id, ret, |
| 7619 | strerror(-ret)); |
| 7620 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7621 | return ret; |
| 7622 | } |
| 7623 | |
| 7624 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7625 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 7626 | { |
| 7627 | struct hostap_sta_driver_data data; |
| 7628 | int ret; |
| 7629 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 7630 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7631 | data.inactive_msec = (unsigned long) -1; |
| 7632 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7633 | if (ret == -ENOENT) |
| 7634 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7635 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 7636 | return -1; |
| 7637 | return data.inactive_msec / 1000; |
| 7638 | } |
| 7639 | |
| 7640 | |
| 7641 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 7642 | { |
| 7643 | #if 0 |
| 7644 | /* TODO */ |
| 7645 | #endif |
| 7646 | return 0; |
| 7647 | } |
| 7648 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7649 | |
| 7650 | 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] | 7651 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7652 | { |
| 7653 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7654 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7655 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 7656 | u8 channel; |
| 7657 | |
| 7658 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 7659 | HOSTAPD_MODE_IEEE80211AD) { |
| 7660 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 7661 | * disassociate the STA instead. */ |
| 7662 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 7663 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7664 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7665 | if (is_mesh_interface(drv->nlmode)) |
| 7666 | return -1; |
| 7667 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7668 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7669 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7670 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7671 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7672 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7673 | WLAN_FC_STYPE_DEAUTH); |
| 7674 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7675 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7676 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7677 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 7678 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7679 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7680 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7681 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | |
| 7685 | 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] | 7686 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7687 | { |
| 7688 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7690 | struct ieee80211_mgmt mgmt; |
| 7691 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7692 | if (is_mesh_interface(drv->nlmode)) |
| 7693 | return -1; |
| 7694 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7695 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7696 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7697 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7698 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7699 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7700 | WLAN_FC_STYPE_DISASSOC); |
| 7701 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7702 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7703 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7704 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 7705 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7706 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7707 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7708 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7709 | } |
| 7710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7711 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7712 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 7713 | { |
| 7714 | char buf[200], *pos, *end; |
| 7715 | int i, res; |
| 7716 | |
| 7717 | pos = buf; |
| 7718 | end = pos + sizeof(buf); |
| 7719 | |
| 7720 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7721 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7722 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7723 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7724 | drv->if_indices[i].ifindex, |
| 7725 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7726 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7727 | break; |
| 7728 | pos += res; |
| 7729 | } |
| 7730 | *pos = '\0'; |
| 7731 | |
| 7732 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 7733 | drv->num_if_indices, buf); |
| 7734 | } |
| 7735 | |
| 7736 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7737 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7738 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7739 | { |
| 7740 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7741 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7742 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7743 | wpa_printf(MSG_DEBUG, |
| 7744 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 7745 | ifidx, ifidx_reason); |
| 7746 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7747 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 7748 | ifidx); |
| 7749 | return; |
| 7750 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7751 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7752 | if (drv->if_indices[i].ifindex == 0) { |
| 7753 | drv->if_indices[i].ifindex = ifidx; |
| 7754 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7755 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7756 | return; |
| 7757 | } |
| 7758 | } |
| 7759 | |
| 7760 | if (drv->if_indices != drv->default_if_indices) |
| 7761 | old = drv->if_indices; |
| 7762 | else |
| 7763 | old = NULL; |
| 7764 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7765 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7766 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7767 | if (!drv->if_indices) { |
| 7768 | if (!old) |
| 7769 | drv->if_indices = drv->default_if_indices; |
| 7770 | else |
| 7771 | drv->if_indices = old; |
| 7772 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 7773 | "interfaces"); |
| 7774 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 7775 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7776 | } |
| 7777 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7778 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 7779 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7780 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 7781 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7782 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7783 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7784 | } |
| 7785 | |
| 7786 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7787 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7788 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7789 | { |
| 7790 | int i; |
| 7791 | |
| 7792 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7793 | if ((drv->if_indices[i].ifindex == ifidx || |
| 7794 | ifidx == IFIDX_ANY) && |
| 7795 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7796 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7797 | drv->if_indices[i].ifindex = 0; |
| 7798 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7799 | break; |
| 7800 | } |
| 7801 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7802 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7803 | } |
| 7804 | |
| 7805 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7806 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7807 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7808 | { |
| 7809 | int i; |
| 7810 | |
| 7811 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7812 | if (drv->if_indices[i].ifindex == ifidx && |
| 7813 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7814 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7815 | return 1; |
| 7816 | |
| 7817 | return 0; |
| 7818 | } |
| 7819 | |
| 7820 | |
| 7821 | 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] | 7822 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7823 | { |
| 7824 | struct i802_bss *bss = priv; |
| 7825 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7826 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7827 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7828 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7829 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7830 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 7831 | if (ret >= (int) sizeof(name)) |
| 7832 | wpa_printf(MSG_WARNING, |
| 7833 | "nl80211: WDS interface name was truncated"); |
| 7834 | else if (ret < 0) |
| 7835 | return ret; |
| 7836 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7837 | if (ifname_wds) |
| 7838 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 7839 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7840 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 7841 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 7842 | if (val) { |
| 7843 | if (!if_nametoindex(name)) { |
| 7844 | if (nl80211_create_iface(drv, name, |
| 7845 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7846 | bss->addr, 1, NULL, NULL, 0) < |
| 7847 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7848 | return -1; |
| 7849 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7850 | linux_br_add_if(drv->global->ioctl_sock, |
| 7851 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7852 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7853 | |
| 7854 | os_memset(&event, 0, sizeof(event)); |
| 7855 | event.wds_sta_interface.sta_addr = addr; |
| 7856 | event.wds_sta_interface.ifname = name; |
| 7857 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7858 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7859 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 7860 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7861 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7862 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 7863 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 7864 | "interface %s up", name); |
| 7865 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7866 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 7867 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7868 | if (bridge_ifname && |
| 7869 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 7870 | name) < 0) |
| 7871 | wpa_printf(MSG_INFO, |
| 7872 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7873 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7874 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7875 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7876 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7877 | os_memset(&event, 0, sizeof(event)); |
| 7878 | event.wds_sta_interface.sta_addr = addr; |
| 7879 | event.wds_sta_interface.ifname = name; |
| 7880 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7881 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7882 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7883 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7884 | } |
| 7885 | } |
| 7886 | |
| 7887 | |
| 7888 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 7889 | { |
| 7890 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7891 | struct sockaddr_ll lladdr; |
| 7892 | unsigned char buf[3000]; |
| 7893 | int len; |
| 7894 | socklen_t fromlen = sizeof(lladdr); |
| 7895 | |
| 7896 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 7897 | (struct sockaddr *)&lladdr, &fromlen); |
| 7898 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7899 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 7900 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7901 | return; |
| 7902 | } |
| 7903 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7904 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7905 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 7906 | } |
| 7907 | |
| 7908 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7909 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 7910 | struct i802_bss *bss, |
| 7911 | const char *brname, const char *ifname) |
| 7912 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7913 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7914 | char in_br[IFNAMSIZ]; |
| 7915 | |
| 7916 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7917 | br_ifindex = if_nametoindex(brname); |
| 7918 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7919 | /* |
| 7920 | * Bridge was configured, but the bridge device does |
| 7921 | * not exist. Try to add it now. |
| 7922 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7923 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7924 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 7925 | "bridge interface %s: %s", |
| 7926 | brname, strerror(errno)); |
| 7927 | return -1; |
| 7928 | } |
| 7929 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7930 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7931 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7932 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7933 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7934 | |
| 7935 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7936 | if (os_strcmp(in_br, brname) == 0) { |
| 7937 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7938 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7939 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7940 | |
| 7941 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 7942 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7943 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 7944 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7945 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 7946 | "remove interface %s from bridge " |
| 7947 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7948 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7949 | return -1; |
| 7950 | } |
| 7951 | } |
| 7952 | |
| 7953 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 7954 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7955 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7956 | wpa_printf(MSG_WARNING, |
| 7957 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7958 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7959 | /* Try to continue without the interface being in a bridge. This |
| 7960 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 7961 | * an external component will need to handle bridge |
| 7962 | * configuration. */ |
| 7963 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7964 | } |
| 7965 | bss->added_if_into_bridge = 1; |
| 7966 | |
| 7967 | return 0; |
| 7968 | } |
| 7969 | |
| 7970 | |
| 7971 | static void *i802_init(struct hostapd_data *hapd, |
| 7972 | struct wpa_init_params *params) |
| 7973 | { |
| 7974 | struct wpa_driver_nl80211_data *drv; |
| 7975 | struct i802_bss *bss; |
| 7976 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7977 | char master_ifname[IFNAMSIZ]; |
| 7978 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7979 | int br_added = 0; |
| 7980 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7981 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 7982 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7983 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7984 | if (bss == NULL) |
| 7985 | return NULL; |
| 7986 | |
| 7987 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7988 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7989 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7990 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7991 | params->ifname, master_ifname); |
| 7992 | br_ifindex = if_nametoindex(master_ifname); |
| 7993 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7994 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 7995 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 7996 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 7997 | params->ifname, master_ifname); |
| 7998 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7999 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 8000 | |
| 8001 | /* check if master itself is under bridge */ |
| 8002 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 8003 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 8004 | master_ifname); |
| 8005 | br_ifindex = if_nametoindex(master_ifname); |
| 8006 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 8007 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8008 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8009 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8010 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8011 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8012 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8013 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8014 | for (i = 0; i < params->num_bridge; i++) { |
| 8015 | if (params->bridge[i]) { |
| 8016 | ifindex = if_nametoindex(params->bridge[i]); |
| 8017 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8018 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8019 | if (ifindex == br_ifindex) |
| 8020 | br_added = 1; |
| 8021 | } |
| 8022 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8023 | |
| 8024 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8025 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8026 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8027 | if (params->num_bridge && params->bridge[0]) { |
| 8028 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 8029 | params->ifname) < 0) |
| 8030 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8031 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8032 | br_added = 1; |
| 8033 | } |
| 8034 | |
| 8035 | if (!br_added && br_ifindex && |
| 8036 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8037 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8038 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8039 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8040 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8041 | int err; |
| 8042 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8043 | drv->rtnl_sk = nl_socket_alloc(); |
| 8044 | if (drv->rtnl_sk == NULL) { |
| 8045 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 8046 | goto failed; |
| 8047 | } |
| 8048 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8049 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 8050 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8051 | 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] | 8052 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8053 | goto failed; |
| 8054 | } |
| 8055 | } |
| 8056 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8057 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8058 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |
| 8059 | wpa_printf(MSG_DEBUG, |
| 8060 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); |
| 8061 | goto skip_eapol_sock; |
| 8062 | } |
| 8063 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8064 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 8065 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8066 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 8067 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8068 | goto failed; |
| 8069 | } |
| 8070 | |
| 8071 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 8072 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8073 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8074 | goto failed; |
| 8075 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8076 | skip_eapol_sock: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8077 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8078 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8079 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8080 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8081 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8082 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8083 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 8084 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8085 | return bss; |
| 8086 | |
| 8087 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8088 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8089 | return NULL; |
| 8090 | } |
| 8091 | |
| 8092 | |
| 8093 | static void i802_deinit(void *priv) |
| 8094 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8095 | struct i802_bss *bss = priv; |
| 8096 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8097 | } |
| 8098 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8099 | |
| 8100 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 8101 | enum wpa_driver_if_type type) |
| 8102 | { |
| 8103 | switch (type) { |
| 8104 | case WPA_IF_STATION: |
| 8105 | return NL80211_IFTYPE_STATION; |
| 8106 | case WPA_IF_P2P_CLIENT: |
| 8107 | case WPA_IF_P2P_GROUP: |
| 8108 | return NL80211_IFTYPE_P2P_CLIENT; |
| 8109 | case WPA_IF_AP_VLAN: |
| 8110 | return NL80211_IFTYPE_AP_VLAN; |
| 8111 | case WPA_IF_AP_BSS: |
| 8112 | return NL80211_IFTYPE_AP; |
| 8113 | case WPA_IF_P2P_GO: |
| 8114 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8115 | case WPA_IF_P2P_DEVICE: |
| 8116 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8117 | case WPA_IF_MESH: |
| 8118 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8119 | default: |
| 8120 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8122 | } |
| 8123 | |
| 8124 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8125 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 8126 | { |
| 8127 | struct wpa_driver_nl80211_data *drv; |
| 8128 | dl_list_for_each(drv, &global->interfaces, |
| 8129 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8130 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8131 | return 1; |
| 8132 | } |
| 8133 | return 0; |
| 8134 | } |
| 8135 | |
| 8136 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8137 | 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] | 8138 | { |
| 8139 | unsigned int idx; |
| 8140 | |
| 8141 | if (!drv->global) |
| 8142 | return -1; |
| 8143 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8144 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8145 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8146 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8147 | new_addr[0] ^= idx << 2; |
| 8148 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 8149 | break; |
| 8150 | } |
| 8151 | if (idx == 64) |
| 8152 | return -1; |
| 8153 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8154 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8155 | MACSTR, MAC2STR(new_addr)); |
| 8156 | |
| 8157 | return 0; |
| 8158 | } |
| 8159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8160 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8161 | struct wdev_info { |
| 8162 | u64 wdev_id; |
| 8163 | int wdev_id_set; |
| 8164 | u8 macaddr[ETH_ALEN]; |
| 8165 | }; |
| 8166 | |
| 8167 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 8168 | { |
| 8169 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8170 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8171 | struct wdev_info *wi = arg; |
| 8172 | |
| 8173 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8174 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8175 | if (tb[NL80211_ATTR_WDEV]) { |
| 8176 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 8177 | wi->wdev_id_set = 1; |
| 8178 | } |
| 8179 | |
| 8180 | if (tb[NL80211_ATTR_MAC]) |
| 8181 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 8182 | ETH_ALEN); |
| 8183 | |
| 8184 | return NL_SKIP; |
| 8185 | } |
| 8186 | |
| 8187 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8188 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 8189 | const char *ifname, const u8 *addr, |
| 8190 | void *bss_ctx, void **drv_priv, |
| 8191 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8192 | const char *bridge, int use_existing, |
| 8193 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8194 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8195 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8196 | struct i802_bss *bss = priv; |
| 8197 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8198 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8199 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8200 | |
| 8201 | if (addr) |
| 8202 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8203 | nlmode = wpa_driver_nl80211_if_type(type); |
| 8204 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 8205 | struct wdev_info p2pdev_info; |
| 8206 | |
| 8207 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 8208 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 8209 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8210 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8211 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 8212 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 8213 | ifname); |
| 8214 | return -1; |
| 8215 | } |
| 8216 | |
| 8217 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 8218 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8219 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8220 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 8221 | os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 8222 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8223 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 8224 | ifname, |
| 8225 | (long long unsigned int) p2pdev_info.wdev_id); |
| 8226 | } else { |
| 8227 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8228 | 0, NULL, NULL, use_existing); |
| 8229 | if (use_existing && ifidx == -ENFILE) { |
| 8230 | added = 0; |
| 8231 | ifidx = if_nametoindex(ifname); |
| 8232 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8233 | return -1; |
| 8234 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8235 | } |
| 8236 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8237 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8238 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8239 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 8240 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8241 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8242 | if (added) |
| 8243 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8244 | return -1; |
| 8245 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8246 | } |
| 8247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8248 | if (!addr && |
| 8249 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8250 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 8251 | type == WPA_IF_STATION)) { |
| 8252 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8253 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8254 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8255 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8256 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8257 | if (added) |
| 8258 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8259 | return -1; |
| 8260 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8261 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8262 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8263 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8264 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8265 | if (added) |
| 8266 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8267 | return -1; |
| 8268 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8269 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8270 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8271 | if (added) |
| 8272 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8273 | return -1; |
| 8274 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8275 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8276 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8277 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8278 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8279 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8280 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 8281 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8282 | if (added) |
| 8283 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8284 | return -1; |
| 8285 | } |
| 8286 | |
| 8287 | if (bridge && |
| 8288 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 8289 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 8290 | "interface %s to a bridge %s", |
| 8291 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8292 | if (added) |
| 8293 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8294 | os_free(new_bss); |
| 8295 | return -1; |
| 8296 | } |
| 8297 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8298 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 8299 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8300 | if (added) |
| 8301 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8302 | os_free(new_bss); |
| 8303 | return -1; |
| 8304 | } |
| 8305 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8306 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8307 | new_bss->ifindex = ifidx; |
| 8308 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8309 | new_bss->next = drv->first_bss->next; |
| 8310 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8311 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8312 | new_bss->added_if = added; |
| 8313 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8314 | if (drv_priv) |
| 8315 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8316 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8317 | |
| 8318 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 8319 | if (nl80211_setup_ap(new_bss)) |
| 8320 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8321 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8322 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8323 | if (drv->global) |
| 8324 | drv->global->if_add_ifindex = ifidx; |
| 8325 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8326 | /* |
| 8327 | * Some virtual interfaces need to process EAPOL packets and events on |
| 8328 | * the parent interface. This is used mainly with hostapd. |
| 8329 | */ |
| 8330 | if (ifidx > 0 && |
| 8331 | (drv->hostapd || |
| 8332 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 8333 | nlmode == NL80211_IFTYPE_WDS || |
| 8334 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8335 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8336 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8337 | return 0; |
| 8338 | } |
| 8339 | |
| 8340 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8341 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8342 | enum wpa_driver_if_type type, |
| 8343 | const char *ifname) |
| 8344 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8345 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8346 | int ifindex = if_nametoindex(ifname); |
| 8347 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8348 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 8349 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8350 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8351 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8352 | else if (ifindex > 0 && !bss->added_if) { |
| 8353 | struct wpa_driver_nl80211_data *drv2; |
| 8354 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8355 | struct wpa_driver_nl80211_data, list) { |
| 8356 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 8357 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 8358 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8359 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8360 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8361 | if (type != WPA_IF_AP_BSS) |
| 8362 | return 0; |
| 8363 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8364 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8365 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 8366 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8367 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8368 | "interface %s from bridge %s: %s", |
| 8369 | bss->ifname, bss->brname, strerror(errno)); |
| 8370 | } |
| 8371 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8372 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8373 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8374 | "bridge %s: %s", |
| 8375 | bss->brname, strerror(errno)); |
| 8376 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8377 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8378 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8379 | struct i802_bss *tbss; |
| 8380 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8381 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 8382 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8383 | if (tbss->next == bss) { |
| 8384 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8385 | /* Unsubscribe management frames */ |
| 8386 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8387 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8388 | if (!bss->added_if) |
| 8389 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8390 | os_free(bss); |
| 8391 | bss = NULL; |
| 8392 | break; |
| 8393 | } |
| 8394 | } |
| 8395 | if (bss) |
| 8396 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 8397 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8398 | } else { |
| 8399 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 8400 | nl80211_teardown_ap(bss); |
| 8401 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8402 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8403 | nl80211_destroy_bss(bss); |
| 8404 | if (!bss->added_if) |
| 8405 | i802_set_iface_flags(bss, 0); |
| 8406 | if (drv->first_bss->next) { |
| 8407 | drv->first_bss = drv->first_bss->next; |
| 8408 | drv->ctx = drv->first_bss->ctx; |
| 8409 | os_free(bss); |
| 8410 | } else { |
| 8411 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 8412 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8413 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8414 | |
| 8415 | return 0; |
| 8416 | } |
| 8417 | |
| 8418 | |
| 8419 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 8420 | { |
| 8421 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8422 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8423 | u64 *cookie = arg; |
| 8424 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8425 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8426 | if (tb[NL80211_ATTR_COOKIE]) |
| 8427 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 8428 | return NL_SKIP; |
| 8429 | } |
| 8430 | |
| 8431 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8432 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8433 | unsigned int freq, unsigned int wait, |
| 8434 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8435 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8436 | int offchanok, const u16 *csa_offs, |
| 8437 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8438 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8439 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8440 | struct nl_msg *msg; |
| 8441 | u64 cookie; |
| 8442 | int ret = -1; |
| 8443 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8444 | 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] | 8445 | "no_ack=%d offchanok=%d", |
| 8446 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8447 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8449 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 8450 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8451 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 8452 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8453 | drv->test_use_roc_tx) && |
| 8454 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 8455 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 8456 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8457 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 8458 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8459 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 8460 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8461 | |
| 8462 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8463 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8464 | msg = NULL; |
| 8465 | if (ret) { |
| 8466 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8467 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 8468 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8469 | } else { |
| 8470 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 8471 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 8472 | (long long unsigned int) cookie); |
| 8473 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8474 | if (save_cookie) |
| 8475 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8476 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8477 | if (!wait) { |
| 8478 | /* There is no need to store this cookie since there |
| 8479 | * is no wait that could be canceled later. */ |
| 8480 | goto fail; |
| 8481 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8482 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8483 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8484 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8485 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8486 | drv->send_frame_cookies[0]); |
| 8487 | os_memmove(&drv->send_frame_cookies[0], |
| 8488 | &drv->send_frame_cookies[1], |
| 8489 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8490 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8491 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8492 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8493 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 8494 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8495 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8496 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8497 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8498 | nlmsg_free(msg); |
| 8499 | return ret; |
| 8500 | } |
| 8501 | |
| 8502 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8503 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 8504 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8505 | unsigned int wait_time, |
| 8506 | const u8 *dst, const u8 *src, |
| 8507 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8508 | const u8 *data, size_t data_len, |
| 8509 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8510 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8511 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8512 | int ret = -1; |
| 8513 | u8 *buf; |
| 8514 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8515 | int offchanok = 1; |
| 8516 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8517 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq && |
| 8518 | bss->beacon_set) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8519 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8520 | |
| 8521 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8522 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
| 8523 | drv->ifindex, freq, wait_time, no_cck, offchanok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8524 | |
| 8525 | buf = os_zalloc(24 + data_len); |
| 8526 | if (buf == NULL) |
| 8527 | return ret; |
| 8528 | os_memcpy(buf + 24, data, data_len); |
| 8529 | hdr = (struct ieee80211_hdr *) buf; |
| 8530 | hdr->frame_control = |
| 8531 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 8532 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 8533 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 8534 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 8535 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8536 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 8537 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 8538 | MAC2STR(src)); |
| 8539 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 8540 | } else { |
| 8541 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 8542 | } |
| 8543 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8544 | #ifdef CONFIG_MESH |
| 8545 | if (is_mesh_interface(drv->nlmode)) { |
| 8546 | struct hostapd_hw_modes *modes; |
| 8547 | u16 num_modes, flags; |
| 8548 | u8 dfs_domain; |
| 8549 | int i; |
| 8550 | |
| 8551 | modes = nl80211_get_hw_feature_data(bss, &num_modes, |
| 8552 | &flags, &dfs_domain); |
| 8553 | if (dfs_domain != HOSTAPD_DFS_REGION_ETSI && |
| 8554 | ieee80211_is_dfs(bss->freq, modes, num_modes)) |
| 8555 | offchanok = 0; |
| 8556 | if (modes) { |
| 8557 | for (i = 0; i < num_modes; i++) { |
| 8558 | os_free(modes[i].channels); |
| 8559 | os_free(modes[i].rates); |
| 8560 | } |
| 8561 | os_free(modes); |
| 8562 | } |
| 8563 | } |
| 8564 | #endif /* CONFIG_MESH */ |
| 8565 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8566 | if (is_ap_interface(drv->nlmode) && |
| 8567 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8568 | (int) freq == bss->freq || drv->device_ap_sme || |
| 8569 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8570 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8571 | 0, freq, no_cck, offchanok, |
| 8572 | wait_time, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8573 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8574 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8575 | 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8576 | 1, no_cck, 0, offchanok, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8577 | |
| 8578 | os_free(buf); |
| 8579 | return ret; |
| 8580 | } |
| 8581 | |
| 8582 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8583 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8584 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8585 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8586 | struct nl_msg *msg; |
| 8587 | int ret; |
| 8588 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8589 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8590 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8591 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8592 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8593 | nlmsg_free(msg); |
| 8594 | return; |
| 8595 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8596 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8597 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8598 | if (ret) |
| 8599 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 8600 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8601 | } |
| 8602 | |
| 8603 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8604 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 8605 | { |
| 8606 | struct i802_bss *bss = priv; |
| 8607 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8608 | unsigned int i; |
| 8609 | u64 cookie; |
| 8610 | |
| 8611 | /* Cancel the last pending TX cookie */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8612 | if (drv->send_frame_cookie != (u64) -1) |
| 8613 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8614 | |
| 8615 | /* |
| 8616 | * Cancel the other pending TX cookies, if any. This is needed since |
| 8617 | * the driver may keep a list of all pending offchannel TX operations |
| 8618 | * and free up the radio only once they have expired or cancelled. |
| 8619 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8620 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 8621 | cookie = drv->send_frame_cookies[i - 1]; |
| 8622 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8623 | nl80211_frame_wait_cancel(bss, cookie); |
| 8624 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8625 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8626 | } |
| 8627 | |
| 8628 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8629 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 8630 | unsigned int duration) |
| 8631 | { |
| 8632 | struct i802_bss *bss = priv; |
| 8633 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8634 | struct nl_msg *msg; |
| 8635 | int ret; |
| 8636 | u64 cookie; |
| 8637 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8638 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 8639 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8640 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 8641 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8642 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8643 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8644 | |
| 8645 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8646 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8647 | if (ret == 0) { |
| 8648 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 8649 | "0x%llx for freq=%u MHz duration=%u", |
| 8650 | (long long unsigned int) cookie, freq, duration); |
| 8651 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8652 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8653 | return 0; |
| 8654 | } |
| 8655 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 8656 | "(freq=%d duration=%u): %d (%s)", |
| 8657 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8658 | return -1; |
| 8659 | } |
| 8660 | |
| 8661 | |
| 8662 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 8663 | { |
| 8664 | struct i802_bss *bss = priv; |
| 8665 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8666 | struct nl_msg *msg; |
| 8667 | int ret; |
| 8668 | |
| 8669 | if (!drv->pending_remain_on_chan) { |
| 8670 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 8671 | "to cancel"); |
| 8672 | return -1; |
| 8673 | } |
| 8674 | |
| 8675 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 8676 | "0x%llx", |
| 8677 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 8678 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8679 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 8680 | if (!msg || |
| 8681 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 8682 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8683 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8684 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8685 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8686 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8687 | if (ret == 0) |
| 8688 | return 0; |
| 8689 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 8690 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8691 | return -1; |
| 8692 | } |
| 8693 | |
| 8694 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8695 | 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] | 8696 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8697 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8698 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8699 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8700 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 8701 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 8702 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8703 | /* |
| 8704 | * Do not disable Probe Request reporting that was |
| 8705 | * enabled in nl80211_setup_ap(). |
| 8706 | */ |
| 8707 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 8708 | "Probe Request reporting nl_preq=%p while " |
| 8709 | "in AP mode", bss->nl_preq); |
| 8710 | } else if (bss->nl_preq) { |
| 8711 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 8712 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8713 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8714 | } |
| 8715 | return 0; |
| 8716 | } |
| 8717 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8718 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8719 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8720 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8721 | return 0; |
| 8722 | } |
| 8723 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8724 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 8725 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8726 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8727 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 8728 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8729 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8730 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8731 | (WLAN_FC_TYPE_MGMT << 2) | |
| 8732 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8733 | NULL, 0, false) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8734 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 8735 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8736 | nl80211_register_eloop_read(&bss->nl_preq, |
| 8737 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8738 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8739 | |
| 8740 | return 0; |
| 8741 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8742 | out_err: |
| 8743 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8744 | return -1; |
| 8745 | } |
| 8746 | |
| 8747 | |
| 8748 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 8749 | int ifindex, int disabled) |
| 8750 | { |
| 8751 | struct nl_msg *msg; |
| 8752 | struct nlattr *bands, *band; |
| 8753 | int ret; |
| 8754 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8755 | wpa_printf(MSG_DEBUG, |
| 8756 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 8757 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 8758 | "no NL80211_TXRATE_LEGACY constraint"); |
| 8759 | |
| 8760 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 8761 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8762 | if (!msg) |
| 8763 | return -1; |
| 8764 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8765 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 8766 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8767 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8768 | |
| 8769 | /* |
| 8770 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 8771 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 8772 | * rates. All 5 GHz rates are left enabled. |
| 8773 | */ |
| 8774 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8775 | if (!band || |
| 8776 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 8777 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 8778 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8779 | nla_nest_end(msg, band); |
| 8780 | |
| 8781 | nla_nest_end(msg, bands); |
| 8782 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8783 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8784 | if (ret) { |
| 8785 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 8786 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8787 | } else |
| 8788 | drv->disabled_11b_rates = disabled; |
| 8789 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8790 | return ret; |
| 8791 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8792 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8793 | nlmsg_free(msg); |
| 8794 | return -1; |
| 8795 | } |
| 8796 | |
| 8797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8798 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 8799 | { |
| 8800 | struct i802_bss *bss = priv; |
| 8801 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8802 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8803 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8804 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8805 | |
| 8806 | /* |
| 8807 | * If the P2P GO interface was dynamically added, then it is |
| 8808 | * possible that the interface change to station is not possible. |
| 8809 | */ |
| 8810 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 8811 | return 0; |
| 8812 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8813 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8814 | } |
| 8815 | |
| 8816 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8817 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 8818 | { |
| 8819 | struct i802_bss *bss = priv; |
| 8820 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8821 | if (!is_ap_interface(drv->nlmode)) |
| 8822 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8823 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8824 | return 0; |
| 8825 | } |
| 8826 | |
| 8827 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8828 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 8829 | { |
| 8830 | struct i802_bss *bss = priv; |
| 8831 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8832 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 8833 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8834 | |
| 8835 | /* |
| 8836 | * If the P2P Client interface was dynamically added, then it is |
| 8837 | * possible that the interface change to station is not possible. |
| 8838 | */ |
| 8839 | if (bss->if_dynamic) |
| 8840 | return 0; |
| 8841 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8842 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 8843 | } |
| 8844 | |
| 8845 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8846 | static void wpa_driver_nl80211_resume(void *priv) |
| 8847 | { |
| 8848 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8849 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8850 | |
| 8851 | if (i802_set_iface_flags(bss, 1)) |
| 8852 | 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] | 8853 | |
| 8854 | if (is_p2p_net_interface(nlmode)) |
| 8855 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8856 | } |
| 8857 | |
| 8858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8859 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 8860 | { |
| 8861 | struct i802_bss *bss = priv; |
| 8862 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8863 | struct nl_msg *msg; |
| 8864 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8865 | |
| 8866 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 8867 | "hysteresis=%d", threshold, hysteresis); |
| 8868 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8869 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 8870 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 8871 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 8872 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 8873 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8874 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8875 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8876 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8877 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8878 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8882 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 8883 | { |
| 8884 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8885 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8886 | struct wpa_signal_info *sig_change = arg; |
| 8887 | |
| 8888 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8889 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8890 | |
| 8891 | sig_change->center_frq1 = -1; |
| 8892 | sig_change->center_frq2 = -1; |
| 8893 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 8894 | |
| 8895 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 8896 | sig_change->chanwidth = convert2width( |
| 8897 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 8898 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 8899 | sig_change->center_frq1 = |
| 8900 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 8901 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 8902 | sig_change->center_frq2 = |
| 8903 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 8904 | } |
| 8905 | |
| 8906 | return NL_SKIP; |
| 8907 | } |
| 8908 | |
| 8909 | |
| 8910 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 8911 | struct wpa_signal_info *sig) |
| 8912 | { |
| 8913 | struct nl_msg *msg; |
| 8914 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8915 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8916 | 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] | 8917 | } |
| 8918 | |
| 8919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8920 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 8921 | { |
| 8922 | struct i802_bss *bss = priv; |
| 8923 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8924 | int res; |
| 8925 | |
| 8926 | os_memset(si, 0, sizeof(*si)); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 8927 | res = nl80211_get_link_signal(drv, drv->bssid, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8928 | if (res) { |
| 8929 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 8930 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 8931 | return res; |
| 8932 | si->current_signal = 0; |
| 8933 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8934 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8935 | res = nl80211_get_channel_width(drv, si); |
| 8936 | if (res != 0) |
| 8937 | return res; |
| 8938 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8939 | return nl80211_get_link_noise(drv, si); |
| 8940 | } |
| 8941 | |
| 8942 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 8943 | static int get_links_noise(struct nl_msg *msg, void *arg) |
| 8944 | { |
| 8945 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8946 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8947 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 8948 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 8949 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 8950 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 8951 | }; |
| 8952 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 8953 | int i; |
| 8954 | |
| 8955 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8956 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8957 | |
| 8958 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 8959 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); |
| 8960 | return NL_SKIP; |
| 8961 | } |
| 8962 | |
| 8963 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 8964 | tb[NL80211_ATTR_SURVEY_INFO], |
| 8965 | survey_policy)) { |
| 8966 | wpa_printf(MSG_DEBUG, |
| 8967 | "nl80211: Failed to parse nested attributes"); |
| 8968 | return NL_SKIP; |
| 8969 | } |
| 8970 | |
| 8971 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 8972 | return NL_SKIP; |
| 8973 | |
| 8974 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 8975 | return NL_SKIP; |
| 8976 | |
| 8977 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 8978 | if (!(mlo_sig->valid_links & BIT(i))) |
| 8979 | continue; |
| 8980 | |
| 8981 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 8982 | mlo_sig->links[i].frequency) |
| 8983 | continue; |
| 8984 | |
| 8985 | mlo_sig->links[i].current_noise = |
| 8986 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 8987 | break; |
| 8988 | } |
| 8989 | |
| 8990 | return NL_SKIP; |
| 8991 | } |
| 8992 | |
| 8993 | |
| 8994 | static int nl80211_get_links_noise(struct wpa_driver_nl80211_data *drv, |
| 8995 | struct wpa_mlo_signal_info *mlo_sig) |
| 8996 | { |
| 8997 | struct nl_msg *msg; |
| 8998 | |
| 8999 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 9000 | return send_and_recv_msgs(drv, msg, get_links_noise, mlo_sig, |
| 9001 | NULL, NULL); |
| 9002 | } |
| 9003 | |
| 9004 | |
| 9005 | static int get_links_channel_width(struct nl_msg *msg, void *arg) |
| 9006 | { |
| 9007 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9008 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9009 | struct wpa_mlo_signal_info *mlo_sig = arg; |
| 9010 | struct nlattr *link; |
| 9011 | int rem_links; |
| 9012 | |
| 9013 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9014 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9015 | |
| 9016 | if (!tb[NL80211_ATTR_MLO_LINKS]) |
| 9017 | return NL_SKIP; |
| 9018 | |
| 9019 | nla_for_each_nested(link, tb[NL80211_ATTR_MLO_LINKS], rem_links) { |
| 9020 | struct nlattr *tb2[NL80211_ATTR_MAX + 1]; |
| 9021 | int link_id; |
| 9022 | |
| 9023 | nla_parse(tb2, NL80211_ATTR_MAX, nla_data(link), nla_len(link), |
| 9024 | NULL); |
| 9025 | |
| 9026 | if (!tb2[NL80211_ATTR_MLO_LINK_ID]) |
| 9027 | continue; |
| 9028 | |
| 9029 | link_id = nla_get_u8(tb2[NL80211_ATTR_MLO_LINK_ID]); |
| 9030 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 9031 | continue; |
| 9032 | |
| 9033 | if (!tb2[NL80211_ATTR_CHANNEL_WIDTH]) |
| 9034 | continue; |
| 9035 | mlo_sig->links[link_id].chanwidth = convert2width( |
| 9036 | nla_get_u32(tb2[NL80211_ATTR_CHANNEL_WIDTH])); |
| 9037 | if (tb2[NL80211_ATTR_CENTER_FREQ1]) |
| 9038 | mlo_sig->links[link_id].center_frq1 = |
| 9039 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ1]); |
| 9040 | if (tb2[NL80211_ATTR_CENTER_FREQ2]) |
| 9041 | mlo_sig->links[link_id].center_frq2 = |
| 9042 | nla_get_u32(tb2[NL80211_ATTR_CENTER_FREQ2]); |
| 9043 | } |
| 9044 | |
| 9045 | return NL_SKIP; |
| 9046 | } |
| 9047 | |
| 9048 | |
| 9049 | static int nl80211_get_links_channel_width(struct wpa_driver_nl80211_data *drv, |
| 9050 | struct wpa_mlo_signal_info *mlo_sig) |
| 9051 | { |
| 9052 | struct nl_msg *msg; |
| 9053 | |
| 9054 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
| 9055 | return send_and_recv_msgs(drv, msg, get_links_channel_width, mlo_sig, |
| 9056 | NULL, NULL); |
| 9057 | } |
| 9058 | |
| 9059 | |
| 9060 | static int nl80211_mlo_signal_poll(void *priv, |
| 9061 | struct wpa_mlo_signal_info *mlo_si) |
| 9062 | { |
| 9063 | struct i802_bss *bss = priv; |
| 9064 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9065 | int res; |
| 9066 | int i; |
| 9067 | |
| 9068 | if (drv->nlmode != NL80211_IFTYPE_STATION || |
| 9069 | !drv->sta_mlo_info.valid_links) |
| 9070 | return -1; |
| 9071 | |
| 9072 | os_memset(mlo_si, 0, sizeof(*mlo_si)); |
| 9073 | mlo_si->valid_links = drv->sta_mlo_info.valid_links; |
| 9074 | |
| 9075 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 9076 | if (!(mlo_si->valid_links & BIT(i))) |
| 9077 | continue; |
| 9078 | |
| 9079 | res = nl80211_get_link_signal(drv, |
| 9080 | drv->sta_mlo_info.links[i].bssid, |
| 9081 | &mlo_si->links[i]); |
| 9082 | if (res != 0) |
| 9083 | return res; |
| 9084 | |
| 9085 | mlo_si->links[i].center_frq1 = -1; |
| 9086 | mlo_si->links[i].center_frq2 = -1; |
| 9087 | mlo_si->links[i].chanwidth = CHAN_WIDTH_UNKNOWN; |
| 9088 | mlo_si->links[i].current_noise = WPA_INVALID_NOISE; |
| 9089 | mlo_si->links[i].frequency = drv->sta_mlo_info.links[i].freq; |
| 9090 | } |
| 9091 | |
| 9092 | res = nl80211_get_links_channel_width(drv, mlo_si); |
| 9093 | if (res != 0) |
| 9094 | return res; |
| 9095 | |
| 9096 | return nl80211_get_links_noise(drv, mlo_si); |
| 9097 | } |
| 9098 | |
| 9099 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9100 | static int nl80211_set_param(void *priv, const char *param) |
| 9101 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9102 | struct i802_bss *bss = priv; |
| 9103 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9104 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9105 | if (param == NULL) |
| 9106 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9107 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9108 | |
| 9109 | #ifdef CONFIG_P2P |
| 9110 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9111 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 9112 | "interface"); |
| 9113 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 9114 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 9115 | } |
| 9116 | #endif /* CONFIG_P2P */ |
| 9117 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9118 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9119 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9120 | |
| 9121 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9122 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9123 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9124 | } |
| 9125 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 9126 | if (os_strstr(param, "force_bss_selection=1")) |
| 9127 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 9128 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9129 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9130 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 9131 | drv->test_use_roc_tx = 1; |
| 9132 | } |
| 9133 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9134 | if (os_strstr(param, "control_port=0")) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9135 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9136 | drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX | |
| 9137 | WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS); |
| 9138 | drv->control_port_ap = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9139 | } |
| 9140 | |
| 9141 | if (os_strstr(param, "control_port_ap=1")) |
| 9142 | drv->control_port_ap = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9143 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9144 | if (os_strstr(param, "control_port_ap=0")) { |
| 9145 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS; |
| 9146 | drv->control_port_ap = 0; |
| 9147 | } |
| 9148 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9149 | if (os_strstr(param, "full_ap_client_state=0")) |
| 9150 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 9151 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9152 | if (os_strstr(param, "no_rrm=1")) { |
| 9153 | drv->no_rrm = 1; |
| 9154 | |
| 9155 | if (!bss->in_deinit && !is_ap_interface(drv->nlmode) && |
| 9156 | !is_mesh_interface(drv->nlmode)) { |
| 9157 | nl80211_mgmt_unsubscribe(bss, "no_rrm=1"); |
| 9158 | if (nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 9159 | wpa_printf(MSG_DEBUG, |
| 9160 | "nl80211: Failed to re-register Action frame processing - ignore for now"); |
| 9161 | } |
| 9162 | } |
| 9163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9164 | return 0; |
| 9165 | } |
| 9166 | |
| 9167 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9168 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9169 | { |
| 9170 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9171 | struct netlink_config *cfg; |
| 9172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9173 | global = os_zalloc(sizeof(*global)); |
| 9174 | if (global == NULL) |
| 9175 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9176 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9177 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9178 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9179 | global->if_add_ifindex = -1; |
| 9180 | |
| 9181 | cfg = os_zalloc(sizeof(*cfg)); |
| 9182 | if (cfg == NULL) |
| 9183 | goto err; |
| 9184 | |
| 9185 | cfg->ctx = global; |
| 9186 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 9187 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 9188 | global->netlink = netlink_init(cfg); |
| 9189 | if (global->netlink == NULL) { |
| 9190 | os_free(cfg); |
| 9191 | goto err; |
| 9192 | } |
| 9193 | |
| 9194 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 9195 | goto err; |
| 9196 | |
| 9197 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 9198 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9199 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 9200 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9201 | goto err; |
| 9202 | } |
| 9203 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9204 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9205 | |
| 9206 | err: |
| 9207 | nl80211_global_deinit(global); |
| 9208 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9209 | } |
| 9210 | |
| 9211 | |
| 9212 | static void nl80211_global_deinit(void *priv) |
| 9213 | { |
| 9214 | struct nl80211_global *global = priv; |
| 9215 | if (global == NULL) |
| 9216 | return; |
| 9217 | if (!dl_list_empty(&global->interfaces)) { |
| 9218 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 9219 | "nl80211_global_deinit", |
| 9220 | dl_list_len(&global->interfaces)); |
| 9221 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9222 | |
| 9223 | if (global->netlink) |
| 9224 | netlink_deinit(global->netlink); |
| 9225 | |
| 9226 | nl_destroy_handles(&global->nl); |
| 9227 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9228 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9229 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9230 | |
| 9231 | nl_cb_put(global->nl_cb); |
| 9232 | |
| 9233 | if (global->ioctl_sock >= 0) |
| 9234 | close(global->ioctl_sock); |
| 9235 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9236 | os_free(global); |
| 9237 | } |
| 9238 | |
| 9239 | |
| 9240 | static const char * nl80211_get_radio_name(void *priv) |
| 9241 | { |
| 9242 | struct i802_bss *bss = priv; |
| 9243 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9244 | return drv->phyname; |
| 9245 | } |
| 9246 | |
| 9247 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9248 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 9249 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9250 | { |
| 9251 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9252 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9253 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9254 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9255 | (params->pmkid && |
| 9256 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 9257 | (params->bssid && |
| 9258 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 9259 | (params->ssid_len && |
| 9260 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 9261 | (params->fils_cache_id && |
| 9262 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 9263 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9264 | (params->pmk_lifetime && |
| 9265 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 9266 | params->pmk_lifetime)) || |
| 9267 | (params->pmk_reauth_threshold && |
| 9268 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 9269 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 9270 | (cmd != NL80211_CMD_DEL_PMKSA && |
| 9271 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9272 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9273 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9274 | nlmsg_free(msg); |
| 9275 | return -ENOBUFS; |
| 9276 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9277 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9278 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9279 | } |
| 9280 | |
| 9281 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9282 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9283 | { |
| 9284 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9285 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9286 | |
| 9287 | if (params->bssid) |
| 9288 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 9289 | MAC2STR(params->bssid)); |
| 9290 | else if (params->fils_cache_id && params->ssid_len) { |
| 9291 | wpa_printf(MSG_DEBUG, |
| 9292 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 9293 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 9294 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 9295 | } |
| 9296 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9297 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 9298 | if (ret < 0) { |
| 9299 | wpa_printf(MSG_DEBUG, |
| 9300 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 9301 | ret, strerror(-ret)); |
| 9302 | } |
| 9303 | |
| 9304 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9305 | } |
| 9306 | |
| 9307 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9308 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9309 | { |
| 9310 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9311 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9312 | |
| 9313 | if (params->bssid) |
| 9314 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 9315 | MAC2STR(params->bssid)); |
| 9316 | else if (params->fils_cache_id && params->ssid_len) { |
| 9317 | wpa_printf(MSG_DEBUG, |
| 9318 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 9319 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 9320 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 9321 | } |
| 9322 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9323 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 9324 | if (ret < 0) { |
| 9325 | wpa_printf(MSG_DEBUG, |
| 9326 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 9327 | ret, strerror(-ret)); |
| 9328 | } |
| 9329 | |
| 9330 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9331 | } |
| 9332 | |
| 9333 | |
| 9334 | static int nl80211_flush_pmkid(void *priv) |
| 9335 | { |
| 9336 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9337 | struct nl_msg *msg; |
| 9338 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9339 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9340 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 9341 | if (!msg) |
| 9342 | return -ENOBUFS; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9343 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9344 | } |
| 9345 | |
| 9346 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9347 | static void clean_survey_results(struct survey_results *survey_results) |
| 9348 | { |
| 9349 | struct freq_survey *survey, *tmp; |
| 9350 | |
| 9351 | if (dl_list_empty(&survey_results->survey_list)) |
| 9352 | return; |
| 9353 | |
| 9354 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 9355 | struct freq_survey, list) { |
| 9356 | dl_list_del(&survey->list); |
| 9357 | os_free(survey); |
| 9358 | } |
| 9359 | } |
| 9360 | |
| 9361 | |
| 9362 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 9363 | struct dl_list *survey_list) |
| 9364 | { |
| 9365 | struct freq_survey *survey; |
| 9366 | |
| 9367 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 9368 | if (!survey) |
| 9369 | return; |
| 9370 | |
| 9371 | survey->ifidx = ifidx; |
| 9372 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 9373 | survey->filled = 0; |
| 9374 | |
| 9375 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 9376 | survey->nf = (int8_t) |
| 9377 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 9378 | survey->filled |= SURVEY_HAS_NF; |
| 9379 | } |
| 9380 | |
| 9381 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 9382 | survey->channel_time = |
| 9383 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 9384 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 9385 | } |
| 9386 | |
| 9387 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 9388 | survey->channel_time_busy = |
| 9389 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 9390 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 9391 | } |
| 9392 | |
| 9393 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 9394 | survey->channel_time_rx = |
| 9395 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 9396 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 9397 | } |
| 9398 | |
| 9399 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 9400 | survey->channel_time_tx = |
| 9401 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 9402 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 9403 | } |
| 9404 | |
| 9405 | 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)", |
| 9406 | survey->freq, |
| 9407 | survey->nf, |
| 9408 | (unsigned long int) survey->channel_time, |
| 9409 | (unsigned long int) survey->channel_time_busy, |
| 9410 | (unsigned long int) survey->channel_time_tx, |
| 9411 | (unsigned long int) survey->channel_time_rx, |
| 9412 | survey->filled); |
| 9413 | |
| 9414 | dl_list_add_tail(survey_list, &survey->list); |
| 9415 | } |
| 9416 | |
| 9417 | |
| 9418 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 9419 | unsigned int freq_filter) |
| 9420 | { |
| 9421 | if (!freq_filter) |
| 9422 | return 1; |
| 9423 | |
| 9424 | return freq_filter == surveyed_freq; |
| 9425 | } |
| 9426 | |
| 9427 | |
| 9428 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 9429 | { |
| 9430 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9431 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9432 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 9433 | struct survey_results *survey_results; |
| 9434 | u32 surveyed_freq = 0; |
| 9435 | u32 ifidx; |
| 9436 | |
| 9437 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 9438 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 9439 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 9440 | }; |
| 9441 | |
| 9442 | survey_results = (struct survey_results *) arg; |
| 9443 | |
| 9444 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9445 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9446 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 9447 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 9448 | return NL_SKIP; |
| 9449 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9450 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 9451 | |
| 9452 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 9453 | return NL_SKIP; |
| 9454 | |
| 9455 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 9456 | tb[NL80211_ATTR_SURVEY_INFO], |
| 9457 | survey_policy)) |
| 9458 | return NL_SKIP; |
| 9459 | |
| 9460 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 9461 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 9462 | return NL_SKIP; |
| 9463 | } |
| 9464 | |
| 9465 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 9466 | |
| 9467 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 9468 | survey_results->freq_filter)) |
| 9469 | return NL_SKIP; |
| 9470 | |
| 9471 | if (survey_results->freq_filter && |
| 9472 | survey_results->freq_filter != surveyed_freq) { |
| 9473 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 9474 | surveyed_freq); |
| 9475 | return NL_SKIP; |
| 9476 | } |
| 9477 | |
| 9478 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 9479 | |
| 9480 | return NL_SKIP; |
| 9481 | } |
| 9482 | |
| 9483 | |
| 9484 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 9485 | { |
| 9486 | struct i802_bss *bss = priv; |
| 9487 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9488 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9489 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9490 | union wpa_event_data data; |
| 9491 | struct survey_results *survey_results; |
| 9492 | |
| 9493 | os_memset(&data, 0, sizeof(data)); |
| 9494 | survey_results = &data.survey_results; |
| 9495 | |
| 9496 | dl_list_init(&survey_results->survey_list); |
| 9497 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9498 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9499 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9500 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9501 | |
| 9502 | if (freq) |
| 9503 | data.survey_results.freq_filter = freq; |
| 9504 | |
| 9505 | do { |
| 9506 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 9507 | err = send_and_recv_msgs(drv, msg, survey_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9508 | survey_results, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9509 | } while (err > 0); |
| 9510 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9511 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9512 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9513 | else |
| 9514 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9515 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9516 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9517 | return err; |
| 9518 | } |
| 9519 | |
| 9520 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9521 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 9522 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9523 | const u8 *replay_ctr) |
| 9524 | { |
| 9525 | struct i802_bss *bss = priv; |
| 9526 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9527 | struct nlattr *replay_nested; |
| 9528 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9529 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9530 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9531 | if (!drv->set_rekey_offload) |
| 9532 | return; |
| 9533 | |
| 9534 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9535 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 9536 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9537 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9538 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9539 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 9540 | replay_ctr)) { |
| 9541 | nl80211_nlmsg_clear(msg); |
| 9542 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9543 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9544 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9545 | |
| 9546 | nla_nest_end(msg, replay_nested); |
| 9547 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9548 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9549 | if (ret == -EOPNOTSUPP) { |
| 9550 | wpa_printf(MSG_DEBUG, |
| 9551 | "nl80211: Driver does not support rekey offload"); |
| 9552 | drv->set_rekey_offload = 0; |
| 9553 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9554 | } |
| 9555 | |
| 9556 | |
| 9557 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 9558 | const u8 *addr, int qos) |
| 9559 | { |
| 9560 | /* send data frame to poll STA and check whether |
| 9561 | * this frame is ACKed */ |
| 9562 | struct { |
| 9563 | struct ieee80211_hdr hdr; |
| 9564 | u16 qos_ctl; |
| 9565 | } STRUCT_PACKED nulldata; |
| 9566 | size_t size; |
| 9567 | |
| 9568 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 9569 | |
| 9570 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 9571 | |
| 9572 | if (qos) { |
| 9573 | nulldata.hdr.frame_control = |
| 9574 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9575 | WLAN_FC_STYPE_QOS_NULL); |
| 9576 | size = sizeof(nulldata); |
| 9577 | } else { |
| 9578 | nulldata.hdr.frame_control = |
| 9579 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9580 | WLAN_FC_STYPE_NULLFUNC); |
| 9581 | size = sizeof(struct ieee80211_hdr); |
| 9582 | } |
| 9583 | |
| 9584 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 9585 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 9586 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 9587 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 9588 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9589 | 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] | 9590 | 0, 0, NULL, 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9591 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 9592 | "send poll frame"); |
| 9593 | } |
| 9594 | |
| 9595 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 9596 | int qos) |
| 9597 | { |
| 9598 | struct i802_bss *bss = priv; |
| 9599 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9600 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9601 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9602 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9603 | |
| 9604 | if (!drv->poll_command_supported) { |
| 9605 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 9606 | return; |
| 9607 | } |
| 9608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9609 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 9610 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9611 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9612 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9613 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9614 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9615 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9616 | if (ret < 0) { |
| 9617 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 9618 | MACSTR " failed: ret=%d (%s)", |
| 9619 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9620 | } else { |
| 9621 | wpa_printf(MSG_DEBUG, |
| 9622 | "nl80211: Client probe request addr=" MACSTR |
| 9623 | " cookie=%llu", MAC2STR(addr), |
| 9624 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9625 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9626 | } |
| 9627 | |
| 9628 | |
| 9629 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 9630 | { |
| 9631 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9632 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9633 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9634 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 9635 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 9636 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 9637 | nlmsg_free(msg); |
| 9638 | return -ENOBUFS; |
| 9639 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9640 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9641 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9642 | if (ret < 0) { |
| 9643 | wpa_printf(MSG_DEBUG, |
| 9644 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 9645 | enabled ? "enabled" : "disabled", |
| 9646 | ret, strerror(-ret)); |
| 9647 | } |
| 9648 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9649 | } |
| 9650 | |
| 9651 | |
| 9652 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 9653 | int ctwindow) |
| 9654 | { |
| 9655 | struct i802_bss *bss = priv; |
| 9656 | |
| 9657 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 9658 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 9659 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9660 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9661 | #ifdef ANDROID_P2P |
| 9662 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9663 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9664 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9665 | #endif /* ANDROID_P2P */ |
| 9666 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9667 | |
| 9668 | if (legacy_ps == -1) |
| 9669 | return 0; |
| 9670 | if (legacy_ps != 0 && legacy_ps != 1) |
| 9671 | return -1; /* Not yet supported */ |
| 9672 | |
| 9673 | return nl80211_set_power_save(bss, legacy_ps); |
| 9674 | } |
| 9675 | |
| 9676 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9677 | static int nl80211_start_radar_detection(void *priv, |
| 9678 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9679 | { |
| 9680 | struct i802_bss *bss = priv; |
| 9681 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9682 | struct nl_msg *msg; |
| 9683 | int ret; |
| 9684 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9685 | 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)", |
| 9686 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9687 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 9688 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9689 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 9690 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 9691 | "detection"); |
| 9692 | return -1; |
| 9693 | } |
| 9694 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9695 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 9696 | nl80211_put_freq_params(msg, freq) < 0) { |
| 9697 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9698 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9699 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9700 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9701 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9702 | if (ret == 0) |
| 9703 | return 0; |
| 9704 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 9705 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9706 | return -1; |
| 9707 | } |
| 9708 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9709 | #ifdef CONFIG_TDLS |
| 9710 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9711 | static int nl80211_add_peer_capab(struct nl_msg *msg, |
| 9712 | enum tdls_peer_capability capa) |
| 9713 | { |
| 9714 | u32 peer_capab = 0; |
| 9715 | |
| 9716 | if (!capa) |
| 9717 | return 0; |
| 9718 | |
| 9719 | if (capa & TDLS_PEER_HT) |
| 9720 | peer_capab |= NL80211_TDLS_PEER_HT; |
| 9721 | if (capa & TDLS_PEER_VHT) |
| 9722 | peer_capab |= NL80211_TDLS_PEER_VHT; |
| 9723 | if (capa & TDLS_PEER_WMM) |
| 9724 | peer_capab |= NL80211_TDLS_PEER_WMM; |
| 9725 | if (capa & TDLS_PEER_HE) |
| 9726 | peer_capab |= NL80211_TDLS_PEER_HE; |
| 9727 | |
| 9728 | return nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 9729 | peer_capab); |
| 9730 | } |
| 9731 | |
| 9732 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9733 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 9734 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 9735 | u32 peer_capab, int initiator, const u8 *buf, |
| 9736 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9737 | { |
| 9738 | struct i802_bss *bss = priv; |
| 9739 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9740 | struct nl_msg *msg; |
| 9741 | |
| 9742 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9743 | return -EOPNOTSUPP; |
| 9744 | |
| 9745 | if (!dst) |
| 9746 | return -EINVAL; |
| 9747 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9748 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 9749 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 9750 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 9751 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9752 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code) || |
| 9753 | nl80211_add_peer_capab(msg, peer_capab) || |
| 9754 | (initiator && nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9755 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 9756 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9757 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9758 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9759 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9760 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9761 | nlmsg_free(msg); |
| 9762 | return -ENOBUFS; |
| 9763 | } |
| 9764 | |
| 9765 | |
| 9766 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 9767 | { |
| 9768 | struct i802_bss *bss = priv; |
| 9769 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9770 | struct nl_msg *msg; |
| 9771 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9772 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9773 | |
| 9774 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9775 | return -EOPNOTSUPP; |
| 9776 | |
| 9777 | switch (oper) { |
| 9778 | case TDLS_DISCOVERY_REQ: |
| 9779 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 9780 | break; |
| 9781 | case TDLS_SETUP: |
| 9782 | nl80211_oper = NL80211_TDLS_SETUP; |
| 9783 | break; |
| 9784 | case TDLS_TEARDOWN: |
| 9785 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 9786 | break; |
| 9787 | case TDLS_ENABLE_LINK: |
| 9788 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 9789 | break; |
| 9790 | case TDLS_DISABLE_LINK: |
| 9791 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 9792 | break; |
| 9793 | case TDLS_ENABLE: |
| 9794 | return 0; |
| 9795 | case TDLS_DISABLE: |
| 9796 | return 0; |
| 9797 | default: |
| 9798 | return -EINVAL; |
| 9799 | } |
| 9800 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9801 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 9802 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 9803 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 9804 | nlmsg_free(msg); |
| 9805 | return -ENOBUFS; |
| 9806 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9807 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9808 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9809 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 9810 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 9811 | strerror(-res)); |
| 9812 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9813 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9814 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9815 | |
| 9816 | static int |
| 9817 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 9818 | const struct hostapd_freq_params *params) |
| 9819 | { |
| 9820 | struct i802_bss *bss = priv; |
| 9821 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9822 | struct nl_msg *msg; |
| 9823 | int ret = -ENOBUFS; |
| 9824 | |
| 9825 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9826 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9827 | return -EOPNOTSUPP; |
| 9828 | |
| 9829 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 9830 | " oper_class=%u freq=%u", |
| 9831 | MAC2STR(addr), oper_class, params->freq); |
| 9832 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 9833 | if (!msg || |
| 9834 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9835 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 9836 | (ret = nl80211_put_freq_params(msg, params))) { |
| 9837 | nlmsg_free(msg); |
| 9838 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 9839 | return ret; |
| 9840 | } |
| 9841 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9842 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9843 | } |
| 9844 | |
| 9845 | |
| 9846 | static int |
| 9847 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 9848 | { |
| 9849 | struct i802_bss *bss = priv; |
| 9850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9851 | struct nl_msg *msg; |
| 9852 | |
| 9853 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9854 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9855 | return -EOPNOTSUPP; |
| 9856 | |
| 9857 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 9858 | MAC2STR(addr)); |
| 9859 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 9860 | if (!msg || |
| 9861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9862 | nlmsg_free(msg); |
| 9863 | wpa_printf(MSG_DEBUG, |
| 9864 | "nl80211: Could not build TDLS cancel chan switch"); |
| 9865 | return -ENOBUFS; |
| 9866 | } |
| 9867 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9868 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9869 | } |
| 9870 | |
| 9871 | #endif /* CONFIG TDLS */ |
| 9872 | |
| 9873 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9874 | static int driver_nl80211_set_key(void *priv, |
| 9875 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9876 | { |
| 9877 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9878 | |
| 9879 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9880 | } |
| 9881 | |
| 9882 | |
| 9883 | static int driver_nl80211_scan2(void *priv, |
| 9884 | struct wpa_driver_scan_params *params) |
| 9885 | { |
| 9886 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9887 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9888 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9889 | |
| 9890 | /* |
| 9891 | * Do a vendor specific scan if possible. If only_new_results is |
| 9892 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 9893 | * cannot be achieved through a vendor scan. The below condition may |
| 9894 | * need to be modified if new scan flags are added in the future whose |
| 9895 | * functionality can only be achieved through a normal scan. |
| 9896 | */ |
| 9897 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 9898 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 9899 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9900 | return wpa_driver_nl80211_scan(bss, params); |
| 9901 | } |
| 9902 | |
| 9903 | |
| 9904 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9905 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9906 | { |
| 9907 | struct i802_bss *bss = priv; |
| 9908 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 9909 | } |
| 9910 | |
| 9911 | |
| 9912 | static int driver_nl80211_authenticate(void *priv, |
| 9913 | struct wpa_driver_auth_params *params) |
| 9914 | { |
| 9915 | struct i802_bss *bss = priv; |
| 9916 | return wpa_driver_nl80211_authenticate(bss, params); |
| 9917 | } |
| 9918 | |
| 9919 | |
| 9920 | static void driver_nl80211_deinit(void *priv) |
| 9921 | { |
| 9922 | struct i802_bss *bss = priv; |
| 9923 | wpa_driver_nl80211_deinit(bss); |
| 9924 | } |
| 9925 | |
| 9926 | |
| 9927 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 9928 | const char *ifname) |
| 9929 | { |
| 9930 | struct i802_bss *bss = priv; |
| 9931 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 9932 | } |
| 9933 | |
| 9934 | |
| 9935 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9936 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9937 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9938 | const u16 *csa_offs, size_t csa_offs_len, |
| 9939 | int no_encrypt, unsigned int wait) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9940 | { |
| 9941 | struct i802_bss *bss = priv; |
| 9942 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9943 | freq, 0, 0, wait, csa_offs, |
| 9944 | csa_offs_len, no_encrypt); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | |
| 9948 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 9949 | { |
| 9950 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9951 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9952 | } |
| 9953 | |
| 9954 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9955 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 9956 | const char *ifname, int vlan_id) |
| 9957 | { |
| 9958 | struct i802_bss *bss = priv; |
| 9959 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 9960 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9961 | |
| 9962 | |
| 9963 | static int driver_nl80211_read_sta_data(void *priv, |
| 9964 | struct hostap_sta_driver_data *data, |
| 9965 | const u8 *addr) |
| 9966 | { |
| 9967 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 9968 | |
| 9969 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9970 | return i802_read_sta_data(bss, data, addr); |
| 9971 | } |
| 9972 | |
| 9973 | |
| 9974 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 9975 | unsigned int wait_time, |
| 9976 | const u8 *dst, const u8 *src, |
| 9977 | const u8 *bssid, |
| 9978 | const u8 *data, size_t data_len, |
| 9979 | int no_cck) |
| 9980 | { |
| 9981 | struct i802_bss *bss = priv; |
| 9982 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 9983 | bssid, data, data_len, no_cck); |
| 9984 | } |
| 9985 | |
| 9986 | |
| 9987 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 9988 | { |
| 9989 | struct i802_bss *bss = priv; |
| 9990 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 9991 | } |
| 9992 | |
| 9993 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9994 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 9995 | const u8 *ies, size_t ies_len) |
| 9996 | { |
| 9997 | int ret; |
| 9998 | struct nl_msg *msg; |
| 9999 | struct i802_bss *bss = priv; |
| 10000 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10001 | u16 mdid = WPA_GET_LE16(md); |
| 10002 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10003 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10004 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 10005 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 10006 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 10007 | nlmsg_free(msg); |
| 10008 | return -ENOBUFS; |
| 10009 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10010 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10011 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10012 | if (ret) { |
| 10013 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 10014 | "err=%d (%s)", ret, strerror(-ret)); |
| 10015 | } |
| 10016 | |
| 10017 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10018 | } |
| 10019 | |
| 10020 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10021 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 10022 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 10023 | { |
| 10024 | int ret; |
| 10025 | struct nl_msg *msg; |
| 10026 | struct i802_bss *bss = priv; |
| 10027 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10028 | |
| 10029 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 10030 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 10031 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 10032 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 10033 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 10034 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 10035 | nlmsg_free(msg); |
| 10036 | return -ENOBUFS; |
| 10037 | } |
| 10038 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10040 | if (ret) { |
| 10041 | wpa_printf(MSG_DEBUG, |
| 10042 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 10043 | ret, strerror(-ret)); |
| 10044 | } |
| 10045 | |
| 10046 | return ret; |
| 10047 | } |
| 10048 | |
| 10049 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 10050 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10051 | { |
| 10052 | struct i802_bss *bss = priv; |
| 10053 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10054 | |
| 10055 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 10056 | return NULL; |
| 10057 | |
| 10058 | return bss->addr; |
| 10059 | } |
| 10060 | |
| 10061 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10062 | static const char * scan_state_str(enum scan_states scan_state) |
| 10063 | { |
| 10064 | switch (scan_state) { |
| 10065 | case NO_SCAN: |
| 10066 | return "NO_SCAN"; |
| 10067 | case SCAN_REQUESTED: |
| 10068 | return "SCAN_REQUESTED"; |
| 10069 | case SCAN_STARTED: |
| 10070 | return "SCAN_STARTED"; |
| 10071 | case SCAN_COMPLETED: |
| 10072 | return "SCAN_COMPLETED"; |
| 10073 | case SCAN_ABORTED: |
| 10074 | return "SCAN_ABORTED"; |
| 10075 | case SCHED_SCAN_STARTED: |
| 10076 | return "SCHED_SCAN_STARTED"; |
| 10077 | case SCHED_SCAN_STOPPED: |
| 10078 | return "SCHED_SCAN_STOPPED"; |
| 10079 | case SCHED_SCAN_RESULTS: |
| 10080 | return "SCHED_SCAN_RESULTS"; |
| 10081 | } |
| 10082 | |
| 10083 | return "??"; |
| 10084 | } |
| 10085 | |
| 10086 | |
| 10087 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 10088 | { |
| 10089 | struct i802_bss *bss = priv; |
| 10090 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10091 | int res; |
| 10092 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10093 | struct nl_msg *msg; |
| 10094 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10095 | |
| 10096 | pos = buf; |
| 10097 | end = buf + buflen; |
| 10098 | |
| 10099 | res = os_snprintf(pos, end - pos, |
| 10100 | "ifindex=%d\n" |
| 10101 | "ifname=%s\n" |
| 10102 | "brname=%s\n" |
| 10103 | "addr=" MACSTR "\n" |
| 10104 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 10105 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10106 | bss->ifindex, |
| 10107 | bss->ifname, |
| 10108 | bss->brname, |
| 10109 | MAC2STR(bss->addr), |
| 10110 | bss->freq, |
| 10111 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 10112 | bss->added_if_into_bridge ? |
| 10113 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 10114 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10115 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 10116 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 10117 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10118 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10119 | return pos - buf; |
| 10120 | pos += res; |
| 10121 | |
| 10122 | if (bss->wdev_id_set) { |
| 10123 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 10124 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10125 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10126 | return pos - buf; |
| 10127 | pos += res; |
| 10128 | } |
| 10129 | |
| 10130 | res = os_snprintf(pos, end - pos, |
| 10131 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10132 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10133 | "drv_ifindex=%d\n" |
| 10134 | "operstate=%d\n" |
| 10135 | "scan_state=%s\n" |
| 10136 | "auth_bssid=" MACSTR "\n" |
| 10137 | "auth_attempt_bssid=" MACSTR "\n" |
| 10138 | "bssid=" MACSTR "\n" |
| 10139 | "prev_bssid=" MACSTR "\n" |
| 10140 | "associated=%d\n" |
| 10141 | "assoc_freq=%u\n" |
| 10142 | "monitor_sock=%d\n" |
| 10143 | "monitor_ifidx=%d\n" |
| 10144 | "monitor_refcount=%d\n" |
| 10145 | "last_mgmt_freq=%u\n" |
| 10146 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10147 | "%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] | 10148 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10149 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10150 | drv->ifindex, |
| 10151 | drv->operstate, |
| 10152 | scan_state_str(drv->scan_state), |
| 10153 | MAC2STR(drv->auth_bssid), |
| 10154 | MAC2STR(drv->auth_attempt_bssid), |
| 10155 | MAC2STR(drv->bssid), |
| 10156 | MAC2STR(drv->prev_bssid), |
| 10157 | drv->associated, |
| 10158 | drv->assoc_freq, |
| 10159 | drv->monitor_sock, |
| 10160 | drv->monitor_ifidx, |
| 10161 | drv->monitor_refcount, |
| 10162 | drv->last_mgmt_freq, |
| 10163 | drv->eapol_tx_sock, |
| 10164 | drv->ignore_if_down_event ? |
| 10165 | "ignore_if_down_event=1\n" : "", |
| 10166 | drv->scan_complete_events ? |
| 10167 | "scan_complete_events=1\n" : "", |
| 10168 | drv->disabled_11b_rates ? |
| 10169 | "disabled_11b_rates=1\n" : "", |
| 10170 | drv->pending_remain_on_chan ? |
| 10171 | "pending_remain_on_chan=1\n" : "", |
| 10172 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 10173 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 10174 | drv->poll_command_supported ? |
| 10175 | "poll_command_supported=1\n" : "", |
| 10176 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 10177 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 10178 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 10179 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 10180 | drv->ignore_next_local_disconnect ? |
| 10181 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 10182 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10183 | "ignore_next_local_deauth=1\n" : ""); |
| 10184 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10185 | return pos - buf; |
| 10186 | pos += res; |
| 10187 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 10188 | if (drv->sta_mlo_info.valid_links) { |
| 10189 | int i; |
| 10190 | struct driver_sta_mlo_info *mlo = &drv->sta_mlo_info; |
| 10191 | |
| 10192 | res = os_snprintf(pos, end - pos, |
| 10193 | "ap_mld_addr=" MACSTR "\n", |
| 10194 | MAC2STR(mlo->ap_mld_addr)); |
| 10195 | if (os_snprintf_error(end - pos, res)) |
| 10196 | return pos - buf; |
| 10197 | pos += res; |
| 10198 | |
| 10199 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 10200 | if (!(mlo->valid_links & BIT(i))) |
| 10201 | continue; |
| 10202 | |
| 10203 | res = os_snprintf(pos, end - pos, |
| 10204 | "link_addr[%u]=" MACSTR "\n" |
| 10205 | "link_bssid[%u]=" MACSTR "\n" |
| 10206 | "link_freq[%u]=%u\n", |
| 10207 | i, MAC2STR(mlo->links[i].addr), |
| 10208 | i, MAC2STR(mlo->links[i].bssid), |
| 10209 | i, mlo->links[i].freq); |
| 10210 | if (os_snprintf_error(end - pos, res)) |
| 10211 | return pos - buf; |
| 10212 | pos += res; |
| 10213 | } |
| 10214 | } |
| 10215 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10216 | if (drv->has_capability) { |
| 10217 | res = os_snprintf(pos, end - pos, |
| 10218 | "capa.key_mgmt=0x%x\n" |
| 10219 | "capa.enc=0x%x\n" |
| 10220 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10221 | "capa.flags=0x%llx\n" |
| 10222 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10223 | "capa.max_scan_ssids=%d\n" |
| 10224 | "capa.max_sched_scan_ssids=%d\n" |
| 10225 | "capa.sched_scan_supported=%d\n" |
| 10226 | "capa.max_match_sets=%d\n" |
| 10227 | "capa.max_remain_on_chan=%u\n" |
| 10228 | "capa.max_stations=%u\n" |
| 10229 | "capa.probe_resp_offloads=0x%x\n" |
| 10230 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10231 | "capa.num_multichan_concurrent=%u\n" |
| 10232 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10233 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 10234 | "capa.conc_capab=%u\n" |
| 10235 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10236 | "capa.max_conc_chan_5_0=%u\n" |
| 10237 | "capa.max_sched_scan_plans=%u\n" |
| 10238 | "capa.max_sched_scan_plan_interval=%u\n" |
| 10239 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10240 | drv->capa.key_mgmt, |
| 10241 | drv->capa.enc, |
| 10242 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10243 | (unsigned long long) drv->capa.flags, |
| 10244 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10245 | drv->capa.max_scan_ssids, |
| 10246 | drv->capa.max_sched_scan_ssids, |
| 10247 | drv->capa.sched_scan_supported, |
| 10248 | drv->capa.max_match_sets, |
| 10249 | drv->capa.max_remain_on_chan, |
| 10250 | drv->capa.max_stations, |
| 10251 | drv->capa.probe_resp_offloads, |
| 10252 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10253 | drv->capa.num_multichan_concurrent, |
| 10254 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10255 | drv->capa.mac_addr_rand_scan_supported, |
| 10256 | drv->capa.conc_capab, |
| 10257 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10258 | drv->capa.max_conc_chan_5_0, |
| 10259 | drv->capa.max_sched_scan_plans, |
| 10260 | drv->capa.max_sched_scan_plan_interval, |
| 10261 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10262 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10263 | return pos - buf; |
| 10264 | pos += res; |
| 10265 | } |
| 10266 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10267 | msg = nlmsg_alloc(); |
| 10268 | if (msg && |
| 10269 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 10270 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 10271 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10272 | alpha2, NULL, NULL) == 0 && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10273 | alpha2[0]) { |
| 10274 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 10275 | alpha2); |
| 10276 | if (os_snprintf_error(end - pos, res)) |
| 10277 | return pos - buf; |
| 10278 | pos += res; |
| 10279 | } |
| 10280 | } else { |
| 10281 | nlmsg_free(msg); |
| 10282 | } |
| 10283 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10284 | return pos - buf; |
| 10285 | } |
| 10286 | |
| 10287 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10288 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 10289 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10290 | if ((settings->head && |
| 10291 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 10292 | settings->head_len, settings->head)) || |
| 10293 | (settings->tail && |
| 10294 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 10295 | settings->tail_len, settings->tail)) || |
| 10296 | (settings->beacon_ies && |
| 10297 | nla_put(msg, NL80211_ATTR_IE, |
| 10298 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 10299 | (settings->proberesp_ies && |
| 10300 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 10301 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 10302 | (settings->assocresp_ies && |
| 10303 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 10304 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 10305 | (settings->probe_resp && |
| 10306 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 10307 | settings->probe_resp_len, settings->probe_resp))) |
| 10308 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10309 | |
| 10310 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10311 | } |
| 10312 | |
| 10313 | |
| 10314 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 10315 | { |
| 10316 | struct nl_msg *msg; |
| 10317 | struct i802_bss *bss = priv; |
| 10318 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10319 | struct nlattr *beacon_csa; |
| 10320 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10321 | int csa_off_len = 0; |
| 10322 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10323 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10324 | wpa_printf(MSG_DEBUG, |
| 10325 | "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] | 10326 | settings->cs_count, settings->block_tx, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10327 | settings->freq_params.freq, |
| 10328 | settings->freq_params.channel, |
| 10329 | settings->freq_params.sec_channel_offset, |
| 10330 | settings->freq_params.bandwidth, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 10331 | settings->freq_params.center_freq1, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10332 | settings->freq_params.center_freq2, |
| 10333 | settings->freq_params.ht_enabled ? " ht" : "", |
| 10334 | settings->freq_params.vht_enabled ? " vht" : "", |
| 10335 | settings->freq_params.he_enabled ? " he" : ""); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10336 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10337 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10338 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 10339 | return -EOPNOTSUPP; |
| 10340 | } |
| 10341 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10342 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 10343 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 10344 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10345 | return -EOPNOTSUPP; |
| 10346 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10347 | /* |
| 10348 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 10349 | * counters match. This implementation assumes that there are only two |
| 10350 | * counters. |
| 10351 | */ |
| 10352 | if (settings->counter_offset_beacon[0] && |
| 10353 | !settings->counter_offset_beacon[1]) { |
| 10354 | csa_off_len = 1; |
| 10355 | } else if (settings->counter_offset_beacon[1] && |
| 10356 | !settings->counter_offset_beacon[0]) { |
| 10357 | csa_off_len = 1; |
| 10358 | settings->counter_offset_beacon[0] = |
| 10359 | settings->counter_offset_beacon[1]; |
| 10360 | settings->counter_offset_presp[0] = |
| 10361 | settings->counter_offset_presp[1]; |
| 10362 | } else if (settings->counter_offset_beacon[1] && |
| 10363 | settings->counter_offset_beacon[0]) { |
| 10364 | csa_off_len = 2; |
| 10365 | } else { |
| 10366 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 10367 | return -EINVAL; |
| 10368 | } |
| 10369 | |
| 10370 | /* Check CSA counters validity */ |
| 10371 | if (drv->capa.max_csa_counters && |
| 10372 | csa_off_len > drv->capa.max_csa_counters) { |
| 10373 | wpa_printf(MSG_ERROR, |
| 10374 | "nl80211: Too many CSA counters provided"); |
| 10375 | return -EINVAL; |
| 10376 | } |
| 10377 | |
| 10378 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10379 | return -EINVAL; |
| 10380 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10381 | for (i = 0; i < csa_off_len; i++) { |
| 10382 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 10383 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 10384 | |
| 10385 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 10386 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 10387 | settings->cs_count)) |
| 10388 | return -EINVAL; |
| 10389 | |
| 10390 | if (settings->beacon_csa.probe_resp && |
| 10391 | ((settings->beacon_csa.probe_resp_len <= |
| 10392 | csa_c_off_presp) || |
| 10393 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 10394 | settings->cs_count))) |
| 10395 | return -EINVAL; |
| 10396 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10397 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10398 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 10399 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 10400 | settings->cs_count) || |
| 10401 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 10402 | (settings->block_tx && |
| 10403 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10404 | goto error; |
| 10405 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10406 | /* beacon_after params */ |
| 10407 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 10408 | if (ret) |
| 10409 | goto error; |
| 10410 | |
| 10411 | /* beacon_csa params */ |
| 10412 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 10413 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10414 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10415 | |
| 10416 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 10417 | if (ret) |
| 10418 | goto error; |
| 10419 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10420 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 10421 | csa_off_len * sizeof(u16), |
| 10422 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10423 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10424 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 10425 | csa_off_len * sizeof(u16), |
| 10426 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10427 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10428 | |
| 10429 | nla_nest_end(msg, beacon_csa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10430 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10431 | if (ret) { |
| 10432 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 10433 | ret, strerror(-ret)); |
| 10434 | } |
| 10435 | return ret; |
| 10436 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10437 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10438 | ret = -ENOBUFS; |
| 10439 | error: |
| 10440 | nlmsg_free(msg); |
| 10441 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 10442 | return ret; |
| 10443 | } |
| 10444 | |
| 10445 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10446 | #ifdef CONFIG_IEEE80211AX |
| 10447 | static int nl80211_switch_color(void *priv, struct cca_settings *settings) |
| 10448 | { |
| 10449 | struct i802_bss *bss = priv; |
| 10450 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10451 | struct nlattr *beacon_cca; |
| 10452 | struct nl_msg *msg; |
| 10453 | int ret = -ENOBUFS; |
| 10454 | |
| 10455 | wpa_printf(MSG_DEBUG, |
| 10456 | "nl80211: Color change request (cca_count=%u color=%d)", |
| 10457 | settings->cca_count, settings->cca_color); |
| 10458 | |
| 10459 | if (drv->nlmode != NL80211_IFTYPE_AP) |
| 10460 | return -EOPNOTSUPP; |
| 10461 | |
| 10462 | if (!settings->beacon_cca.tail) |
| 10463 | return -EINVAL; |
| 10464 | |
| 10465 | if (settings->beacon_cca.tail_len <= settings->counter_offset_beacon || |
| 10466 | settings->beacon_cca.tail[settings->counter_offset_beacon] != |
| 10467 | settings->cca_count) |
| 10468 | return -EINVAL; |
| 10469 | |
| 10470 | if (settings->beacon_cca.probe_resp && |
| 10471 | (settings->beacon_cca.probe_resp_len <= |
| 10472 | settings->counter_offset_presp || |
| 10473 | settings->beacon_cca.probe_resp[settings->counter_offset_presp] != |
| 10474 | settings->cca_count)) |
| 10475 | return -EINVAL; |
| 10476 | |
| 10477 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_COLOR_CHANGE_REQUEST); |
| 10478 | if (!msg || |
| 10479 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, |
| 10480 | settings->cca_count) || |
| 10481 | nla_put_u8(msg, NL80211_ATTR_COLOR_CHANGE_COLOR, |
| 10482 | settings->cca_color)) |
| 10483 | goto error; |
| 10484 | |
| 10485 | /* beacon_after params */ |
| 10486 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 10487 | if (ret) |
| 10488 | goto error; |
| 10489 | |
| 10490 | /* beacon_csa params */ |
| 10491 | beacon_cca = nla_nest_start(msg, NL80211_ATTR_COLOR_CHANGE_ELEMS); |
| 10492 | if (!beacon_cca) { |
| 10493 | ret = -ENOBUFS; |
| 10494 | goto error; |
| 10495 | } |
| 10496 | |
| 10497 | ret = set_beacon_data(msg, &settings->beacon_cca); |
| 10498 | if (ret) |
| 10499 | goto error; |
| 10500 | |
| 10501 | if (nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_BEACON, |
| 10502 | settings->counter_offset_beacon) || |
| 10503 | (settings->beacon_cca.probe_resp && |
| 10504 | nla_put_u16(msg, NL80211_ATTR_CNTDWN_OFFS_PRESP, |
| 10505 | settings->counter_offset_presp))) { |
| 10506 | ret = -ENOBUFS; |
| 10507 | goto error; |
| 10508 | } |
| 10509 | |
| 10510 | nla_nest_end(msg, beacon_cca); |
| 10511 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 10512 | if (ret) { |
| 10513 | wpa_printf(MSG_DEBUG, |
| 10514 | "nl80211: switch_color failed err=%d (%s)", |
| 10515 | ret, strerror(-ret)); |
| 10516 | } |
| 10517 | return ret; |
| 10518 | |
| 10519 | error: |
| 10520 | nlmsg_free(msg); |
| 10521 | wpa_printf(MSG_DEBUG, "nl80211: Could not build color switch request"); |
| 10522 | return ret; |
| 10523 | } |
| 10524 | #endif /* CONFIG_IEEE80211AX */ |
| 10525 | |
| 10526 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10527 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 10528 | u8 user_priority, u16 admitted_time) |
| 10529 | { |
| 10530 | struct i802_bss *bss = priv; |
| 10531 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10532 | struct nl_msg *msg; |
| 10533 | int ret; |
| 10534 | |
| 10535 | wpa_printf(MSG_DEBUG, |
| 10536 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 10537 | tsid, admitted_time, user_priority); |
| 10538 | |
| 10539 | if (!is_sta_interface(drv->nlmode)) |
| 10540 | return -ENOTSUP; |
| 10541 | |
| 10542 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 10543 | if (!msg || |
| 10544 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10545 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10546 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 10547 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 10548 | nlmsg_free(msg); |
| 10549 | return -ENOBUFS; |
| 10550 | } |
| 10551 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10552 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10553 | if (ret) |
| 10554 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 10555 | ret, strerror(-ret)); |
| 10556 | return ret; |
| 10557 | } |
| 10558 | |
| 10559 | |
| 10560 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 10561 | { |
| 10562 | struct i802_bss *bss = priv; |
| 10563 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10564 | struct nl_msg *msg; |
| 10565 | int ret; |
| 10566 | |
| 10567 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 10568 | |
| 10569 | if (!is_sta_interface(drv->nlmode)) |
| 10570 | return -ENOTSUP; |
| 10571 | |
| 10572 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 10573 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10574 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10575 | nlmsg_free(msg); |
| 10576 | return -ENOBUFS; |
| 10577 | } |
| 10578 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10579 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10580 | if (ret) |
| 10581 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 10582 | ret, strerror(-ret)); |
| 10583 | return ret; |
| 10584 | } |
| 10585 | |
| 10586 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10587 | #ifdef CONFIG_TESTING_OPTIONS |
| 10588 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 10589 | { |
| 10590 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10591 | struct wpabuf *buf = arg; |
| 10592 | |
| 10593 | if (!buf) |
| 10594 | return NL_SKIP; |
| 10595 | |
| 10596 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 10597 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 10598 | return NL_SKIP; |
| 10599 | } |
| 10600 | |
| 10601 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 10602 | genlmsg_attrlen(gnlh, 0)); |
| 10603 | |
| 10604 | return NL_SKIP; |
| 10605 | } |
| 10606 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10607 | |
| 10608 | |
| 10609 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 10610 | { |
| 10611 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10612 | struct nlattr *nl_vendor_reply, *nl; |
| 10613 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10614 | struct wpabuf *buf = arg; |
| 10615 | int rem; |
| 10616 | |
| 10617 | if (!buf) |
| 10618 | return NL_SKIP; |
| 10619 | |
| 10620 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10621 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10622 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10623 | |
| 10624 | if (!nl_vendor_reply) |
| 10625 | return NL_SKIP; |
| 10626 | |
| 10627 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 10628 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 10629 | return NL_SKIP; |
| 10630 | } |
| 10631 | |
| 10632 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 10633 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 10634 | } |
| 10635 | |
| 10636 | return NL_SKIP; |
| 10637 | } |
| 10638 | |
| 10639 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10640 | static bool is_cmd_with_nested_attrs(unsigned int vendor_id, |
| 10641 | unsigned int subcmd) |
| 10642 | { |
| 10643 | if (vendor_id != OUI_QCA) |
| 10644 | return true; |
| 10645 | |
| 10646 | switch (subcmd) { |
| 10647 | case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY: |
| 10648 | case QCA_NL80211_VENDOR_SUBCMD_STATS_EXT: |
| 10649 | case QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI: |
| 10650 | case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY: |
| 10651 | case QCA_NL80211_VENDOR_SUBCMD_SPECTRAL_SCAN_GET_STATUS: |
| 10652 | case QCA_NL80211_VENDOR_SUBCMD_NAN: |
| 10653 | return false; |
| 10654 | default: |
| 10655 | return true; |
| 10656 | } |
| 10657 | } |
| 10658 | |
| 10659 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10660 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 10661 | unsigned int subcmd, const u8 *data, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10662 | size_t data_len, enum nested_attr nested_attr, |
| 10663 | struct wpabuf *buf) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10664 | { |
| 10665 | struct i802_bss *bss = priv; |
| 10666 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10667 | struct nl_msg *msg; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10668 | int ret, nla_flag; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10669 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10670 | #ifdef CONFIG_TESTING_OPTIONS |
| 10671 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10672 | msg = nlmsg_alloc(); |
| 10673 | if (!msg) |
| 10674 | return -ENOMEM; |
| 10675 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10676 | nl80211_cmd(drv, msg, 0, subcmd); |
| 10677 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 10678 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10679 | goto fail; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10680 | /* This test vendor_cmd can be used with nl80211 commands that |
| 10681 | * need the connect nl_sock, so use the owner-setting variant |
| 10682 | * of send_and_recv_msgs(). */ |
| 10683 | ret = send_and_recv_msgs_owner(drv, msg, |
| 10684 | get_connect_handle(bss), 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10685 | cmd_reply_handler, buf, |
| 10686 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10687 | if (ret) |
| 10688 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 10689 | ret); |
| 10690 | return ret; |
| 10691 | } |
| 10692 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10693 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10694 | if (nested_attr == NESTED_ATTR_USED) |
| 10695 | nla_flag = NLA_F_NESTED; |
| 10696 | else if (nested_attr == NESTED_ATTR_UNSPECIFIED && |
| 10697 | is_cmd_with_nested_attrs(vendor_id, subcmd)) |
| 10698 | nla_flag = NLA_F_NESTED; |
| 10699 | else |
| 10700 | nla_flag = 0; |
| 10701 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10702 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 10703 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 10704 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 10705 | (data && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10706 | nla_put(msg, nla_flag | NL80211_ATTR_VENDOR_DATA, |
| 10707 | data_len, data))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10708 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10709 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10710 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf, |
| 10711 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10712 | if (ret) |
| 10713 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 10714 | ret); |
| 10715 | return ret; |
| 10716 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10717 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10718 | nlmsg_free(msg); |
| 10719 | return -ENOBUFS; |
| 10720 | } |
| 10721 | |
| 10722 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10723 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 10724 | u8 qos_map_set_len) |
| 10725 | { |
| 10726 | struct i802_bss *bss = priv; |
| 10727 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10728 | struct nl_msg *msg; |
| 10729 | int ret; |
| 10730 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10731 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 10732 | qos_map_set, qos_map_set_len); |
| 10733 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10734 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 10735 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 10736 | nlmsg_free(msg); |
| 10737 | return -ENOBUFS; |
| 10738 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10739 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10740 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10741 | if (ret) |
| 10742 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 10743 | |
| 10744 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10745 | } |
| 10746 | |
| 10747 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10748 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 10749 | { |
| 10750 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10751 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10752 | int *wowlan_enabled = arg; |
| 10753 | |
| 10754 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10755 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10756 | |
| 10757 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 10758 | |
| 10759 | return NL_SKIP; |
| 10760 | } |
| 10761 | |
| 10762 | |
| 10763 | static int nl80211_get_wowlan(void *priv) |
| 10764 | { |
| 10765 | struct i802_bss *bss = priv; |
| 10766 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10767 | struct nl_msg *msg; |
| 10768 | int wowlan_enabled; |
| 10769 | int ret; |
| 10770 | |
| 10771 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 10772 | |
| 10773 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 10774 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10775 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled, |
| 10776 | NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10777 | if (ret) { |
| 10778 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 10779 | return 0; |
| 10780 | } |
| 10781 | |
| 10782 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 10783 | wowlan_enabled ? "enabled" : "disabled"); |
| 10784 | |
| 10785 | return wowlan_enabled; |
| 10786 | } |
| 10787 | |
| 10788 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10789 | static int nl80211_set_wowlan(void *priv, |
| 10790 | const struct wowlan_triggers *triggers) |
| 10791 | { |
| 10792 | struct i802_bss *bss = priv; |
| 10793 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10794 | struct nl_msg *msg; |
| 10795 | struct nlattr *wowlan_triggers; |
| 10796 | int ret; |
| 10797 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10798 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 10799 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 10800 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10801 | !(wowlan_triggers = nla_nest_start(msg, |
| 10802 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 10803 | (triggers->any && |
| 10804 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 10805 | (triggers->disconnect && |
| 10806 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 10807 | (triggers->magic_pkt && |
| 10808 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 10809 | (triggers->gtk_rekey_failure && |
| 10810 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 10811 | (triggers->eap_identity_req && |
| 10812 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 10813 | (triggers->four_way_handshake && |
| 10814 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 10815 | (triggers->rfkill_release && |
| 10816 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 10817 | nlmsg_free(msg); |
| 10818 | return -ENOBUFS; |
| 10819 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10820 | |
| 10821 | nla_nest_end(msg, wowlan_triggers); |
| 10822 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10823 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10824 | if (ret) |
| 10825 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 10826 | |
| 10827 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10828 | } |
| 10829 | |
| 10830 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10831 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10832 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 10833 | { |
| 10834 | struct i802_bss *bss = priv; |
| 10835 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10836 | struct nl_msg *msg; |
| 10837 | struct nlattr *params; |
| 10838 | |
| 10839 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 10840 | |
| 10841 | if (!drv->roaming_vendor_cmd_avail) { |
| 10842 | wpa_printf(MSG_DEBUG, |
| 10843 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 10844 | return -1; |
| 10845 | } |
| 10846 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10847 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10848 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10849 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10850 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 10851 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10852 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 10853 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 10854 | QCA_ROAMING_NOT_ALLOWED) || |
| 10855 | (bssid && |
| 10856 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 10857 | nlmsg_free(msg); |
| 10858 | return -1; |
| 10859 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10860 | nla_nest_end(msg, params); |
| 10861 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10862 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10863 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10864 | |
| 10865 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10866 | static int nl80211_disable_fils(void *priv, int disable) |
| 10867 | { |
| 10868 | struct i802_bss *bss = priv; |
| 10869 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10870 | struct nl_msg *msg; |
| 10871 | struct nlattr *params; |
| 10872 | |
| 10873 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 10874 | |
| 10875 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10876 | return -1; |
| 10877 | |
| 10878 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10879 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10880 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10881 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 10882 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10883 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 10884 | disable)) { |
| 10885 | nlmsg_free(msg); |
| 10886 | return -1; |
| 10887 | } |
| 10888 | nla_nest_end(msg, params); |
| 10889 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10890 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10891 | } |
| 10892 | |
| 10893 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10894 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 10895 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 10896 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10897 | static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid, |
| 10898 | const u8 *bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10899 | { |
| 10900 | struct i802_bss *bss = priv; |
| 10901 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10902 | struct nl_msg *msg; |
| 10903 | struct nlattr *params, *nlbssids, *attr; |
| 10904 | unsigned int i; |
| 10905 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10906 | wpa_printf(MSG_DEBUG, |
| 10907 | "nl80211: Set temporarily disallowed BSSIDs (num=%u)", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10908 | num_bssid); |
| 10909 | |
| 10910 | if (!drv->roam_vendor_cmd_avail) |
| 10911 | return -1; |
| 10912 | |
| 10913 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10914 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10915 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10916 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 10917 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10918 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10919 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10920 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 10921 | WPA_SUPPLICANT_CLIENT_ID) || |
| 10922 | nla_put_u32(msg, |
| 10923 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 10924 | num_bssid)) |
| 10925 | goto fail; |
| 10926 | |
| 10927 | nlbssids = nla_nest_start( |
| 10928 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 10929 | if (!nlbssids) |
| 10930 | goto fail; |
| 10931 | |
| 10932 | for (i = 0; i < num_bssid; i++) { |
| 10933 | attr = nla_nest_start(msg, i); |
| 10934 | if (!attr) |
| 10935 | goto fail; |
| 10936 | if (nla_put(msg, |
| 10937 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 10938 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 10939 | goto fail; |
| 10940 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 10941 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 10942 | nla_nest_end(msg, attr); |
| 10943 | } |
| 10944 | nla_nest_end(msg, nlbssids); |
| 10945 | nla_nest_end(msg, params); |
| 10946 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10947 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10948 | |
| 10949 | fail: |
| 10950 | nlmsg_free(msg); |
| 10951 | return -1; |
| 10952 | } |
| 10953 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10954 | |
| 10955 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 10956 | { |
| 10957 | struct i802_bss *bss = priv; |
| 10958 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10959 | struct nl_msg *msg; |
| 10960 | struct nlattr *params; |
| 10961 | |
| 10962 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 10963 | return -EOPNOTSUPP; |
| 10964 | |
| 10965 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 10966 | |
| 10967 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10968 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10969 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10970 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 10971 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10972 | (addr && |
| 10973 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 10974 | addr)) || |
| 10975 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 10976 | auth_alg)) { |
| 10977 | nlmsg_free(msg); |
| 10978 | wpa_printf(MSG_ERROR, |
| 10979 | "%s: err in adding vendor_cmd and vendor_data", |
| 10980 | __func__); |
| 10981 | return -1; |
| 10982 | } |
| 10983 | nla_nest_end(msg, params); |
| 10984 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10985 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10986 | } |
| 10987 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10988 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10989 | |
| 10990 | |
| 10991 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 10992 | { |
| 10993 | struct i802_bss *bss = priv; |
| 10994 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10995 | int new_addr = addr != NULL; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 10996 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10997 | struct nl_msg *msg; |
| 10998 | struct nlattr *params; |
| 10999 | int ret; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11000 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11001 | wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11002 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11003 | if (TEST_FAIL()) |
| 11004 | return -1; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11005 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11006 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11007 | if (!addr ) { |
| 11008 | addr = drv->global->p2p_perm_addr; |
| 11009 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11010 | |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11011 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 11012 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 11013 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11014 | BRCM_VENDOR_SCMD_SET_MAC) || |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11015 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11016 | nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) { |
| 11017 | wpa_printf(MSG_ERROR, "failed to put p2p randmac"); |
| 11018 | nl80211_nlmsg_clear(msg); |
| 11019 | nlmsg_free(msg); |
| 11020 | return -ENOBUFS; |
| 11021 | } |
| 11022 | nla_nest_end(msg, params); |
| 11023 | |
| 11024 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 11025 | if (ret) { |
| 11026 | wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)", |
| 11027 | ret, strerror(-ret)); |
| 11028 | } |
| 11029 | memcpy(bss->addr, addr, ETH_ALEN); |
| 11030 | return ret; |
| 11031 | #else |
| 11032 | return -ENOTSUP; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 11033 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11034 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11035 | if (!addr) |
| 11036 | addr = drv->perm_addr; |
| 11037 | |
| 11038 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 11039 | return -1; |
| 11040 | |
| 11041 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 11042 | { |
| 11043 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11044 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 11045 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11046 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11047 | 1) < 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11048 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11049 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11050 | } |
| 11051 | return -1; |
| 11052 | } |
| 11053 | |
| 11054 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11055 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11056 | drv->addr_changed = new_addr; |
| 11057 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 11058 | |
| 11059 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 11060 | { |
| 11061 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 11062 | "nl80211: Could not restore interface UP after set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11063 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11064 | return 0; |
| 11065 | } |
| 11066 | |
| 11067 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11068 | #ifdef CONFIG_MESH |
| 11069 | |
| 11070 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 11071 | { |
| 11072 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 11073 | wpa_printf(MSG_INFO, |
| 11074 | "nl80211: Failed to set interface into mesh mode"); |
| 11075 | return -1; |
| 11076 | } |
| 11077 | return 0; |
| 11078 | } |
| 11079 | |
| 11080 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11081 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 11082 | size_t mesh_id_len) |
| 11083 | { |
| 11084 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11085 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 11086 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11087 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 11088 | } |
| 11089 | |
| 11090 | return 0; |
| 11091 | } |
| 11092 | |
| 11093 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11094 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 11095 | struct wpa_driver_mesh_bss_params *params) |
| 11096 | { |
| 11097 | struct nlattr *container; |
| 11098 | |
| 11099 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 11100 | if (!container) |
| 11101 | return -1; |
| 11102 | |
| 11103 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11104 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 11105 | params->auto_plinks)) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11106 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) && |
| 11107 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 11108 | params->forwarding)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11109 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 11110 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11111 | params->max_peer_links)) || |
| 11112 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 11113 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 11114 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11115 | return -1; |
| 11116 | |
| 11117 | /* |
| 11118 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 11119 | * the timer could disconnect stations even in that case. |
| 11120 | */ |
| 11121 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 11122 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 11123 | params->peer_link_timeout)) { |
| 11124 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 11125 | return -1; |
| 11126 | } |
| 11127 | |
| 11128 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 11129 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 11130 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 11131 | return -1; |
| 11132 | } |
| 11133 | |
| 11134 | nla_nest_end(msg, container); |
| 11135 | |
| 11136 | return 0; |
| 11137 | } |
| 11138 | |
| 11139 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11140 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11141 | struct wpa_driver_mesh_join_params *params) |
| 11142 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11143 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11144 | struct nl_msg *msg; |
| 11145 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 11146 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11147 | |
| 11148 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 11149 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 11150 | if (!msg || |
| 11151 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 11152 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 11153 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11154 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 11155 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11156 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11157 | |
| 11158 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 11159 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11160 | if (params->handle_dfs && nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS)) |
| 11161 | goto fail; |
| 11162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11163 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 11164 | if (!container) |
| 11165 | goto fail; |
| 11166 | |
| 11167 | if (params->ies) { |
| 11168 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 11169 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 11170 | params->ies)) |
| 11171 | goto fail; |
| 11172 | } |
| 11173 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 11174 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 11175 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 11176 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 11177 | goto fail; |
| 11178 | } |
| 11179 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 11180 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 11181 | goto fail; |
| 11182 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 11183 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 11184 | goto fail; |
| 11185 | nla_nest_end(msg, container); |
| 11186 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 11187 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 11188 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 11189 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 11190 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11191 | goto fail; |
| 11192 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11193 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11194 | msg = NULL; |
| 11195 | if (ret) { |
| 11196 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 11197 | ret, strerror(-ret)); |
| 11198 | goto fail; |
| 11199 | } |
| 11200 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11201 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11202 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 11203 | |
| 11204 | fail: |
| 11205 | nlmsg_free(msg); |
| 11206 | return ret; |
| 11207 | } |
| 11208 | |
| 11209 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11210 | static int |
| 11211 | wpa_driver_nl80211_join_mesh(void *priv, |
| 11212 | struct wpa_driver_mesh_join_params *params) |
| 11213 | { |
| 11214 | struct i802_bss *bss = priv; |
| 11215 | int ret, timeout; |
| 11216 | |
| 11217 | timeout = params->conf.peer_link_timeout; |
| 11218 | |
| 11219 | /* Disable kernel inactivity timer */ |
| 11220 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 11221 | params->conf.peer_link_timeout = 0; |
| 11222 | |
| 11223 | ret = nl80211_join_mesh(bss, params); |
| 11224 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 11225 | wpa_printf(MSG_DEBUG, |
| 11226 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 11227 | /* |
| 11228 | * Old kernel does not support setting |
| 11229 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 11230 | * into future from peer_link_timeout. |
| 11231 | */ |
| 11232 | params->conf.peer_link_timeout = timeout + 60; |
| 11233 | ret = nl80211_join_mesh(priv, params); |
| 11234 | } |
| 11235 | |
| 11236 | params->conf.peer_link_timeout = timeout; |
| 11237 | return ret; |
| 11238 | } |
| 11239 | |
| 11240 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11241 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 11242 | { |
| 11243 | struct i802_bss *bss = priv; |
| 11244 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11245 | struct nl_msg *msg; |
| 11246 | int ret; |
| 11247 | |
| 11248 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 11249 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11250 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11251 | if (ret) { |
| 11252 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 11253 | ret, strerror(-ret)); |
| 11254 | } else { |
| 11255 | wpa_printf(MSG_DEBUG, |
| 11256 | "nl80211: mesh leave request send successfully"); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11257 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11258 | } |
| 11259 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11260 | if (drv->start_mode_sta && |
| 11261 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11262 | NL80211_IFTYPE_STATION)) { |
| 11263 | wpa_printf(MSG_INFO, |
| 11264 | "nl80211: Failed to set interface into station mode"); |
| 11265 | } |
| 11266 | return ret; |
| 11267 | } |
| 11268 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11269 | |
| 11270 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 11271 | size_t len) |
| 11272 | { |
| 11273 | struct i802_bss *bss = priv; |
| 11274 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11275 | struct nl_msg *msg; |
| 11276 | int ret; |
| 11277 | |
| 11278 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 11279 | if (!msg || |
| 11280 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11281 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 11282 | nlmsg_free(msg); |
| 11283 | return -ENOBUFS; |
| 11284 | } |
| 11285 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11286 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11287 | if (ret) { |
| 11288 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 11289 | " failed: ret=%d (%s)", |
| 11290 | MAC2STR(addr), ret, strerror(-ret)); |
| 11291 | } else { |
| 11292 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 11293 | " probed successfully", MAC2STR(addr)); |
| 11294 | } |
| 11295 | |
| 11296 | return ret; |
| 11297 | } |
| 11298 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11299 | #endif /* CONFIG_MESH */ |
| 11300 | |
| 11301 | |
| 11302 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 11303 | const u8 *ipaddr, int prefixlen, |
| 11304 | const u8 *addr) |
| 11305 | { |
| 11306 | #ifdef CONFIG_LIBNL3_ROUTE |
| 11307 | struct i802_bss *bss = priv; |
| 11308 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11309 | struct rtnl_neigh *rn; |
| 11310 | struct nl_addr *nl_ipaddr = NULL; |
| 11311 | struct nl_addr *nl_lladdr = NULL; |
| 11312 | int family, addrsize; |
| 11313 | int res; |
| 11314 | |
| 11315 | if (!ipaddr || prefixlen == 0 || !addr) |
| 11316 | return -EINVAL; |
| 11317 | |
| 11318 | if (bss->br_ifindex == 0) { |
| 11319 | wpa_printf(MSG_DEBUG, |
| 11320 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 11321 | return -1; |
| 11322 | } |
| 11323 | |
| 11324 | if (!drv->rtnl_sk) { |
| 11325 | wpa_printf(MSG_DEBUG, |
| 11326 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 11327 | return -1; |
| 11328 | } |
| 11329 | |
| 11330 | if (version == 4) { |
| 11331 | family = AF_INET; |
| 11332 | addrsize = 4; |
| 11333 | } else if (version == 6) { |
| 11334 | family = AF_INET6; |
| 11335 | addrsize = 16; |
| 11336 | } else { |
| 11337 | return -EINVAL; |
| 11338 | } |
| 11339 | |
| 11340 | rn = rtnl_neigh_alloc(); |
| 11341 | if (rn == NULL) |
| 11342 | return -ENOMEM; |
| 11343 | |
| 11344 | /* set the destination ip address for neigh */ |
| 11345 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 11346 | if (nl_ipaddr == NULL) { |
| 11347 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 11348 | res = -ENOMEM; |
| 11349 | goto errout; |
| 11350 | } |
| 11351 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 11352 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 11353 | if (res) { |
| 11354 | wpa_printf(MSG_DEBUG, |
| 11355 | "nl80211: neigh set destination addr failed"); |
| 11356 | goto errout; |
| 11357 | } |
| 11358 | |
| 11359 | /* set the corresponding lladdr for neigh */ |
| 11360 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 11361 | if (nl_lladdr == NULL) { |
| 11362 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 11363 | res = -ENOMEM; |
| 11364 | goto errout; |
| 11365 | } |
| 11366 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 11367 | |
| 11368 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 11369 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 11370 | |
| 11371 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 11372 | if (res) { |
| 11373 | wpa_printf(MSG_DEBUG, |
| 11374 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11375 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11376 | } |
| 11377 | errout: |
| 11378 | if (nl_lladdr) |
| 11379 | nl_addr_put(nl_lladdr); |
| 11380 | if (nl_ipaddr) |
| 11381 | nl_addr_put(nl_ipaddr); |
| 11382 | if (rn) |
| 11383 | rtnl_neigh_put(rn); |
| 11384 | return res; |
| 11385 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 11386 | return -1; |
| 11387 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 11388 | } |
| 11389 | |
| 11390 | |
| 11391 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 11392 | const u8 *ipaddr) |
| 11393 | { |
| 11394 | #ifdef CONFIG_LIBNL3_ROUTE |
| 11395 | struct i802_bss *bss = priv; |
| 11396 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11397 | struct rtnl_neigh *rn; |
| 11398 | struct nl_addr *nl_ipaddr; |
| 11399 | int family, addrsize; |
| 11400 | int res; |
| 11401 | |
| 11402 | if (!ipaddr) |
| 11403 | return -EINVAL; |
| 11404 | |
| 11405 | if (version == 4) { |
| 11406 | family = AF_INET; |
| 11407 | addrsize = 4; |
| 11408 | } else if (version == 6) { |
| 11409 | family = AF_INET6; |
| 11410 | addrsize = 16; |
| 11411 | } else { |
| 11412 | return -EINVAL; |
| 11413 | } |
| 11414 | |
| 11415 | if (bss->br_ifindex == 0) { |
| 11416 | wpa_printf(MSG_DEBUG, |
| 11417 | "nl80211: bridge must be set to delete an ip neigh"); |
| 11418 | return -1; |
| 11419 | } |
| 11420 | |
| 11421 | if (!drv->rtnl_sk) { |
| 11422 | wpa_printf(MSG_DEBUG, |
| 11423 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 11424 | return -1; |
| 11425 | } |
| 11426 | |
| 11427 | rn = rtnl_neigh_alloc(); |
| 11428 | if (rn == NULL) |
| 11429 | return -ENOMEM; |
| 11430 | |
| 11431 | /* set the destination ip address for neigh */ |
| 11432 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 11433 | if (nl_ipaddr == NULL) { |
| 11434 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 11435 | res = -ENOMEM; |
| 11436 | goto errout; |
| 11437 | } |
| 11438 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 11439 | if (res) { |
| 11440 | wpa_printf(MSG_DEBUG, |
| 11441 | "nl80211: neigh set destination addr failed"); |
| 11442 | goto errout; |
| 11443 | } |
| 11444 | |
| 11445 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 11446 | |
| 11447 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 11448 | if (res) { |
| 11449 | wpa_printf(MSG_DEBUG, |
| 11450 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11451 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11452 | } |
| 11453 | errout: |
| 11454 | if (nl_ipaddr) |
| 11455 | nl_addr_put(nl_ipaddr); |
| 11456 | if (rn) |
| 11457 | rtnl_neigh_put(rn); |
| 11458 | return res; |
| 11459 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 11460 | return -1; |
| 11461 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 11462 | } |
| 11463 | |
| 11464 | |
| 11465 | static int linux_write_system_file(const char *path, unsigned int val) |
| 11466 | { |
| 11467 | char buf[50]; |
| 11468 | int fd, len; |
| 11469 | |
| 11470 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 11471 | if (os_snprintf_error(sizeof(buf), len)) |
| 11472 | return -1; |
| 11473 | |
| 11474 | fd = open(path, O_WRONLY); |
| 11475 | if (fd < 0) |
| 11476 | return -1; |
| 11477 | |
| 11478 | if (write(fd, buf, len) < 0) { |
| 11479 | wpa_printf(MSG_DEBUG, |
| 11480 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 11481 | path, val); |
| 11482 | close(fd); |
| 11483 | return -1; |
| 11484 | } |
| 11485 | close(fd); |
| 11486 | |
| 11487 | return 0; |
| 11488 | } |
| 11489 | |
| 11490 | |
| 11491 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 11492 | { |
| 11493 | switch (attr) { |
| 11494 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 11495 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11496 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 11497 | return "hairpin_mode"; |
| 11498 | } |
| 11499 | |
| 11500 | return NULL; |
| 11501 | } |
| 11502 | |
| 11503 | |
| 11504 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 11505 | unsigned int val) |
| 11506 | { |
| 11507 | struct i802_bss *bss = priv; |
| 11508 | char path[128]; |
| 11509 | const char *attr_txt; |
| 11510 | |
| 11511 | attr_txt = drv_br_port_attr_str(attr); |
| 11512 | if (attr_txt == NULL) |
| 11513 | return -EINVAL; |
| 11514 | |
| 11515 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 11516 | bss->ifname, attr_txt); |
| 11517 | |
| 11518 | if (linux_write_system_file(path, val)) |
| 11519 | return -1; |
| 11520 | |
| 11521 | return 0; |
| 11522 | } |
| 11523 | |
| 11524 | |
| 11525 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 11526 | { |
| 11527 | switch (param) { |
| 11528 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11529 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11530 | default: |
| 11531 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11532 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11533 | } |
| 11534 | |
| 11535 | |
| 11536 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 11537 | unsigned int val) |
| 11538 | { |
| 11539 | struct i802_bss *bss = priv; |
| 11540 | char path[128]; |
| 11541 | const char *param_txt; |
| 11542 | int ip_version = 4; |
| 11543 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11544 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 11545 | os_snprintf(path, sizeof(path), |
| 11546 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 11547 | bss->brname); |
| 11548 | goto set_val; |
| 11549 | } |
| 11550 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11551 | param_txt = drv_br_net_param_str(param); |
| 11552 | if (param_txt == NULL) |
| 11553 | return -EINVAL; |
| 11554 | |
| 11555 | switch (param) { |
| 11556 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11557 | ip_version = 4; |
| 11558 | break; |
| 11559 | default: |
| 11560 | return -EINVAL; |
| 11561 | } |
| 11562 | |
| 11563 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 11564 | ip_version, bss->brname, param_txt); |
| 11565 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11566 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11567 | if (linux_write_system_file(path, val)) |
| 11568 | return -1; |
| 11569 | |
| 11570 | return 0; |
| 11571 | } |
| 11572 | |
| 11573 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11574 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 11575 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11576 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 11577 | { |
| 11578 | switch (hw_mode) { |
| 11579 | case HOSTAPD_MODE_IEEE80211B: |
| 11580 | return QCA_ACS_MODE_IEEE80211B; |
| 11581 | case HOSTAPD_MODE_IEEE80211G: |
| 11582 | return QCA_ACS_MODE_IEEE80211G; |
| 11583 | case HOSTAPD_MODE_IEEE80211A: |
| 11584 | return QCA_ACS_MODE_IEEE80211A; |
| 11585 | case HOSTAPD_MODE_IEEE80211AD: |
| 11586 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 11587 | case HOSTAPD_MODE_IEEE80211ANY: |
| 11588 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11589 | default: |
| 11590 | return -1; |
| 11591 | } |
| 11592 | } |
| 11593 | |
| 11594 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11595 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 11596 | { |
| 11597 | int num_channels = 0, num_freqs; |
| 11598 | u8 *ch_list; |
| 11599 | enum hostapd_hw_mode hw_mode; |
| 11600 | int ret = 0; |
| 11601 | int i; |
| 11602 | |
| 11603 | if (!freq_list) |
| 11604 | return 0; |
| 11605 | |
| 11606 | num_freqs = int_array_len(freq_list); |
| 11607 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 11608 | if (!ch_list) |
| 11609 | return -1; |
| 11610 | |
| 11611 | for (i = 0; i < num_freqs; i++) { |
| 11612 | const int freq = freq_list[i]; |
| 11613 | |
| 11614 | if (freq == 0) |
| 11615 | break; |
| 11616 | /* Send 2.4 GHz and 5 GHz channels with |
| 11617 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 11618 | * compatibility. |
| 11619 | */ |
| 11620 | if (!(freq >= 2412 && freq <= 2484) && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11621 | !(freq >= 5180 && freq <= 5900) && |
| 11622 | !(freq >= 5945 && freq <= 7115)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11623 | continue; |
| 11624 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 11625 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 11626 | num_channels++; |
| 11627 | } |
| 11628 | |
| 11629 | if (num_channels) |
| 11630 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 11631 | num_channels, ch_list); |
| 11632 | |
| 11633 | os_free(ch_list); |
| 11634 | return ret; |
| 11635 | } |
| 11636 | |
| 11637 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11638 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 11639 | { |
| 11640 | int i, len, ret; |
| 11641 | u32 *freqs; |
| 11642 | |
| 11643 | if (!freq_list) |
| 11644 | return 0; |
| 11645 | len = int_array_len(freq_list); |
| 11646 | freqs = os_malloc(sizeof(u32) * len); |
| 11647 | if (!freqs) |
| 11648 | return -1; |
| 11649 | for (i = 0; i < len; i++) |
| 11650 | freqs[i] = freq_list[i]; |
| 11651 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 11652 | sizeof(u32) * len, freqs); |
| 11653 | os_free(freqs); |
| 11654 | return ret; |
| 11655 | } |
| 11656 | |
| 11657 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11658 | static int nl80211_qca_do_acs(struct wpa_driver_nl80211_data *drv, |
| 11659 | struct drv_acs_params *params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11660 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11661 | struct nl_msg *msg; |
| 11662 | struct nlattr *data; |
| 11663 | int ret; |
| 11664 | int mode; |
| 11665 | |
| 11666 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 11667 | if (mode < 0) |
| 11668 | return -1; |
| 11669 | |
| 11670 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11671 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11672 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11673 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 11674 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11675 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 11676 | (params->ht_enabled && |
| 11677 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 11678 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11679 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 11680 | (params->vht_enabled && |
| 11681 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11682 | (params->eht_enabled && |
| 11683 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EHT_ENABLED)) || |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11684 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 11685 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11686 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11687 | add_acs_freq_list(msg, params->freq_list) || |
| 11688 | (params->edmg_enabled && |
| 11689 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11690 | nlmsg_free(msg); |
| 11691 | return -ENOBUFS; |
| 11692 | } |
| 11693 | nla_nest_end(msg, data); |
| 11694 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11695 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11696 | "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] | 11697 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 11698 | params->vht_enabled, params->eht_enabled, params->ch_width, |
| 11699 | params->edmg_enabled); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11700 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11701 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11702 | if (ret) { |
| 11703 | wpa_printf(MSG_DEBUG, |
| 11704 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11705 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11706 | } |
| 11707 | return ret; |
| 11708 | } |
| 11709 | |
| 11710 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11711 | static int nl80211_set_band(void *priv, u32 band_mask) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11712 | { |
| 11713 | struct i802_bss *bss = priv; |
| 11714 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11715 | struct nl_msg *msg; |
| 11716 | struct nlattr *data; |
| 11717 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11718 | enum qca_set_band qca_band_value; |
| 11719 | u32 qca_band_mask = QCA_SETBAND_AUTO; |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11720 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11721 | if (!drv->setband_vendor_cmd_avail || |
| 11722 | (band_mask > (WPA_SETBAND_2G | WPA_SETBAND_5G | WPA_SETBAND_6G))) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11723 | return -1; |
| 11724 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11725 | if (band_mask & WPA_SETBAND_5G) |
| 11726 | qca_band_mask |= QCA_SETBAND_5G; |
| 11727 | if (band_mask & WPA_SETBAND_2G) |
| 11728 | qca_band_mask |= QCA_SETBAND_2G; |
| 11729 | if (band_mask & WPA_SETBAND_6G) |
| 11730 | qca_band_mask |= QCA_SETBAND_6G; |
| 11731 | |
| 11732 | /* |
| 11733 | * QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE is a legacy interface hence make |
| 11734 | * it suite to its values (AUTO/5G/2G) for backwards compatibility. |
| 11735 | */ |
| 11736 | qca_band_value = ((qca_band_mask & QCA_SETBAND_5G) && |
| 11737 | (qca_band_mask & QCA_SETBAND_2G)) ? |
| 11738 | QCA_SETBAND_AUTO : |
| 11739 | qca_band_mask & ~QCA_SETBAND_6G; |
| 11740 | |
| 11741 | wpa_printf(MSG_DEBUG, |
| 11742 | "nl80211: QCA_BAND_MASK = 0x%x, QCA_BAND_VALUE = %d", |
| 11743 | qca_band_mask, qca_band_value); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11744 | |
| 11745 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11746 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11747 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11748 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 11749 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11750 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, |
| 11751 | qca_band_value) || |
| 11752 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_MASK, |
| 11753 | qca_band_mask)) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11754 | nlmsg_free(msg); |
| 11755 | return -ENOBUFS; |
| 11756 | } |
| 11757 | nla_nest_end(msg, data); |
| 11758 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11759 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11760 | if (ret) { |
| 11761 | wpa_printf(MSG_DEBUG, |
| 11762 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11763 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11764 | } |
| 11765 | return ret; |
| 11766 | } |
| 11767 | |
| 11768 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11769 | struct nl80211_pcl { |
| 11770 | unsigned int num; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11771 | struct weighted_pcl *freq_list; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11772 | }; |
| 11773 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11774 | static void get_pcl_attr_values(struct weighted_pcl *wpcl, struct nlattr *nl[]) |
| 11775 | { |
| 11776 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]) |
| 11777 | wpcl->freq = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FREQ]); |
| 11778 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]) |
| 11779 | wpcl->weight = nla_get_u8(nl[QCA_WLAN_VENDOR_ATTR_PCL_WEIGHT]); |
| 11780 | if (nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]) { |
| 11781 | u32 flags = nla_get_u32(nl[QCA_WLAN_VENDOR_ATTR_PCL_FLAG]); |
| 11782 | |
| 11783 | wpcl->flag = 0; |
| 11784 | if (flags & BIT(0)) |
| 11785 | wpcl->flag |= WEIGHTED_PCL_GO; |
| 11786 | if (flags & BIT(1)) |
| 11787 | wpcl->flag |= WEIGHTED_PCL_CLI; |
| 11788 | if (flags & BIT(2)) |
| 11789 | wpcl->flag |= WEIGHTED_PCL_MUST_CONSIDER; |
| 11790 | if (flags & BIT(3)) |
| 11791 | wpcl->flag |= WEIGHTED_PCL_EXCLUDE; |
| 11792 | } else { |
| 11793 | wpcl->flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 11794 | } |
| 11795 | } |
| 11796 | |
| 11797 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11798 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 11799 | { |
| 11800 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11801 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11802 | struct nl80211_pcl *param = arg; |
| 11803 | struct nlattr *nl_vend, *attr; |
| 11804 | enum qca_iface_type iface_type; |
| 11805 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11806 | struct nlattr *nl_pcl[QCA_WLAN_VENDOR_ATTR_PCL_MAX + 1]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11807 | unsigned int num, max_num; |
| 11808 | u32 *freqs; |
| 11809 | |
| 11810 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11811 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11812 | |
| 11813 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 11814 | if (!nl_vend) |
| 11815 | return NL_SKIP; |
| 11816 | |
| 11817 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 11818 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 11819 | |
| 11820 | attr = tb_vendor[ |
| 11821 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 11822 | if (!attr) { |
| 11823 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 11824 | param->num = 0; |
| 11825 | return NL_SKIP; |
| 11826 | } |
| 11827 | |
| 11828 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 11829 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 11830 | iface_type); |
| 11831 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11832 | attr = tb_vendor[ |
| 11833 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_WEIGHED_PCL]; |
| 11834 | if (attr) { |
| 11835 | int rem; |
| 11836 | struct nlattr *wpcl = attr; |
| 11837 | unsigned int i; |
| 11838 | |
| 11839 | num = 0; |
| 11840 | nla_for_each_nested(attr, wpcl, rem) { |
| 11841 | if (num == param->num) |
| 11842 | break; /* not enough room for all entries */ |
| 11843 | if (nla_parse(nl_pcl, QCA_WLAN_VENDOR_ATTR_PCL_MAX, |
| 11844 | nla_data(attr), nla_len(attr), NULL)) { |
| 11845 | wpa_printf(MSG_ERROR, |
| 11846 | "nl80211: Failed to parse PCL info"); |
| 11847 | param->num = 0; |
| 11848 | return NL_SKIP; |
| 11849 | } |
| 11850 | get_pcl_attr_values(¶m->freq_list[num], nl_pcl); |
| 11851 | num++; |
| 11852 | } |
| 11853 | param->num = num; |
| 11854 | |
| 11855 | /* Sort frequencies based on their weight */ |
| 11856 | for (i = 0; i < num; i++) { |
| 11857 | unsigned int j; |
| 11858 | |
| 11859 | for (j = i + 1; j < num; j++) { |
| 11860 | if (param->freq_list[i].weight < |
| 11861 | param->freq_list[j].weight) { |
| 11862 | struct weighted_pcl tmp; |
| 11863 | |
| 11864 | tmp = param->freq_list[i]; |
| 11865 | param->freq_list[i] = |
| 11866 | param->freq_list[j]; |
| 11867 | param->freq_list[j] = tmp; |
| 11868 | } |
| 11869 | } |
| 11870 | } |
| 11871 | } else if (tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]) { |
| 11872 | wpa_printf(MSG_DEBUG, |
| 11873 | "nl80211: Driver does not provide weighted PCL; use the non-weighted variant"); |
| 11874 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 11875 | /* |
| 11876 | * param->num has the maximum number of entries for which there |
| 11877 | * is room in the freq_list provided by the caller. |
| 11878 | */ |
| 11879 | freqs = nla_data(attr); |
| 11880 | max_num = nla_len(attr) / sizeof(u32); |
| 11881 | if (max_num > param->num) |
| 11882 | max_num = param->num; |
| 11883 | for (num = 0; num < max_num; num++) { |
| 11884 | param->freq_list[num].freq = freqs[num]; |
| 11885 | param->freq_list[num].flag = |
| 11886 | WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
| 11887 | } |
| 11888 | param->num = num; |
| 11889 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11890 | wpa_printf(MSG_ERROR, |
| 11891 | "nl80211: preferred_freq_list couldn't be found"); |
| 11892 | param->num = 0; |
| 11893 | return NL_SKIP; |
| 11894 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11895 | return NL_SKIP; |
| 11896 | } |
| 11897 | |
| 11898 | |
| 11899 | static int nl80211_get_pref_freq_list(void *priv, |
| 11900 | enum wpa_driver_if_type if_type, |
| 11901 | unsigned int *num, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11902 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11903 | { |
| 11904 | struct i802_bss *bss = priv; |
| 11905 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11906 | struct nl_msg *msg; |
| 11907 | int ret; |
| 11908 | unsigned int i; |
| 11909 | struct nlattr *params; |
| 11910 | struct nl80211_pcl param; |
| 11911 | enum qca_iface_type iface_type; |
| 11912 | |
| 11913 | if (!drv->get_pref_freq_list) |
| 11914 | return -1; |
| 11915 | |
| 11916 | switch (if_type) { |
| 11917 | case WPA_IF_STATION: |
| 11918 | iface_type = QCA_IFACE_TYPE_STA; |
| 11919 | break; |
| 11920 | case WPA_IF_AP_BSS: |
| 11921 | iface_type = QCA_IFACE_TYPE_AP; |
| 11922 | break; |
| 11923 | case WPA_IF_P2P_GO: |
| 11924 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 11925 | break; |
| 11926 | case WPA_IF_P2P_CLIENT: |
| 11927 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 11928 | break; |
| 11929 | case WPA_IF_IBSS: |
| 11930 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 11931 | break; |
| 11932 | case WPA_IF_TDLS: |
| 11933 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 11934 | break; |
| 11935 | default: |
| 11936 | return -1; |
| 11937 | } |
| 11938 | |
| 11939 | param.num = *num; |
| 11940 | param.freq_list = freq_list; |
| 11941 | |
| 11942 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11943 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 11944 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11945 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11946 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 11947 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11948 | nla_put_u32(msg, |
| 11949 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 11950 | iface_type)) { |
| 11951 | wpa_printf(MSG_ERROR, |
| 11952 | "%s: err in adding vendor_cmd and vendor_data", |
| 11953 | __func__); |
| 11954 | nlmsg_free(msg); |
| 11955 | return -1; |
| 11956 | } |
| 11957 | nla_nest_end(msg, params); |
| 11958 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11959 | if (freq_list) |
| 11960 | os_memset(freq_list, 0, *num * sizeof(struct weighted_pcl)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11961 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m, |
| 11962 | NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11963 | if (ret) { |
| 11964 | wpa_printf(MSG_ERROR, |
| 11965 | "%s: err in send_and_recv_msgs", __func__); |
| 11966 | return ret; |
| 11967 | } |
| 11968 | |
| 11969 | *num = param.num; |
| 11970 | |
| 11971 | for (i = 0; i < *num; i++) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 11972 | wpa_printf(MSG_DEBUG, |
| 11973 | "nl80211: preferred_channel_list[%d]=%d[%d]:0x%x", |
| 11974 | i, freq_list[i].freq, freq_list[i].weight, |
| 11975 | freq_list[i].flag); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11976 | } |
| 11977 | |
| 11978 | return 0; |
| 11979 | } |
| 11980 | |
| 11981 | |
| 11982 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 11983 | { |
| 11984 | struct i802_bss *bss = priv; |
| 11985 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11986 | struct nl_msg *msg; |
| 11987 | int ret; |
| 11988 | struct nlattr *params; |
| 11989 | |
| 11990 | if (!drv->set_prob_oper_freq) |
| 11991 | return -1; |
| 11992 | |
| 11993 | wpa_printf(MSG_DEBUG, |
| 11994 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 11995 | freq, bss->ifindex); |
| 11996 | |
| 11997 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11998 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11999 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12000 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 12001 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12002 | nla_put_u32(msg, |
| 12003 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 12004 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 12005 | nla_put_u32(msg, |
| 12006 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 12007 | freq)) { |
| 12008 | wpa_printf(MSG_ERROR, |
| 12009 | "%s: err in adding vendor_cmd and vendor_data", |
| 12010 | __func__); |
| 12011 | nlmsg_free(msg); |
| 12012 | return -1; |
| 12013 | } |
| 12014 | nla_nest_end(msg, params); |
| 12015 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12016 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12017 | msg = NULL; |
| 12018 | if (ret) { |
| 12019 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 12020 | __func__); |
| 12021 | return ret; |
| 12022 | } |
| 12023 | nlmsg_free(msg); |
| 12024 | return 0; |
| 12025 | } |
| 12026 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12027 | |
| 12028 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 12029 | unsigned int period, unsigned int interval, |
| 12030 | unsigned int count, const u8 *device_types, |
| 12031 | size_t dev_types_len, |
| 12032 | const u8 *ies, size_t ies_len) |
| 12033 | { |
| 12034 | struct i802_bss *bss = priv; |
| 12035 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12036 | struct nl_msg *msg; |
| 12037 | struct nlattr *container; |
| 12038 | int ret; |
| 12039 | |
| 12040 | wpa_printf(MSG_DEBUG, |
| 12041 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 12042 | freq, period, interval, count); |
| 12043 | |
| 12044 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 12045 | return -1; |
| 12046 | |
| 12047 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12048 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12049 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12050 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 12051 | goto fail; |
| 12052 | |
| 12053 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12054 | if (!container) |
| 12055 | goto fail; |
| 12056 | |
| 12057 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 12058 | freq) || |
| 12059 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 12060 | period) || |
| 12061 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 12062 | interval) || |
| 12063 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 12064 | count) || |
| 12065 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 12066 | dev_types_len, device_types) || |
| 12067 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 12068 | ies_len, ies)) |
| 12069 | goto fail; |
| 12070 | |
| 12071 | nla_nest_end(msg, container); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12072 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12073 | msg = NULL; |
| 12074 | if (ret) { |
| 12075 | wpa_printf(MSG_DEBUG, |
| 12076 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 12077 | goto fail; |
| 12078 | } |
| 12079 | |
| 12080 | return 0; |
| 12081 | |
| 12082 | fail: |
| 12083 | nlmsg_free(msg); |
| 12084 | return -1; |
| 12085 | } |
| 12086 | |
| 12087 | |
| 12088 | static int nl80211_p2p_lo_stop(void *priv) |
| 12089 | { |
| 12090 | struct i802_bss *bss = priv; |
| 12091 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12092 | struct nl_msg *msg; |
| 12093 | |
| 12094 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 12095 | |
| 12096 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 12097 | return -1; |
| 12098 | |
| 12099 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12100 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12101 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12102 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 12103 | nlmsg_free(msg); |
| 12104 | return -1; |
| 12105 | } |
| 12106 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12107 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12108 | } |
| 12109 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 12110 | |
| 12111 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 12112 | { |
| 12113 | struct i802_bss *bss = priv; |
| 12114 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12115 | struct nl_msg *msg; |
| 12116 | struct nlattr *params; |
| 12117 | int ret; |
| 12118 | u32 tdls_mode; |
| 12119 | |
| 12120 | wpa_printf(MSG_DEBUG, |
| 12121 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 12122 | tdls_external_control); |
| 12123 | |
| 12124 | if (tdls_external_control == 1) |
| 12125 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 12126 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 12127 | else |
| 12128 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 12129 | |
| 12130 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12131 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12132 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12133 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 12134 | goto fail; |
| 12135 | |
| 12136 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12137 | if (!params) |
| 12138 | goto fail; |
| 12139 | |
| 12140 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 12141 | tdls_mode)) |
| 12142 | goto fail; |
| 12143 | |
| 12144 | nla_nest_end(msg, params); |
| 12145 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12146 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 12147 | msg = NULL; |
| 12148 | if (ret) { |
| 12149 | wpa_printf(MSG_ERROR, |
| 12150 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 12151 | ret, strerror(-ret)); |
| 12152 | goto fail; |
| 12153 | } |
| 12154 | return 0; |
| 12155 | fail: |
| 12156 | nlmsg_free(msg); |
| 12157 | return -1; |
| 12158 | } |
| 12159 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12160 | |
| 12161 | #ifdef CONFIG_MBO |
| 12162 | |
| 12163 | static enum mbo_transition_reject_reason |
| 12164 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 12165 | { |
| 12166 | switch (status) { |
| 12167 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 12168 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 12169 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 12170 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 12171 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 12172 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 12173 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 12174 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 12175 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 12176 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 12177 | case QCA_STATUS_REJECT_UNKNOWN: |
| 12178 | default: |
| 12179 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 12180 | } |
| 12181 | } |
| 12182 | |
| 12183 | |
| 12184 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 12185 | struct nlattr *tb[], int num) |
| 12186 | { |
| 12187 | enum qca_wlan_btm_candidate_status status; |
| 12188 | char buf[50]; |
| 12189 | |
| 12190 | os_memcpy(candidate->bssid, |
| 12191 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 12192 | ETH_ALEN); |
| 12193 | |
| 12194 | status = nla_get_u32( |
| 12195 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 12196 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 12197 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 12198 | |
| 12199 | if (candidate->is_accept) |
| 12200 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 12201 | else |
| 12202 | os_snprintf(buf, sizeof(buf), |
| 12203 | "Rejected, Reject_reason: %d", |
| 12204 | candidate->reject_reason); |
| 12205 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 12206 | num, MAC2STR(candidate->bssid), buf); |
| 12207 | } |
| 12208 | |
| 12209 | |
| 12210 | static int |
| 12211 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 12212 | { |
| 12213 | struct wpa_bss_candidate_info *info = arg; |
| 12214 | struct candidate_list *candidate = info->candidates; |
| 12215 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 12216 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 12217 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 12218 | static struct nla_policy policy[ |
| 12219 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 12220 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 12221 | .minlen = ETH_ALEN |
| 12222 | }, |
| 12223 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 12224 | .type = NLA_U32, |
| 12225 | }, |
| 12226 | }; |
| 12227 | struct nlattr *attr; |
| 12228 | int rem; |
| 12229 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 12230 | u8 num; |
| 12231 | |
| 12232 | num = info->num; /* number of candidates sent to driver */ |
| 12233 | info->num = 0; |
| 12234 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 12235 | genlmsg_attrlen(gnlh, 0), NULL); |
| 12236 | |
| 12237 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 12238 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 12239 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 12240 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 12241 | return NL_SKIP; |
| 12242 | |
| 12243 | wpa_printf(MSG_DEBUG, |
| 12244 | "nl80211: WNM Candidate list received from driver"); |
| 12245 | nla_for_each_nested(attr, |
| 12246 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 12247 | rem) { |
| 12248 | if (info->num >= num || |
| 12249 | nla_parse_nested( |
| 12250 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 12251 | attr, policy) || |
| 12252 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 12253 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 12254 | break; |
| 12255 | |
| 12256 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 12257 | |
| 12258 | candidate++; |
| 12259 | info->num++; |
| 12260 | } |
| 12261 | |
| 12262 | return NL_SKIP; |
| 12263 | } |
| 12264 | |
| 12265 | |
| 12266 | static struct wpa_bss_candidate_info * |
| 12267 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 12268 | { |
| 12269 | struct i802_bss *bss = priv; |
| 12270 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12271 | struct nl_msg *msg; |
| 12272 | struct nlattr *attr, *attr1, *attr2; |
| 12273 | struct wpa_bss_candidate_info *info; |
| 12274 | u8 i; |
| 12275 | int ret; |
| 12276 | u8 *pos; |
| 12277 | |
| 12278 | if (!drv->fetch_bss_trans_status) |
| 12279 | return NULL; |
| 12280 | |
| 12281 | info = os_zalloc(sizeof(*info)); |
| 12282 | if (!info) |
| 12283 | return NULL; |
| 12284 | /* Allocate memory for number of candidates sent to driver */ |
| 12285 | info->candidates = os_calloc(params->n_candidates, |
| 12286 | sizeof(*info->candidates)); |
| 12287 | if (!info->candidates) { |
| 12288 | os_free(info); |
| 12289 | return NULL; |
| 12290 | } |
| 12291 | |
| 12292 | /* Copy the number of candidates being sent to driver. This is used in |
| 12293 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 12294 | * candidates that can be populated in info->candidates and will be |
| 12295 | * later overwritten with the actual number of candidates received from |
| 12296 | * the driver. |
| 12297 | */ |
| 12298 | info->num = params->n_candidates; |
| 12299 | |
| 12300 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12301 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12302 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12303 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 12304 | goto fail; |
| 12305 | |
| 12306 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12307 | if (!attr) |
| 12308 | goto fail; |
| 12309 | |
| 12310 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 12311 | params->mbo_transition_reason)) |
| 12312 | goto fail; |
| 12313 | |
| 12314 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 12315 | if (!attr1) |
| 12316 | goto fail; |
| 12317 | |
| 12318 | wpa_printf(MSG_DEBUG, |
| 12319 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 12320 | params->mbo_transition_reason, params->n_candidates); |
| 12321 | pos = params->bssid; |
| 12322 | for (i = 0; i < params->n_candidates; i++) { |
| 12323 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 12324 | MAC2STR(pos)); |
| 12325 | attr2 = nla_nest_start(msg, i); |
| 12326 | if (!attr2 || |
| 12327 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 12328 | ETH_ALEN, pos)) |
| 12329 | goto fail; |
| 12330 | pos += ETH_ALEN; |
| 12331 | nla_nest_end(msg, attr2); |
| 12332 | } |
| 12333 | |
| 12334 | nla_nest_end(msg, attr1); |
| 12335 | nla_nest_end(msg, attr); |
| 12336 | |
| 12337 | ret = send_and_recv_msgs(drv, msg, |
| 12338 | nl80211_get_bss_transition_status_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12339 | info, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12340 | msg = NULL; |
| 12341 | if (ret) { |
| 12342 | wpa_printf(MSG_ERROR, |
| 12343 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 12344 | ret, strerror(-ret)); |
| 12345 | goto fail; |
| 12346 | } |
| 12347 | return info; |
| 12348 | |
| 12349 | fail: |
| 12350 | nlmsg_free(msg); |
| 12351 | os_free(info->candidates); |
| 12352 | os_free(info); |
| 12353 | return NULL; |
| 12354 | } |
| 12355 | |
| 12356 | |
| 12357 | /** |
| 12358 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 12359 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 12360 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 12361 | * Returns: 0 on success, -1 on failure |
| 12362 | */ |
| 12363 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 12364 | { |
| 12365 | struct i802_bss *bss = priv; |
| 12366 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12367 | struct nl_msg *msg; |
| 12368 | struct nlattr *attr; |
| 12369 | int ret = -1; |
| 12370 | |
| 12371 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 12372 | return -1; |
| 12373 | |
| 12374 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12375 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12376 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12377 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 12378 | goto fail; |
| 12379 | |
| 12380 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12381 | if (!attr) |
| 12382 | goto fail; |
| 12383 | |
| 12384 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 12385 | ignore_disallow); |
| 12386 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 12387 | ignore_disallow)) |
| 12388 | goto fail; |
| 12389 | |
| 12390 | nla_nest_end(msg, attr); |
| 12391 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12392 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12393 | msg = NULL; |
| 12394 | if (ret) { |
| 12395 | wpa_printf(MSG_ERROR, |
| 12396 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 12397 | ret, strerror(-ret)); |
| 12398 | goto fail; |
| 12399 | } |
| 12400 | |
| 12401 | fail: |
| 12402 | nlmsg_free(msg); |
| 12403 | return ret; |
| 12404 | } |
| 12405 | |
| 12406 | #endif /* CONFIG_MBO */ |
| 12407 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 12408 | |
| 12409 | #ifdef CONFIG_PASN |
| 12410 | |
| 12411 | static int nl80211_send_pasn_resp(void *priv, struct pasn_auth *params) |
| 12412 | { |
| 12413 | unsigned int i; |
| 12414 | struct i802_bss *bss = priv; |
| 12415 | struct nl_msg *msg = NULL; |
| 12416 | struct nlattr *nlpeers, *attr, *attr1; |
| 12417 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12418 | |
| 12419 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12420 | "nl80211: PASN authentication response for %d entries", |
| 12421 | params->num_peers); |
| 12422 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 12423 | if (!msg || |
| 12424 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12425 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12426 | QCA_NL80211_VENDOR_SUBCMD_PASN)) |
| 12427 | goto fail; |
| 12428 | |
| 12429 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12430 | if (!attr) |
| 12431 | goto fail; |
| 12432 | |
| 12433 | nlpeers = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEERS); |
| 12434 | if (!nlpeers) |
| 12435 | goto fail; |
| 12436 | |
| 12437 | for (i = 0; i < params->num_peers; i++) { |
| 12438 | attr1 = nla_nest_start(msg, i); |
| 12439 | if (!attr1 || |
| 12440 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_SRC_ADDR, |
| 12441 | ETH_ALEN, params->peer[i].own_addr) || |
| 12442 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_PASN_PEER_MAC_ADDR, |
| 12443 | ETH_ALEN, params->peer[i].peer_addr)) |
| 12444 | goto fail; |
| 12445 | |
| 12446 | if (params->peer[i].status == 0) |
| 12447 | nla_put_flag(msg, |
| 12448 | QCA_WLAN_VENDOR_ATTR_PASN_PEER_STATUS_SUCCESS); |
| 12449 | |
| 12450 | wpa_printf(MSG_DEBUG, |
| 12451 | "nl80211: Own address[%u]: " MACSTR |
| 12452 | " Peer address[%u]: " MACSTR " Status: %s", |
| 12453 | i, MAC2STR(params->peer[i].own_addr), i, |
| 12454 | MAC2STR(params->peer[i].peer_addr), |
| 12455 | params->peer[i].status ? "Fail" : "Success"); |
| 12456 | nla_nest_end(msg, attr1); |
| 12457 | } |
| 12458 | |
| 12459 | nla_nest_end(msg, nlpeers); |
| 12460 | nla_nest_end(msg, attr); |
| 12461 | |
| 12462 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 12463 | |
| 12464 | fail: |
| 12465 | nlmsg_free(msg); |
| 12466 | return -1; |
| 12467 | } |
| 12468 | |
| 12469 | |
| 12470 | static u32 wpa_ltf_keyseed_len_to_sha_type(size_t len) |
| 12471 | { |
| 12472 | if (len == SHA384_MAC_LEN) |
| 12473 | return QCA_WLAN_VENDOR_SHA_384; |
| 12474 | if (len == SHA256_MAC_LEN) |
| 12475 | return QCA_WLAN_VENDOR_SHA_256; |
| 12476 | |
| 12477 | wpa_printf(MSG_ERROR, "nl80211: Unexpected LTF keyseed len %zu", len); |
| 12478 | return (u32) -1; |
| 12479 | } |
| 12480 | |
| 12481 | |
| 12482 | static int nl80211_set_secure_ranging_ctx(void *priv, |
| 12483 | struct secure_ranging_params *params) |
| 12484 | { |
| 12485 | int ret; |
| 12486 | u32 suite; |
| 12487 | struct nlattr *attr; |
| 12488 | struct nl_msg *msg = NULL; |
| 12489 | struct i802_bss *bss = priv; |
| 12490 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12491 | |
| 12492 | /* Configure secure ranging context only to the drivers that support it. |
| 12493 | */ |
| 12494 | if (!drv->secure_ranging_ctx_vendor_cmd_avail) |
| 12495 | return 0; |
| 12496 | |
| 12497 | if (!params->peer_addr || !params->own_addr) |
| 12498 | return -1; |
| 12499 | |
| 12500 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12501 | "nl80211: Secure ranging context for " MACSTR, |
| 12502 | MAC2STR(params->peer_addr)); |
| 12503 | |
| 12504 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 12505 | if (!msg || |
| 12506 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 12507 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 12508 | QCA_NL80211_VENDOR_SUBCMD_SECURE_RANGING_CONTEXT)) |
| 12509 | goto fail; |
| 12510 | |
| 12511 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 12512 | if (!attr) |
| 12513 | goto fail; |
| 12514 | |
| 12515 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_PEER_MAC_ADDR, |
| 12516 | ETH_ALEN, params->peer_addr) || |
| 12517 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SRC_ADDR, |
| 12518 | ETH_ALEN, params->own_addr) || |
| 12519 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_ACTION, |
| 12520 | params->action)) |
| 12521 | goto fail; |
| 12522 | |
| 12523 | if (params->cipher) { |
| 12524 | suite = wpa_cipher_to_cipher_suite(params->cipher); |
| 12525 | if (!suite || |
| 12526 | nla_put_u32(msg, |
| 12527 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_CIPHER, |
| 12528 | suite)) |
| 12529 | goto fail; |
| 12530 | } |
| 12531 | |
| 12532 | if (params->tk_len && params->tk) { |
| 12533 | if (nla_put(msg, QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_TK, |
| 12534 | params->tk_len, params->tk)) |
| 12535 | goto fail; |
| 12536 | wpa_hexdump_key(MSG_DEBUG, "nl80211: TK", |
| 12537 | params->tk, params->tk_len); |
| 12538 | } |
| 12539 | |
| 12540 | if (params->ltf_keyseed_len && params->ltf_keyseed) { |
| 12541 | u32 sha_type = wpa_ltf_keyseed_len_to_sha_type( |
| 12542 | params->ltf_keyseed_len); |
| 12543 | |
| 12544 | if (sha_type == (u32) -1 || |
| 12545 | nla_put_u32( |
| 12546 | msg, |
| 12547 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_SHA_TYPE, |
| 12548 | sha_type) || |
| 12549 | nla_put(msg, |
| 12550 | QCA_WLAN_VENDOR_ATTR_SECURE_RANGING_CTX_LTF_KEYSEED, |
| 12551 | params->ltf_keyseed_len, params->ltf_keyseed)) |
| 12552 | goto fail; |
| 12553 | wpa_hexdump_key(MSG_DEBUG, "nl80211: LTF keyseed", |
| 12554 | params->ltf_keyseed, params->ltf_keyseed_len); |
| 12555 | } |
| 12556 | nla_nest_end(msg, attr); |
| 12557 | |
| 12558 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 12559 | if (ret) |
| 12560 | wpa_printf(MSG_DEBUG, |
| 12561 | "nl80211: Set secure ranging context failed: ret=%d (%s)", |
| 12562 | ret, strerror(-ret)); |
| 12563 | return ret; |
| 12564 | fail: |
| 12565 | nlmsg_free(msg); |
| 12566 | return -1; |
| 12567 | } |
| 12568 | |
| 12569 | #endif /* CONFIG_PASN */ |
| 12570 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12571 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 12572 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12573 | static int nl80211_do_acs(void *priv, struct drv_acs_params *params) |
| 12574 | { |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12575 | #if defined(CONFIG_DRIVER_NL80211_QCA) || defined(CONFIG_DRIVER_NL80211_BRCM) \ |
| 12576 | || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12577 | struct i802_bss *bss = priv; |
| 12578 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12579 | #endif /* CONFIG_DRIVER_NL80211_QCA || CONFIG_DRIVER_NL80211_BRCM \ |
| 12580 | || defined(CONFIG_DRIVER_NL80211_SYNA) */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12581 | |
| 12582 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 12583 | if (drv->qca_do_acs) |
| 12584 | return nl80211_qca_do_acs(drv, params); |
| 12585 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 12586 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12587 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12588 | if (drv->brcm_do_acs) |
| 12589 | return wpa_driver_do_broadcom_acs(drv, params); |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 12590 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12591 | |
| 12592 | return -1; |
| 12593 | } |
| 12594 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12595 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12596 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 12597 | { |
| 12598 | int fd, len; |
| 12599 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12600 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12601 | |
| 12602 | fd = open(name, O_RDWR); |
| 12603 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12604 | int level; |
| 12605 | /* |
| 12606 | * Flags may not exist on older kernels, or while we're tearing |
| 12607 | * down a disappearing device. |
| 12608 | */ |
| 12609 | if (errno == ENOENT) { |
| 12610 | ret = 0; |
| 12611 | level = MSG_DEBUG; |
| 12612 | } else { |
| 12613 | ret = -1; |
| 12614 | level = MSG_ERROR; |
| 12615 | } |
| 12616 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12617 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12618 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12619 | } |
| 12620 | |
| 12621 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 12622 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12623 | if (len < 0) { |
| 12624 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12625 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 12626 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12627 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12628 | close(fd); |
| 12629 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12630 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12631 | } |
| 12632 | |
| 12633 | |
| 12634 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 12635 | { |
| 12636 | struct i802_bss *bss = priv; |
| 12637 | char path[128]; |
| 12638 | int ret; |
| 12639 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12640 | /* P2P-Device has no netdev that can (or should) be configured here */ |
| 12641 | if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE) |
| 12642 | return 0; |
| 12643 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12644 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 12645 | filter_flags); |
| 12646 | |
| 12647 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 12648 | ret = os_snprintf(path, sizeof(path), |
| 12649 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 12650 | bss->ifname); |
| 12651 | if (os_snprintf_error(sizeof(path), ret)) |
| 12652 | return -1; |
| 12653 | |
| 12654 | ret = nl80211_write_to_file(path, |
| 12655 | !!(filter_flags & |
| 12656 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 12657 | if (ret) { |
| 12658 | wpa_printf(MSG_ERROR, |
| 12659 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 12660 | return ret; |
| 12661 | } |
| 12662 | |
| 12663 | os_snprintf(path, sizeof(path), |
| 12664 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 12665 | bss->ifname); |
| 12666 | ret = nl80211_write_to_file(path, |
| 12667 | !!(filter_flags & |
| 12668 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 12669 | |
| 12670 | if (ret) { |
| 12671 | wpa_printf(MSG_ERROR, |
| 12672 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 12673 | return ret; |
| 12674 | } |
| 12675 | |
| 12676 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 12677 | os_snprintf(path, sizeof(path), |
| 12678 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 12679 | bss->ifname); |
| 12680 | ret = nl80211_write_to_file(path, |
| 12681 | !!(filter_flags & |
| 12682 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 12683 | if (ret) { |
| 12684 | wpa_printf(MSG_ERROR, |
| 12685 | "nl80211: Failed set gratuitous ARP filter"); |
| 12686 | return ret; |
| 12687 | } |
| 12688 | |
| 12689 | /* Configure filtering of IPv6 NA frames */ |
| 12690 | os_snprintf(path, sizeof(path), |
| 12691 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 12692 | bss->ifname); |
| 12693 | ret = nl80211_write_to_file(path, |
| 12694 | !!(filter_flags & |
| 12695 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 12696 | if (ret) { |
| 12697 | wpa_printf(MSG_ERROR, |
| 12698 | "nl80211: Failed to set unsolicited NA filter"); |
| 12699 | return ret; |
| 12700 | } |
| 12701 | |
| 12702 | return 0; |
| 12703 | } |
| 12704 | |
| 12705 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 12706 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 12707 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 12708 | unsigned int *ext_capa_len) |
| 12709 | { |
| 12710 | struct i802_bss *bss = priv; |
| 12711 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12712 | enum nl80211_iftype nlmode; |
| 12713 | unsigned int i; |
| 12714 | |
| 12715 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 12716 | return -1; |
| 12717 | |
| 12718 | nlmode = wpa_driver_nl80211_if_type(type); |
| 12719 | |
| 12720 | /* By default, use the per-radio values */ |
| 12721 | *ext_capa = drv->extended_capa; |
| 12722 | *ext_capa_mask = drv->extended_capa_mask; |
| 12723 | *ext_capa_len = drv->extended_capa_len; |
| 12724 | |
| 12725 | /* Replace the default value if a per-interface type value exists */ |
| 12726 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 12727 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 12728 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 12729 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 12730 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 12731 | break; |
| 12732 | } |
| 12733 | } |
| 12734 | |
| 12735 | return 0; |
| 12736 | } |
| 12737 | |
| 12738 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12739 | static int nl80211_update_connection_params( |
| 12740 | void *priv, struct wpa_driver_associate_params *params, |
| 12741 | enum wpa_drv_update_connect_params_mask mask) |
| 12742 | { |
| 12743 | struct i802_bss *bss = priv; |
| 12744 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12745 | struct nl_msg *msg; |
| 12746 | int ret = -1; |
| 12747 | enum nl80211_auth_type type; |
| 12748 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12749 | /* Update Connection Params is intended for drivers that implement |
| 12750 | * internal SME and expect these updated connection params from |
| 12751 | * wpa_supplicant. Do not send this request for the drivers using |
| 12752 | * SME from wpa_supplicant. |
| 12753 | */ |
| 12754 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 12755 | return 0; |
| 12756 | |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 12757 | /* 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^] | 12758 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 12759 | if (mask & WPA_DRV_UPDATE_TD_POLICY) { |
| 12760 | ret = nl80211_set_td_policy(priv, params->td_policy); |
| 12761 | if (ret) { |
| 12762 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12763 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 12764 | ret, strerror(-ret)); |
| 12765 | } |
| 12766 | return ret; |
| 12767 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 12768 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 12769 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12770 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 12771 | if (!msg) |
| 12772 | goto fail; |
| 12773 | |
| 12774 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 12775 | drv->ifindex); |
| 12776 | |
| 12777 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 12778 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 12779 | params->wpa_ie)) |
| 12780 | goto fail; |
| 12781 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 12782 | params->wpa_ie_len); |
| 12783 | } |
| 12784 | |
| 12785 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 12786 | type = get_nl_auth_type(params->auth_alg); |
| 12787 | if (type == NL80211_AUTHTYPE_MAX || |
| 12788 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 12789 | goto fail; |
| 12790 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 12791 | } |
| 12792 | |
| 12793 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 12794 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 12795 | goto fail; |
| 12796 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12797 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12798 | msg = NULL; |
| 12799 | if (ret) |
| 12800 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12801 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 12802 | ret, strerror(-ret)); |
| 12803 | |
| 12804 | fail: |
| 12805 | nlmsg_free(msg); |
| 12806 | return ret; |
| 12807 | } |
| 12808 | |
| 12809 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12810 | static int nl80211_send_external_auth_status(void *priv, |
| 12811 | struct external_auth *params) |
| 12812 | { |
| 12813 | struct i802_bss *bss = priv; |
| 12814 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12815 | struct nl_msg *msg = NULL; |
| 12816 | int ret = -1; |
| 12817 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12818 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12819 | * internal SME but want to offload authentication processing (e.g., |
| 12820 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12821 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 12822 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12823 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12824 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 12825 | return -1; |
| 12826 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12827 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12828 | "nl80211: External auth status: %u", params->status); |
| 12829 | |
| 12830 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 12831 | if (!msg || |
| 12832 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12833 | (params->ssid && params->ssid_len && |
| 12834 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 12835 | (params->pmkid && |
| 12836 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 12837 | (params->bssid && |
| 12838 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12839 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12840 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12841 | msg = NULL; |
| 12842 | if (ret) { |
| 12843 | wpa_printf(MSG_DEBUG, |
| 12844 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 12845 | ret, strerror(-ret)); |
| 12846 | goto fail; |
| 12847 | } |
| 12848 | fail: |
| 12849 | nlmsg_free(msg); |
| 12850 | return ret; |
| 12851 | } |
| 12852 | |
| 12853 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12854 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 12855 | int val) |
| 12856 | { |
| 12857 | struct i802_bss *bss = priv; |
| 12858 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12859 | struct nl_msg *msg; |
| 12860 | int ret = -ENOBUFS; |
| 12861 | |
| 12862 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 12863 | val ? "Enable" : "Disable", bridge_ifname); |
| 12864 | |
| 12865 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 12866 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 12867 | goto fail; |
| 12868 | |
| 12869 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 12870 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 12871 | bridge_ifname, bss->ifname)) { |
| 12872 | wpa_printf(MSG_ERROR, |
| 12873 | "nl80211: Failed to remove interface %s from bridge %s", |
| 12874 | bss->ifname, bridge_ifname); |
| 12875 | return -1; |
| 12876 | } |
| 12877 | bss->added_if_into_bridge = 0; |
| 12878 | } |
| 12879 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12880 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12881 | msg = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12882 | if (ret && val && nl80211_get_4addr(bss) == 1) { |
| 12883 | wpa_printf(MSG_DEBUG, |
| 12884 | "nl80211: 4addr mode was already enabled"); |
| 12885 | ret = 0; |
| 12886 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12887 | if (!ret) { |
| 12888 | if (bridge_ifname[0] && val && |
| 12889 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 12890 | return -1; |
| 12891 | return 0; |
| 12892 | } |
| 12893 | |
| 12894 | fail: |
| 12895 | nlmsg_free(msg); |
| 12896 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 12897 | |
| 12898 | return ret; |
| 12899 | } |
| 12900 | |
| 12901 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 12902 | #ifdef CONFIG_DPP |
| 12903 | static int nl80211_dpp_listen(void *priv, bool enable) |
| 12904 | { |
| 12905 | struct i802_bss *bss = priv; |
| 12906 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12907 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
| 12908 | struct nl_sock *handle; |
| 12909 | |
| 12910 | if (!drv->multicast_registrations || !bss->nl_mgmt) |
| 12911 | return 0; /* cannot do more than hope broadcast RX works */ |
| 12912 | |
| 12913 | wpa_printf(MSG_DEBUG, |
| 12914 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", |
| 12915 | enable ? "enable" : "disable"); |
| 12916 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 12917 | return nl80211_register_frame(bss, handle, type, |
| 12918 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, |
| 12919 | enable); |
| 12920 | } |
| 12921 | #endif /* CONFIG_DPP */ |
| 12922 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 12923 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame] | 12924 | static int nl80211_set_td_policy(void *priv, u32 td_policy) |
| 12925 | { |
| 12926 | struct i802_bss *bss = priv; |
| 12927 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12928 | struct nl_msg *msg; |
| 12929 | int ret; |
| 12930 | struct nlattr *params; |
| 12931 | |
| 12932 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12933 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 12934 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_SET_TD_POLICY) || |
| 12935 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12936 | (nla_put_u32(msg, BRCM_ATTR_DRIVER_TD_POLICY, td_policy))) { |
| 12937 | nl80211_nlmsg_clear(msg); |
| 12938 | nlmsg_free(msg); |
| 12939 | return -ENOBUFS; |
| 12940 | } |
| 12941 | nla_nest_end(msg, params); |
| 12942 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable Policy %d\n", td_policy); |
| 12943 | |
| 12944 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 12945 | if (ret) { |
| 12946 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable setting failed: ret=%d (%s)", |
| 12947 | ret, strerror(-ret)); |
| 12948 | } |
| 12949 | |
| 12950 | return ret; |
| 12951 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame^] | 12952 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 12953 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12954 | #ifdef CONFIG_TESTING_OPTIONS |
| 12955 | |
| 12956 | static int testing_nl80211_register_frame(void *priv, u16 type, |
| 12957 | const u8 *match, size_t match_len, |
| 12958 | bool multicast) |
| 12959 | { |
| 12960 | struct i802_bss *bss = priv; |
| 12961 | struct nl_sock *handle; |
| 12962 | |
| 12963 | if (!bss->nl_mgmt) |
| 12964 | return -1; |
| 12965 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 12966 | return nl80211_register_frame(bss, handle, type, match, match_len, |
| 12967 | multicast); |
| 12968 | } |
| 12969 | |
| 12970 | |
| 12971 | static int testing_nl80211_radio_disable(void *priv, int disabled) |
| 12972 | { |
| 12973 | struct i802_bss *bss = priv; |
| 12974 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12975 | |
| 12976 | /* For now, this is supported only partially in station mode with |
| 12977 | * SME-in-wpa_supplicant case where the NL80211_ATTR_LOCAL_STATE_CHANGE |
| 12978 | * attribute can be used to avoid sending out the Deauthentication frame |
| 12979 | * to the currently associated AP. */ |
| 12980 | |
| 12981 | if (!disabled) |
| 12982 | return 0; |
| 12983 | |
| 12984 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 12985 | return -1; |
| 12986 | |
| 12987 | if (!drv->associated) |
| 12988 | return 0; |
| 12989 | |
| 12990 | return wpa_driver_nl80211_mlme(drv, drv->bssid, |
| 12991 | NL80211_CMD_DEAUTHENTICATE, |
| 12992 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1, |
| 12993 | drv->first_bss); |
| 12994 | } |
| 12995 | |
| 12996 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 12997 | |
| 12998 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12999 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 13000 | .name = "nl80211", |
| 13001 | .desc = "Linux nl80211/cfg80211", |
| 13002 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 13003 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13004 | .set_key = driver_nl80211_set_key, |
| 13005 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13006 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 13007 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13008 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 13009 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13010 | .deauthenticate = driver_nl80211_deauthenticate, |
| 13011 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13012 | .associate = wpa_driver_nl80211_associate, |
| 13013 | .global_init = nl80211_global_init, |
| 13014 | .global_deinit = nl80211_global_deinit, |
| 13015 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13016 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13017 | .get_capa = wpa_driver_nl80211_get_capa, |
| 13018 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 13019 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 13020 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 13021 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13022 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 13023 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13024 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13025 | .if_remove = driver_nl80211_if_remove, |
| 13026 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13027 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13028 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13029 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 13030 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13031 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 13032 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13033 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13034 | .hapd_init = i802_init, |
| 13035 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 13036 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13037 | .get_seqnum = i802_get_seqnum, |
| 13038 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13039 | .get_inact_sec = i802_get_inact_sec, |
| 13040 | .sta_clear_stats = i802_sta_clear_stats, |
| 13041 | .set_rts = i802_set_rts, |
| 13042 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13043 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13044 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13045 | .sta_deauth = i802_sta_deauth, |
| 13046 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13047 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13048 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13049 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13050 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 13051 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 13052 | .cancel_remain_on_channel = |
| 13053 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 13054 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13055 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 13056 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13057 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13058 | .signal_monitor = nl80211_signal_monitor, |
| 13059 | .signal_poll = nl80211_signal_poll, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13060 | .mlo_signal_poll = nl80211_mlo_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13061 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13062 | .set_param = nl80211_set_param, |
| 13063 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 13064 | .add_pmkid = nl80211_add_pmkid, |
| 13065 | .remove_pmkid = nl80211_remove_pmkid, |
| 13066 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13067 | .set_rekey_info = nl80211_set_rekey_info, |
| 13068 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13069 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 13070 | .start_dfs_cac = nl80211_start_radar_detection, |
| 13071 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13072 | #ifdef CONFIG_TDLS |
| 13073 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 13074 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13075 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 13076 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13077 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 13078 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13079 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 13080 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13081 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 13082 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 13083 | .switch_channel = nl80211_switch_channel, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 13084 | #ifdef CONFIG_IEEE80211AX |
| 13085 | .switch_color = nl80211_switch_color, |
| 13086 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13087 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 13088 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13089 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 13090 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 13091 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 13092 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 13093 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 13094 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 13095 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 13096 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 13097 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 13098 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 13099 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 13100 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 13101 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13102 | #ifdef CONFIG_MESH |
| 13103 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 13104 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 13105 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 13106 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13107 | #endif /* CONFIG_MESH */ |
| 13108 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 13109 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 13110 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 13111 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 13112 | .add_tx_ts = nl80211_add_ts, |
| 13113 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 13114 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13115 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13116 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13117 | .disable_fils = nl80211_disable_fils, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 13118 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13119 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 13120 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 13121 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 13122 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 13123 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 13124 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13125 | #ifdef CONFIG_MBO |
| 13126 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 13127 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 13128 | #endif /* CONFIG_MBO */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 13129 | .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 13130 | .add_sta_node = nl80211_add_sta_node, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13131 | #ifdef CONFIG_PASN |
| 13132 | .send_pasn_resp = nl80211_send_pasn_resp, |
| 13133 | .set_secure_ranging_ctx = nl80211_set_secure_ranging_ctx, |
| 13134 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13135 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13136 | .do_acs = nl80211_do_acs, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13137 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 13138 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 13139 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 13140 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 13141 | .set_4addr_mode = nl80211_set_4addr_mode, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 13142 | #ifdef CONFIG_DPP |
| 13143 | .dpp_listen = nl80211_dpp_listen, |
| 13144 | #endif /* CONFIG_DPP */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 13145 | .get_sta_mlo_info = nl80211_get_sta_mlo_info, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 13146 | #ifdef CONFIG_TESTING_OPTIONS |
| 13147 | .register_frame = testing_nl80211_register_frame, |
| 13148 | .radio_disable = testing_nl80211_radio_disable, |
| 13149 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13150 | }; |